public void GetProductPrice_Should_Return_Price() { // Setup int productId = _fixture.Create <int>(); var expectedResult = _fixture.Create <string>(); var mockDatabase = new Mock <IDatabase>(); RedisValue convertedToRedisValue = expectedResult; _connMultiplexer.Setup(x => x.IsConnected).Returns(false); mockDatabase .Setup(x => x.StringGet(It.IsAny <RedisKey>(), It.IsAny <CommandFlags>())) .Returns(convertedToRedisValue); _connMultiplexer .Setup(x => x.GetDatabase(It.IsAny <int>(), It.IsAny <object>())) .Returns(mockDatabase.Object); // Act var result = _pricingRepository.GetProductPrice(productId); // Assert result.Should().Be(expectedResult); }
public ProductData GetProductData(int productId) { var productData = _retailProductRepository.GetProduct(productId); if (productData == null) { //Here, I would definitely NOT throw the base Exception class if this wasn't a case study. //Adding extra boilerplate just to wrap Exception in another class seemed unnecessary at the moment, though. throw new Exception("Unable to read product information"); } productData.Price = _pricingRepository.GetProductPrice(productId) ?? "0.00"; return(productData); }