示例#1
0
        public async Task ShouldUpsertHabitCompletion()
        {
            // Arrange
            var mediatorMock = new Mock <IMediator>();
            var sutCreate    = new UpsertHabitCompletionCommand.Handler(_context, mediatorMock.Object);
            var sutUpdate    = new UpsertHabitCompletionCommand.Handler(_context, mediatorMock.Object);
            var dateTime     = DateTime.Now;

            // Act
            var habitCompletionId = await sutCreate.Handle(new UpsertHabitCompletionCommand
            {
                HabitId           = 1,
                HabitVariationId  = 1,
                Date              = dateTime,
                HabitDifficultyId = 2,
            }, CancellationToken.None);

            await sutUpdate.Handle(new UpsertHabitCompletionCommand
            {
                Id                = habitCompletionId,
                HabitId           = 1,
                HabitVariationId  = 2,
                Date              = dateTime.AddDays(1),
                HabitDifficultyId = 4,
            }, CancellationToken.None);

            var habitCompletion = await _context.HabitCompletions.FindAsync(habitCompletionId);

            // Assert
            habitCompletion.HabitId.ShouldBe(1);
            habitCompletion.HabitVariationId.ShouldBe(2);
            habitCompletion.Date.ShouldBe(dateTime.AddDays(1));
            habitCompletion.HabitDifficultyId.ShouldBe(4);
        }
示例#2
0
        public async Task Handle_GivenValidRequest_ShouldRaiseHabitCompletionCreatedNotification()
        {
            // Arrange
            var mediatorMock = new Mock <IMediator>();
            var sut          = new UpsertHabitCompletionCommand.Handler(_context, mediatorMock.Object);
            var dateTime     = DateTime.Now;

            // Act
            var habitCompletionId = await sut.Handle(new UpsertHabitCompletionCommand {
                HabitId           = 1,
                HabitVariationId  = 1,
                Date              = dateTime,
                HabitDifficultyId = 2
            }, CancellationToken.None);

            // Assert
            mediatorMock.Verify(m => m.Publish(It.Is <HabitCompletionCreated>(h => h.HabitCompletionId == habitCompletionId), It.IsAny <CancellationToken>()), Times.Once);
        }