コード例 #1
0
        public void Handle_InvalidCommand_EmptyName_ShouldThrowValidationException()
        {
            var handler = new CreateCategory.Handler(mockRepository.Object);

            Func <Task> func = async() => await handler.Handle(new CreateCategory.CreateCategoryCommand {
                Name = ""
            }, CancellationToken.None);

            func.Should().Throw <ValidationException>();

            mockRepository.Verify(repo => repo.AddAsync(It.IsAny <Category>()), Times.Never());
        }
コード例 #2
0
        public async Task Handle_ValidCommand_ShouldAddToRepository()
        {
            var initialListCount = (await mockRepository.Object.GetAllAsync()).Count;

            var handler = new CreateCategory.Handler(mockRepository.Object);

            await handler.Handle(new CreateCategory.CreateCategoryCommand {
                Name = "TestCategory"
            }, CancellationToken.None);

            var categories = await mockRepository.Object.GetAllAsync();

            categories.Count.Should().Be(initialListCount + 1);

            mockRepository.Verify(repo => repo.AddAsync(It.IsAny <Category>()), Times.Once());
        }