public async Task GivenValidQuery_ReturnProductVm()
        {
            var result = await _handler.Handle(_query, CancellationToken.None);

            Assert.Equal(TestContext.TestProductCommon.Name, result.Name);
            Assert.Equal(TestContext.TestProductCommon.ProductType, result.ProductType);
            Assert.NotEmpty(result.Materials);
            Assert.Equal(TestContext.TestProductCommon.Materials.Count, result.Materials.Count);
            Assert.NotEmpty(result.Materials.First().Name);
        }
Ejemplo n.º 2
0
        public async Task Handle_ProductExists_ReturnProduct(
            Entities.Product product,
            [Frozen] Mock <IRepository <Entities.Product> > productRepoMock,
            GetProductQueryHandler sut,
            GetProductQuery query
            )
        {
            // Arrange
            productRepoMock.Setup(x => x.GetBySpecAsync(
                                      It.IsAny <GetProductSpecification>(),
                                      It.IsAny <CancellationToken>()
                                      ))
            .ReturnsAsync(product);

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            productRepoMock.Verify(x => x.GetBySpecAsync(
                                       It.IsAny <GetProductSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ));
            result.ProductNumber.Should().Be(product.ProductNumber);
        }
Ejemplo n.º 3
0
        public async Task GetFail()
        {
            var sut = new GetProductQueryHandler(_context, _mapper);

            Exception ex = await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(new GetProductQuery {
                Id = 10
            }, CancellationToken.None));

            ex.Message.ShouldBe("Entity \"Product\" (10) was not found.");
        }
Ejemplo n.º 4
0
        public async Task Get()
        {
            var sut = new GetProductQueryHandler(_context, _mapper);

            var result = await sut.Handle(new GetProductQuery { Id = 1 }, CancellationToken.None);

            result.ShouldBeOfType <ProductViewModel>();
            result.ProductId.ShouldBe(1);
            result.ProductName.ShouldBe("KeyBoard");
        }
Ejemplo n.º 5
0
        public async Task ShouldGetProduct()
        {
            // Arrange
            var getProductCommand = new GetProductCommand(2, WorkContext.WorkingLanguageId);

            // Act
            var result = await _getProductQueryHandler.Handle(getProductCommand);

            // Assert
            Assert.IsNotNull(result?.Object);
        }
Ejemplo n.º 6
0
        public async Task Handle_GivenValidId_ReturnsCorrectProduct()
        {
            var query = new GetProductQuery {
                Id = 999
            };

            var sut = new GetProductQueryHandler(_context);

            var result = await sut.Handle(query, CancellationToken.None);

            result.ProductId.ShouldBe(999);
        }
        public async Task GetProductQueryHandler_Success()
        {
            //Arrange
            productRepository.Setup(x =>
                                    x.GetByConditionWithIncludeFirst(It.IsAny <Expression <Func <Product, bool> > >(), It.IsAny <Expression <Func <Product, Brand> > >()))
            .Returns(Task.FromResult(product));

            mapper.Setup(x => x.Map <GetProductDto>(product)).Returns(productDto);

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

            //Assert
            Assert.Equal(productName, action.ProductName);
        }
Ejemplo n.º 8
0
        public async Task GetAsync()
        {
            var dataAccess = new ProductDataAccess(this.Context, Mapper());

            //Act
            var sutCreate    = new CreateProductCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateProductCommand
            {
                Data = ProductTestData.ProductDTO
            }, CancellationToken.None);

            //Act
            var sutGet    = new GetProductQueryHandler(dataAccess);
            var resultGet = await sutGet.Handle(new GetProductQuery
            {
                Id = resultCreate.Data.Id
            }, CancellationToken.None);

            Assert.IsTrue(resultGet?.Data != null);
        }
        public async Task Should_ThrowArguementException_WhenRecordNotFound()
        {
            var productName = Guid.NewGuid().ToString();
            var testProduct = new Product()
            {
                Active     = true,
                ModifiedOn = DateTime.Now,
                Name       = productName,
                Price      = 15
            };

            await testProduct.SaveAsync();

            var handler   = new GetProductQueryHandler();
            var testQuery = new Queries.GetProductQuery()
            {
                ProductId = ObjectId.GenerateNewId().ToString()
            };

            Assert.ThrowsAsync <ArgumentException>(async() => await handler.Handle(testQuery, default));
        }
        public async Task Should_ThrowFormatException_WhenQueryIsInvalid()
        {
            var productName = Guid.NewGuid().ToString();
            var testProduct = new Product()
            {
                Active     = true,
                ModifiedOn = DateTime.Now,
                Name       = productName,
                Price      = 15
            };

            await testProduct.SaveAsync();

            var handler   = new GetProductQueryHandler();
            var testQuery = new Queries.GetProductQuery()
            {
                ProductId = "test"
            };

            Assert.ThrowsAsync <FormatException>(async() => await handler.Handle(testQuery, default));
        }
        public async Task Should_ReturnValidProductDTO_WhenQueryIsValid()
        {
            var productName = Guid.NewGuid().ToString();
            var testProduct = new Product()
            {
                Active     = true,
                ModifiedOn = DateTime.Now,
                Name       = productName,
                Price      = 15
            };

            await testProduct.SaveAsync();

            var handler = new GetProductQueryHandler();
            var result  = await handler.Handle(new Queries.GetProductQuery()
            {
                ProductId = testProduct.ID
            }, default);

            Assert.NotNull(result);
            Assert.AreEqual(productName, result.Name);
            Assert.AreEqual(15, result.Price);
            Assert.IsTrue(result.Active);
        }
Ejemplo n.º 12
0
        public void Handle_ProductDoesNotExists_ThrowArgumentNullException(
            //Entities.Product product,
            [Frozen] Mock <IRepository <Entities.Product> > productRepoMock,
            GetProductQueryHandler sut,
            GetProductQuery query
            )
        {
            // Arrange
            productRepoMock.Setup(x => x.GetBySpecAsync(
                                      It.IsAny <GetProductSpecification>(),
                                      It.IsAny <CancellationToken>()
                                      ))
            .ReturnsAsync((Entities.Product)null);

            //Act
            Func <Task> func = async() => await sut.Handle(query, CancellationToken.None);

            //Assert
            func.Should().ThrowAsync <ArgumentNullException>();
            productRepoMock.Verify(x => x.GetBySpecAsync(
                                       It.IsAny <GetProductSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ));
        }