Exemplo n.º 1
0
 public GetBrandsQueryHandlerTest()
 {
     mapper          = new Mock <IMapper>();
     brandRepository = new Mock <IBrandRepository>();
     query           = new GetBrandsQuery();
     queryHandler    = new GetBrandsQueryHandler(brandRepository.Object, mapper.Object);
     brands          = new List <Brand> {
         new Brand(), new Brand()
     };
     brandsDto = new List <GetBrandsDto> {
         new GetBrandsDto(), new GetBrandsDto()
     };
 }
        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");
        }