public async Task CreateAsync_ExplicitUserId(bool isAdmin, string currentUserId, string createdByUserId, string expectedEntryUserId) { // Arrange using var dbContext = CreateDbContext(); var userContextAccessorMock = new Mock <IUserContextAccessor>(); userContextAccessorMock.Setup(m => m.GetUserId()).Returns(currentUserId); userContextAccessorMock.Setup(m => m.IsAdminUser()).Returns(isAdmin); var workEntriesService = new WorkEntriesService(dbContext, Mock.Of <IDbErrorHandler>(), userContextAccessorMock.Object); // Act var entry = new WorkEntry { HoursSpent = 5, Date = DateTime.Now.Date, Notes = "Notes", UserId = createdByUserId }; entry = await workEntriesService.CreateAsync(entry); // Assert Assert.Equal(expectedEntryUserId, entry.UserId); }
public async Task CreateAsync_InitsEmptyFields() { // Arrange string testUserId = Guid.NewGuid().ToString(); using var dbContext = CreateDbContext(); var userContextAccessorMock = new Mock <IUserContextAccessor>(); userContextAccessorMock.Setup(m => m.GetUserId()).Returns(testUserId); var workEntriesService = new WorkEntriesService(dbContext, Mock.Of <IDbErrorHandler>(), userContextAccessorMock.Object); // Act var entry = new WorkEntry { HoursSpent = 5, Date = DateTime.Now.Date, Notes = "Notes" }; var createdEntry = await workEntriesService.CreateAsync(entry); // Assert Assert.NotEqual(Guid.Empty, createdEntry.Id); Assert.Equal(testUserId, createdEntry.UserId); Assert.Equal(entry.Date, createdEntry.Date); Assert.Equal(entry.Notes, createdEntry.Notes); Assert.Equal(entry.HoursSpent, createdEntry.HoursSpent); }