public ActionResult Get([FromQuery] ProductSearchTerms searchTerms) { var result = this._productService.GetAvailableProduct(searchTerms); if (result == null) { return(NotFound()); } return(Ok(result)); }
public IEnumerable <Product> GetAvailableProduct(ProductSearchTerms searchTerms) { User user = this._users.GetUser(searchTerms.UserID); decimal ltv = PodiumUtility.CalculateLTV(searchTerms.PropertyValue, searchTerms.DepositeAmount); bool IsUnder18 = PodiumUtility.IsUnder18(user.DOB); if (IsUnder18) { return(null); } IProductFactory factory = new ProductFactory(_products, ltv); return(factory.GetProducts()); }
public void GetAvailableProduct_Should_Not_Return_Available_Products_if_ltv_equals_90() { IProduct products = new InMemoryProduct(); IUser users = new InMemoryUser(); User newUser = new User() { Id = 0, FirstName = "Sanjay", LastName = "xxx", DOB = DateTime.Parse("1990-05-05"), Email = "*****@*****.**" }; users.AddUser(newUser); ProductServiceProvider service = new ProductServiceProvider(products, users); ProductSearchTerms terms = new ProductSearchTerms() { UserID = 1, PropertyValue = 100000, DepositeAmount = 10000 }; var result = service.GetAvailableProduct(terms); Assert.AreEqual(null, result); }
public void GetAvailableProduct_Should_Return_Available_Products_LTV60_And90() { IProduct products = new InMemoryProduct(); IUser users = new InMemoryUser(); User newUser = new User() { Id = 0, FirstName = "Sanjay", LastName = "xxx", DOB = DateTime.Parse("1990-05-05"), Email = "*****@*****.**" }; users.AddUser(newUser); ProductServiceProvider service = new ProductServiceProvider(products, users); ProductSearchTerms terms = new ProductSearchTerms() { UserID = 1, PropertyValue = 100000, DepositeAmount = 40001 }; var expect = products.GetAllProducts(); var result = service.GetAvailableProduct(terms); Assert.AreEqual(expect.Count() == 3, result.Count() == 3); Assert.AreEqual(expect.ElementAt(0).LoanToValuePercentage, result.ElementAt(0).LoanToValuePercentage); }