Beispiel #1
0
        public async void FindById_ShouldReturnAProduct()
        {
            // Arrange
            var product = _productTestsFixture.GetValidProduct();

            _productRepositoryMock.Setup(r => r.FindById(product.Id, true, true))
            .Returns(Task.FromResult(product));

            // Act
            var result = await _productService.FindById(product.Id, true, true);

            // Assert
            _productRepositoryMock.Verify(x => x.FindById(product.Id, true, true), Times.Once);
            result.Should().BeEquivalentTo(product);
        }
Beispiel #2
0
        public async Task ProductController_GetProductById_ShouldReturnCorrectProduct()
        {
            // Arrange
            var mock      = new Mock <IProductService>();
            var product   = _productFixture.GetValidProduct();
            var productId = Guid.NewGuid();

            mock.Setup(service => service.GetById(productId)).ReturnsAsync(product);

            // Act
            ProductController controller = new ProductController(mock.Object);

            var actionResult = await controller.GetById(productId);

            var result     = Assert.IsType <ActionResult <ProductDTO> >(actionResult).Result;
            var statusCode = result as OkResult;

            // Arrange
            result.Should().Equals(product);
            statusCode.Should().Equals(HttpStatusCode.OK);
        }