public void Can_calculate_total_price() { var id = Guid.NewGuid(); var initial = new Entity("ins_salesorderline") { Id = id }; initial.Set("ins_qty", 5); var target = new Entity("ins_salesorderline") { Id = id }; target.Set("ins_priceamount", new Money(200m)); var testEvent = new TestEvent { Plugin = { Configure = PreSalesOrderLine.ConfigurePlugin }, Db = { initial } }; testEvent.ForUpdate(target); var context = testEvent.CreatePluginContext(); new CalculateTotalPrice(context).Execute(); Assert.Equal(1000m, target.Get <Money>("ins_totalprice").Value); }
public void Can_calculate_total_price() { var id = Guid.NewGuid(); var initial = new ins_salesorderline { Id = id, ins_qty = 5 }; var target = new ins_salesorderline { Id = id, ins_priceamount = new Money(200m) }; var testEvent = new TestEvent <ins_salesorderline> { Plugin = { Configure = PreSalesOrderLine.ConfigurePlugin }, Db = { initial } }; testEvent.ForUpdate(target); var context = testEvent.CreatePluginContext(); new CalculateTotalPrice(context).Execute(); Assert.Equal(1000m, target.ins_totalprice.Value); }
public void Can_update_sales_order_on_post() { var salesOrder = new Entity("ins_salesorder") { Id = Guid.NewGuid() }; var line = new Entity("ins_salesorderline") { Id = Guid.NewGuid() }; line.Set("ins_salesorderid", salesOrder.ToEntityReference()); line.Set("ins_totalprice", new Money(1000m)); var unrelatedLine = new Entity("ins_salesorderline") { Id = Guid.NewGuid() }; unrelatedLine.Set("ins_salesorderid", new EntityReference("ins_salesorder", Guid.NewGuid())); unrelatedLine.Set("ins_totalprice", new Money(7000m)); var id = Guid.NewGuid(); var initial = new Entity("ins_salesorderline") { Id = id }; initial.Set("ins_salesorderid", salesOrder.ToEntityReference()); initial.Set("ins_totalprice", new Money(500m)); var target = new Entity("ins_salesorderline") { Id = id }; target.Set("ins_totalprice", new Money(500m)); var testEvent = new TestEvent { Plugin = { Configure = PostSalesOrderLine.ConfigurePlugin }, Db = { initial, line, unrelatedLine, salesOrder } }; testEvent.ForUpdate(target, 40); var context = testEvent.CreatePluginContext(); new UpdateSalesOrder(context).Execute(); var updateSalesOrder = testEvent.FakedContext .CreateQuery("ins_salesorder") .First(); Assert.Equal(1500m, updateSalesOrder.Get <Money>("ins_totalprice").Value); }
public void Can_update_sales_order_on_delete() { var salesOrder = new ins_salesorder { Id = Guid.NewGuid() }; var line = new ins_salesorderline { Id = Guid.NewGuid() }; line.Set(e => e.ins_salesorderid, salesOrder.ToEntityReference()); line.Set(e => e.ins_totalprice, 1000m); var unrelatedLine = new ins_salesorderline { Id = Guid.NewGuid() }; unrelatedLine.Set(e => e.ins_salesorderid, new EntityReference(ins_salesorder.EntityLogicalName, Guid.NewGuid())); unrelatedLine.Set(e => e.ins_totalprice, 7000m); var id = Guid.NewGuid(); var initial = new ins_salesorderline { Id = id }; initial.Set(e => e.ins_salesorderid, salesOrder.ToEntityReference()); initial.Set(e => e.ins_totalprice, 500m); var target = new ins_salesorderline { Id = id }; var testEvent = new TestEvent <ins_salesorderline> { Plugin = { Configure = PreSalesOrderLine.ConfigurePlugin }, Db = { initial, line, unrelatedLine, salesOrder } }; testEvent.ForDelete(target.ToEntityReference()); var context = testEvent.CreatePluginContext(); new UpdateSalesOrder(context).Execute(); var updateSalesOrder = testEvent.FakedContext .CreateQuery <ins_salesorder>() .First(); Assert.Equal(1000m, updateSalesOrder.Get(e => e.ins_totalprice).Value); }
public void Can_update_sales_order_on_post() { var salesOrder = new ins_salesorder { Id = Guid.NewGuid() }; var line = new ins_salesorderline { Id = Guid.NewGuid(), ins_salesorderid = salesOrder.ToEntityReference(), ins_totalprice = new Money(1000m) }; var unrelatedLine = new ins_salesorderline { Id = Guid.NewGuid(), ins_salesorderid = new EntityReference(ins_salesorder.EntityLogicalName, Guid.NewGuid()), ins_totalprice = new Money(7000m) }; var id = Guid.NewGuid(); var initial = new ins_salesorderline { Id = id, ins_salesorderid = salesOrder.ToEntityReference(), ins_totalprice = new Money(500m) }; var target = new ins_salesorderline { Id = id, ins_totalprice = new Money(500m) }; var testEvent = new TestEvent <ins_salesorderline> { Plugin = { Configure = PostSalesOrderLine.ConfigurePlugin }, Db = { initial, line, unrelatedLine, salesOrder } }; testEvent.ForUpdate(target, 40); var context = testEvent.CreatePluginContext(); new UpdateSalesOrder(context).Execute(); var updateSalesOrder = testEvent.FakedContext .CreateQuery <ins_salesorder>() .First(); Assert.Equal(1500m, updateSalesOrder.ins_totalprice.Value); }
public void Can_load_product_data() { var product = new Product { Id = Guid.NewGuid() }; product.Set(e => e.Name, "Product ABC"); product.Set(e => e.Price, 2500m); var id = Guid.NewGuid(); var initial = new ins_salesorderline { Id = id }; var target = new ins_salesorderline { Id = id }; target.Set(e => e.ins_productid, product.ToEntityReference()); var testEvent = new TestEvent <ins_salesorderline> { Plugin = { Configure = PreSalesOrderLine.ConfigurePlugin }, Db = { initial, product } }; testEvent.ForUpdate(target); var context = testEvent.CreatePluginContext(); new LoadProductData(context).Execute(); Assert.Equal("Product ABC", target.Get(e => e.ins_linenumber)); Assert.Equal(2500m, target.Get(e => e.ins_priceamount).Value); }
public void Can_load_product_data() { var product = new Entity("product") { Id = Guid.NewGuid() }; product.Set("name", "Product ABC"); product.Set("price", new Money(2500m)); var id = Guid.NewGuid(); var initial = new Entity("ins_salesorderline") { Id = id }; var target = new Entity("ins_salesorderline") { Id = id }; target.Set("ins_productid", product.ToEntityReference()); var testEvent = new TestEvent { Plugin = { Configure = PreSalesOrderLine.ConfigurePlugin }, Db = { initial, product } }; testEvent.ForUpdate(target); var context = testEvent.CreatePluginContext(); new LoadProductData(context).Execute(); Assert.Equal("Product ABC", target.Get <string>("ins_linenumber")); Assert.Equal(2500m, target.Get <Money>("ins_priceamount").Value); }