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 LoadProductDataUsingExtensions(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); }
public void Can_update_sales_order_on_post() { 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 }; target.Set(e => e.ins_totalprice, 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.Get(e => e.ins_totalprice).Value); }