Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void Can_update_sales_order_on_delete()
        {
            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
            };

            var testEvent = new TestEvent
            {
                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 <Money>("ins_totalprice").Value);
        }