コード例 #1
0
        public async Task GetBrandsQueryHandler_Success()
        {
            //Arrange
            brandRepository.Setup(x => x.GetAll()).Returns(Task.FromResult(brands));

            mapper.Setup(x => x.Map <List <GetBrandsDto> >(brands)).Returns(brandsDto);

            //Act
            var action = await queryHandler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            Assert.Equal(brandsDto.Count, action.Count());
        }
コード例 #2
0
        public async Task GetBrandsQueryHandler_Works()
        {
            var repository = new Mock <IRepository>();

            var selectorCaptor = new ExpressionCaptor <Brand, BrandDto>();

            repository.Setup(x => x.ListAsync(selectorCaptor.Capture())).ReturnsAsync(new List <BrandDto>());

            var queryHandler = new GetBrandsQueryHandler(repository.Object);

            var result = await queryHandler
                         .Handle(new GetBrandsQuery(), It.IsAny <CancellationToken>())
                         .ConfigureAwait(false);

            Assert.That(result, Is.InstanceOf <List <BrandDto> >());
            var brand = new Brand {
                Id = 1, Name = "a", ImageUri = "uri1"
            };
            var transformedResult = selectorCaptor.Invoke(brand);

            transformedResult.Id.Should().Be(1);
            transformedResult.Name.Should().Be("a");
            transformedResult.ImageUri.Should().Be("uri1");
        }