public async Task Handle_GivenValidRequest_ShouldRaiseHabitVariationCreatedNotification() { // Arrange var mediatorMock = new Mock <IMediator>(); var sut = new UpsertHabitVariationCommand.Handler(_context, mediatorMock.Object); var dateTime = DateTime.Now; // Act var habitVariationId = await sut.Handle(new UpsertHabitVariationCommand { HabitId = 1, Name = "Running", }, CancellationToken.None); // Assert mediatorMock.Verify(m => m.Publish(It.Is <HabitVariationCreated>(h => h.HabitVariationId == habitVariationId), It.IsAny <CancellationToken>()), Times.Once); }
public async Task ShouldCreateHabitVariation() { // Arrange var mediatorMock = new Mock <IMediator>(); var sut = new UpsertHabitVariationCommand.Handler(_context, mediatorMock.Object); var dateTime = DateTime.Now; // Act await sut.Handle(new UpsertHabitVariationCommand { HabitId = 1, Name = "Running", }, CancellationToken.None); // Assert var habit = await _context.Habits.FindAsync(1); habit.Variants.First().HabitVariantName.ShouldBe("Running"); }