public void GetProductOptionById_PositiveScenario() { // Arrange var expectedProductOptions = new List <ProductOption> { new ProductOption { Id = 1, Code = "PO1", Description = "Product Option 1", ProductId = 1 }, new ProductOption { Id = 2, Code = "PO2", Description = "Product Option 2", ProductId = 1 } }; _productQueryService.Setup(x => x.GetProductOptionsByProductId(It.IsAny <int>())).Returns(expectedProductOptions); var productOptionController = new ProductOptionController(_productCommandService.Object, _productQueryService.Object); // Act IActionResult result = productOptionController.GetProductOptionsByProductId(It.IsAny <int>()); var actualProductOptions = ((OkObjectResult)result).Value as List <ProductOption>; // Assert _productQueryService.Verify(x => x.GetProductOptionsByProductId(It.IsAny <int>()), Times.Once); Assert.IsType <OkObjectResult>(result); actualProductOptions.Should().BeEquivalentTo(expectedProductOptions); }
public void GetProductOptionById_ThrowsException() { // Arrange _productQueryService.Setup(x => x.GetProductOptionsByProductId(It.IsAny <int>())).Throws(new Exception("An error occurred while retrieving Product Options")); var productOptionController = new ProductOptionController(_productCommandService.Object, _productQueryService.Object); // Act & Assert Assert.Throws <Exception>(() => productOptionController.GetProductOptionsByProductId(It.IsAny <int>())); }