diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-21 22:36:04 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-21 22:36:04 +0800 |
commit | 431ba02aa831448ca2aa9e9a42aa3aaf1345edbe (patch) | |
tree | 1712a6f45678c4af0313cfdf6a2019533243f0e1 | |
parent | 726cb51b4fccb328dd05ee5c17214028aeeb6885 (diff) | |
download | timeline-431ba02aa831448ca2aa9e9a42aa3aaf1345edbe.tar.gz timeline-431ba02aa831448ca2aa9e9a42aa3aaf1345edbe.tar.bz2 timeline-431ba02aa831448ca2aa9e9a42aa3aaf1345edbe.zip |
Add database test for user detail.
-rw-r--r-- | Timeline.Tests/DatabaseTest.cs | 17 | ||||
-rw-r--r-- | Timeline/Services/UserDetailService.cs | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Timeline.Tests/DatabaseTest.cs b/Timeline.Tests/DatabaseTest.cs index e280637c..f75ab71b 100644 --- a/Timeline.Tests/DatabaseTest.cs +++ b/Timeline.Tests/DatabaseTest.cs @@ -1,5 +1,4 @@ using FluentAssertions;
-using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using Timeline.Entities;
@@ -33,5 +32,21 @@ namespace Timeline.Tests _context.SaveChanges();
_context.UserAvatars.Count().Should().Be(1);
}
+
+ [Fact]
+ public void DeleteUserShouldAlsoDeleteDetail()
+ {
+ var user = _context.Users.First();
+ _context.UserDetails.Add(new UserDetailEntity
+ {
+ UserId = user.Id
+ });
+ _context.SaveChanges();
+ _context.UserDetails.Count().Should().Be(1);
+
+ _context.Users.Remove(user);
+ _context.SaveChanges();
+ _context.UserDetails.Count().Should().Be(0);
+ }
}
}
diff --git a/Timeline/Services/UserDetailService.cs b/Timeline/Services/UserDetailService.cs index c3a2a1af..d1fdc040 100644 --- a/Timeline/Services/UserDetailService.cs +++ b/Timeline/Services/UserDetailService.cs @@ -53,6 +53,7 @@ namespace Timeline.Services };
_databaseContext.UserDetails.Add(detail);
await _databaseContext.SaveChangesAsync();
+ _logger.LogInformation("An entity is created in user_details.");
}
return detail;
}
@@ -85,6 +86,7 @@ namespace Timeline.Services detailEntity.Description = detail.Description;
await _databaseContext.SaveChangesAsync();
+ _logger.LogInformation("An entity is updated in user_details.");
}
}
}
|