public void Available_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.Available(products)); Assert.Equal(nameof(products), ex.ParamName); }
public void Available_Should_Return_Only_Products_On_Sale_And_With_Units_In_Stock() { var p1 = Product.Create("ean", "sku", "name", "url"); var p2 = Product.Create("ean", "sku", "name", "url"); var p3 = Product.Create("ean", "sku", "name", "url"); p1.SetOnSale(); p1.SetUnitInStock(1); p2.SetOnSale(DateTime.Today.AddDays(-1), DateTime.Today.AddMonths(1)); p2.SetUnitInStock(2); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); var today = DateTime.Now; var productsAvailable = ProductExtensions.Available(products).ToArray(); Assert.True(productsAvailable.All(p => p.IsOnSale && p.OnSaleFrom <= today && (!p.OnSaleTo.HasValue || p.OnSaleTo >= today) && p.UnitInStock > 0)); }