コード例 #1
0
        public async Task ProductController_GetProducts_Returns_OKResult_With_Correct_Products_ObjectType()
        {
            // Arrange
            _mockProductsService.Setup(p => p.GetProducts()).Returns(Task.FromResult(GetTestData.GetTestProducts()));

            ProductController controller = new ProductController(_mockLogger.Object, _mockProductsService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetProducts();

            ObjectResult objectResult = result as ObjectResult;

            // Assert
            Assert.IsNotNull(objectResult);
            Assert.AreEqual(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.IsInstanceOfType(objectResult.Value, typeof(IEnumerable <Product>));
        }
コード例 #2
0
        public async Task ProductController_GetProductsBySKU_Returns_NotFound_When_SKU_Not_Exists()
        {
            // Arrange
            _mockProductsService.Setup(p => p.GetProductById(It.IsAny <string>()))
            .Returns(Task.FromResult(GetTestData.GetTestProducts().Where(t => t.Id == "00000").FirstOrDefault()));

            ProductController controller = new ProductController(_mockLogger.Object, _mockProductsService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetProductsValue();

            StatusCodeResult statusCodeResult = result as NotFoundResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.GetType(), typeof(NotFoundResult));
            Assert.AreEqual(StatusCodes.Status404NotFound, statusCodeResult.StatusCode);
        }
コード例 #3
0
        public async Task ProductController_GetProductsBySKU_Returns_OKResult_With_Correct_Total_Amount()
        {
            // Arrange
            _mockProductsService.Setup(p => p.GetProductById(It.IsAny <string>()))
            .Returns(Task.FromResult(GetTestData.GetTestProducts().Where(t => t.Id == "T2006").FirstOrDefault()));

            _mockCalculatorService.Setup(p => p.ComputeTotalProductsValueByCurrency(It.IsAny <IEnumerable <Product> >(), It.IsAny <CurrencyCode>())).Returns(10.16M);

            ProductController controller = new ProductController(_mockLogger.Object, _mockProductsService.Object, _mockCalculatorService.Object, _mockPersistenceService.Object);

            // Act
            IActionResult result = await controller.GetProductsValue();

            ObjectResult objectResult = result as ObjectResult;
            decimal?     content      = objectResult.Value as decimal?;

            // Assert
            Assert.IsNotNull(objectResult);
            Assert.AreEqual(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.AreEqual(10.16M, content);
        }