public void MainProducts_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.MainProducts(products)); Assert.Equal(nameof(products), ex.ParamName); }
public virtual ActionResult DeleteDispatchLists(List <int> items) { foreach (var item in items) { ProductExtensions.DispatchListDelById(item); } return(Json(new { result = true })); }
public void WithUnitInStock_Should_Throw_ArgumentException_If_UnitInStock_Is_Less_Than_Zero() { IQueryable <Product> products = new Product[0].AsQueryable(); int unitInStock = -1; var ex = Assert.Throws <ArgumentException>(() => ProductExtensions.WithUnitInStock(products, unitInStock)); Assert.Equal(nameof(unitInStock), ex.ParamName); }
public void WithUnitInStock_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; int unitInStock = 0; var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.WithUnitInStock(products, unitInStock)); Assert.Equal(nameof(products), ex.ParamName); }
public void VariantsOf_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; Guid productId = Guid.NewGuid(); var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.VariantsOf(products, productId)); Assert.Equal(nameof(products), ex.ParamName); }
public void VariantsOf_Should_Throw_ArgumentException_If_ProductId_Is_Empty() { IQueryable <Product> products = new Product[0].AsQueryable(); Guid productId = Guid.Empty; var ex = Assert.Throws <ArgumentException>(() => ProductExtensions.VariantsOf(products, productId)); Assert.Equal(nameof(productId), ex.ParamName); }
public void ByVendor_Should_Throw_ArgumentException_If_VendorId_Is_Empty() { IQueryable <Product> products = new Product[0].AsQueryable(); Guid vendorId = Guid.Empty; var ex = Assert.Throws <ArgumentException>(() => ProductExtensions.ByVendor(products, vendorId)); Assert.Equal(nameof(vendorId), ex.ParamName); }
public void OnSaleTill_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; DateTime tillDate = DateTime.Today; var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.OnSaleTill(products, tillDate)); Assert.Equal(nameof(products), ex.ParamName); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); ProductExtensions.Environment = "Live"; ProductExtensions.Domain = ProductExtensions.GetDomain(Configuration, "domain"); ProductExtensions.DB = ProductExtensions.GetDomain(Configuration, "db"); var connection = @"Server=cloudchargesql.database.windows.net;Database=nskdevcom_test;User Id=user; Password=Azure@403;Encrypt=True;TrustServerCertificate=False;"; services.AddDbContext <ProductContext>(options => options.UseSqlServer(connection)); }
public virtual ActionResult Get(bool?status, int page, int pageSize, string orderBy, string description, string periodStart, string periodEnd, string sku, string orderByDirection) { try { if (orderByDirection == "Descending") { orderByDirection = "desc"; } else { orderByDirection = "asc"; } var dispatchs = ProductExtensions.listDispatchGen(new PaginationParameters() { PageSize = pageSize, PageIndex = page, OrderBy = orderBy, Order = orderByDirection, Description = description, PeriodStart = periodStart, PeriodEnd = periodEnd, SKU = sku }); if (!dispatchs.Any()) { return(Json(new { result = true, totalPages = 0, page = String.Format("<tr><td colspan=\"6\">{0}</td></tr>", Translation.GetTerm("ThereAreNoDispatchs", "There are no dispatcs")) })); } var builder = new StringBuilder(); foreach (var dispatch in dispatchs) { string controllerName = (dispatch.Description); string editUrl = string.Format("~/Products/{0}/Edit?dispatchID={1}", "Dispatch", dispatch.DispatchID); builder.Append("<tr>") .AppendCheckBoxCell(value: dispatch.DispatchID.ToString()) .AppendLinkCell(editUrl, dispatch.Description) .AppendCell(dispatch.PeriodStart.ToString()) .AppendCell(dispatch.PeriodEnd.ToString()) .AppendCell(dispatch.DateStart.HasValue ? dispatch.DateStart.Value.ToString("g", CoreContext.CurrentCultureInfo) : string.Empty) .AppendCell(dispatch.DateEnd.HasValue ? dispatch.DateEnd.Value.ToString("g", CoreContext.CurrentCultureInfo) : string.Empty) .AppendCell(dispatch.Situacion.ToString()) .AppendCell(dispatch.ListName.ToString()) .Append("</tr>"); } return(Json(new { result = true, totalPages = dispatchs.TotalPages, page = dispatchs.TotalCount == 0 ? "<tr><td colspan=\"7\">There are no Dispatch</td></tr>" : builder.ToString() })); } catch (Exception ex) { var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException); return(Json(new { result = false, message = exception.PublicMessage })); } }
public void MainProducts_Should_Return_Only_Products_Without_A_Main_Product_Associated() { var p1 = Product.Create("ean", "sku", "name", "url"); var p2 = Product.Create("ean", "sku", "name", "url"); var p3 = Product.Create("ean", "sku", "name", "url"); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); var mainProducts = ProductExtensions.MainProducts(products).ToArray(); Assert.True(mainProducts.All(p => p.MainProduct == null)); }
public void Active_Should_Return_Only_Products_Not_Deleted() { var p1 = Product.Create("ean", "sku", "name", "url"); var p2 = Product.Create("ean", "sku", "name", "url"); var p3 = Product.Create("ean", "sku", "name", "url"); p3.Delete(); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); var activeProducts = ProductExtensions.Active(products).ToArray(); Assert.True(activeProducts.All(p => !p.Deleted)); }
public void OnSaleTill_Should_Return_Only_Products_OnSale_And_With_OnSaleTo_Date_Previous_Than_The_Specified_Date() { 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(DateTime.Today.AddDays(-5), DateTime.Today.AddDays(-1)); p2.SetOnSale(DateTime.Today.AddDays(-3), DateTime.Today); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); DateTime tillDate = DateTime.Today; var productsOnSale = ProductExtensions.OnSaleTill(products, tillDate).ToArray(); Assert.True(productsOnSale.All(p => p.IsOnSale && p.OnSaleTo <= tillDate)); }
public void OnSaleFrom_Should_Return_Only_Products_On_Sale_With_OnSaleFrom_Date_Greater_Than_The_Specified_Date() { 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(); p2.SetOnSale(DateTime.Today, null); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); DateTime fromDate = DateTime.Today; var productsOnSale = ProductExtensions.OnSaleFrom(products, fromDate).ToArray(); Assert.True(productsOnSale.All(p => p.IsOnSale && p.OnSaleFrom >= fromDate)); }
public void WithUnitInStock_Should_Return_Only_Products_With_Units_In_Stock_Greater_Than_The_Specified_Quantity() { 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.SetUnitInStock(2); p2.SetUnitInStock(3); p3.SetUnitInStock(1); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); int unitInStock = 1; var productsWithUnitInStock = ProductExtensions.WithUnitInStock(products, unitInStock).ToArray(); Assert.True(productsWithUnitInStock.All(p => p.UnitInStock > unitInStock)); }
public void ByVendor_Should_Return_Only_Products_With_The_Specified_Vendor() { var vendor = Brand.Create("brand", "brand"); 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.SetVendor(vendor); p2.SetVendor(vendor); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); Guid vendorId = vendor.Id; var productsByVendor = ProductExtensions.ByVendor(products, vendorId).ToArray(); Assert.True(productsByVendor.All(p => p.Vendor != null && p.Vendor.Id == vendorId)); }
public void OnSale_Should_Return_Only_Products_OnSale_On_The_Current_Date() { 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(); p2.SetOnSale(DateTime.Today.AddDays(-1), DateTime.Today.AddMonths(1)); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); var today = DateTime.Now; var productsOnSale = ProductExtensions.OnSale(products).ToArray(); Assert.Equal(2, productsOnSale.Count()); Assert.True(productsOnSale.All(p => p.IsOnSale && p.OnSaleFrom <= today && (!p.OnSaleTo.HasValue || p.OnSaleTo >= today))); }
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)); }