示例#1
0
        public void Can_add_and_remove_events()
        {
            var logs = new List <string>();

            var entity = new MsGenerated.Account
            {
                Id          = Guid.NewGuid(),
                CreditLimit = new Money(200m)
            };

            entity.PropertyChanging += (sender, e) => logs.Add("Hello");

            AttributeChangingEventHandler attributeChanging = (sender, e) => logs.Add("World");
            var txEntity = new TransactionContextEntity <MsGenerated.Account>(entity);

            txEntity.AttributeChanging += attributeChanging;

            txEntity.Set(e => e.CreditLimit, new Money(450m));
            Assert.Equal("Hello World", String.Join(" ", logs));

            txEntity.AttributeChanging -= attributeChanging;
            logs = new List <string>();
            entity.CreditLimit = new Money(450m);
            Assert.Equal("Hello", String.Join(" ", logs));

            logs = new List <string>();
            txEntity["creditlimit"] = new Money(450m);
            Assert.Equal("", String.Join(" ", logs));
        }
示例#2
0
        public void Can_execute_attribute_changed()
        {
            var entity = new MsGenerated.Account
            {
                Id          = Guid.NewGuid(),
                CreditLimit = new Money(200m)
            };

            var txEntity = new TransactionContextEntity <MsGenerated.Account>(entity);

            Entity senderEntity          = null;
            AttributeChangedEventArgs ev = null;
            Money value = null;

            txEntity.AttributeChanged += (sender, e) =>
            {
                senderEntity = (Entity)sender;
                ev           = e;
                value        = ((Entity)sender).GetAttributeValue <Money>(e.AttributeName);
            };

            txEntity.Entity.CreditLimit = new Money(450m);

            Assert.Equal(entity, senderEntity);
            Assert.Equal("CreditLimit", ev.PropertyName);
            Assert.Equal("creditlimit", ev.AttributeName);
            Assert.Equal(450m, value.Value);
        }
        public void Can_get_attribute_name_from_crmsvcutil_generated()
        {
            var account = new MsGenerated.Account();

            Assert.Equal("accountid", Helper.Name <MsGenerated.Account>(e => e.Id));
            Assert.Equal("accountid", account.Name(e => e.Id));
            Assert.Equal("parentaccountid", Helper.Name <MsGenerated.Account>(e => e.parentaccountid));
            Assert.Equal("parentaccountid", account.Name(e => e.parentaccountid));
        }
示例#4
0
        public void Can_get_set_indexer()
        {
            var entity = new MsGenerated.Account
            {
                Id            = Guid.NewGuid(),
                AccountNumber = "1234"
            };

            var txEntity = new TransactionContextEntity <MsGenerated.Account>(entity);

            Assert.Equal("1234", (string)txEntity["accountnumber"]);
            Assert.Equal("1234", (string)entity["accountnumber"]);
        }
示例#5
0
        public void Can_copy_attribute_value_from_ms_generated_entity()
        {
            var id           = Guid.NewGuid();
            var sourceEntity = new MsGenerated.Account
            {
                Id = id,
                FormattedValues =
                {
                    ["creditlimit"] = "$100.00"
                }
            };
            var source = new TransactionContextEntity <MsGenerated.Account>(sourceEntity);

            var currentEntity = new MsGenerated.Account
            {
                Id = id,
                FormattedValues =
                {
                    ["accountratingcode"] = "Release"
                }
            };
            var current = new TransactionContextEntity <MsGenerated.Account>(currentEntity);

            var actionContext = new CurrentActionContext
            {
                TransactionContext = null,
                Target             = source,
                Current            = current
            };
            var action = new CopyValueEventCurrentAction();

            action.Execute(actionContext);
            source.Set(e => e.CreditLimit, new Money(100m));
            Assert.Equal(100m, current.Get <Money>("creditlimit").Value);
            Assert.Equal("$100.00", current.Entity.FormattedValues["creditlimit"]);
            Assert.Equal("Release", current.Entity.FormattedValues["accountratingcode"]);

            source.Entity.AccountRatingCode = new OptionSetValue(12);
            Assert.Equal(12, current.Get <OptionSetValue>("accountratingcode").Value);
            Assert.Equal("$100.00", current.Entity.FormattedValues["creditlimit"]);
            Assert.Null(current.Entity.FormattedValues["accountratingcode"]);
        }