Ejemplo n.º 1
0
        public void PreUpdateTest()
        {
            using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountPlugin>())
            {
                var pre = new Entities.Account
                {
                    AccountId = Guid.NewGuid(),
                    Name      = "Prename"
                };
                ctx.AddEntity(pre);

                var target = new Entities.Account
                {
                    AccountId = pre.AccountId,
                    Name      = "the next name"
                };

                ctx.OnPre = delegate()
                {
                    var result = ctx.GetEntityById <Entities.Account>(pre.AccountId.Value);
                    Assert.AreEqual("The Next Name", result.Name);
                    Assert.AreEqual(pre.Name, result.Description);
                };

                ctx.Update(target);
            }
        }
Ejemplo n.º 2
0
 public void GetQueryTest()
 {
     using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountPlugin>())
     {
         var query = ctx.GetQuery <Entities.Contact>();
         Assert.IsNotNull(query);
     }
 }
        public void UniqueKeyQueryTest()
        {
            using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountCreatePlugin>())
            {
                var id = Guid.NewGuid();
                ctx.AddEntity(new Entities.Account {
                    AccountId = id, Name = "Kurt"
                });

                var accountQuery = ctx.GetQuery <Entities.Account>();
                var kurt         = (from a in accountQuery where a.AccountId == id select a).Single();

                Assert.AreEqual("Kurt", kurt.Name);
            }
        }
        public void TwoInnerJoinEntityQueryTest()
        {
            using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountCreatePlugin>())
            {
                var a1 = new Entities.Account {
                    AccountId = Guid.NewGuid(), Name = "Kurt A/S"
                };
                var a2 = new Entities.Account {
                    AccountId = Guid.NewGuid(), Name = "Lars ApS"
                };

                var c1 = new Entities.Contact {
                    ContactId = Guid.NewGuid(), FirstName = "Kurt", LastName = "Jensen", ParentCustomerId = new Microsoft.Xrm.Sdk.EntityReference(Entities.Account.EntityLogicalName, a1.AccountId.Value)
                };
                var c2 = new Entities.Contact {
                    ContactId = Guid.NewGuid(), FirstName = "Kurt", LastName = "Vilhjem", ParentCustomerId = new Microsoft.Xrm.Sdk.EntityReference(Entities.Account.EntityLogicalName, a1.AccountId.Value)
                };
                var c3 = new Entities.Contact {
                    ContactId = Guid.NewGuid(), FirstName = "Lars", LastName = "Madsen", ParentCustomerId = new Microsoft.Xrm.Sdk.EntityReference(Entities.Account.EntityLogicalName, a2.AccountId.Value)
                };

                ctx.AddEntity(a1);
                ctx.AddEntity(a2);

                ctx.AddEntity(c1);
                ctx.AddEntity(c2);
                ctx.AddEntity(c3);

                var accountQuery = ctx.GetQuery <Entities.Account>();
                var contactQuery = ctx.GetQuery <Entities.Contact>();
                var kurt         = (from a in accountQuery
                                    join c in contactQuery on a.AccountId equals c.ParentCustomerId.Id
                                    where a.Name == "Kurt A/S"
                                    select new
                {
                    Name = a.Name,
                    Firstname = c.FirstName,
                    Lastname = c.LastName
                }).ToArray().OrderBy(r => r.Lastname).ToArray();

                Assert.AreEqual(2, kurt.Length);

                Assert.AreEqual("Kurt A/S", kurt.First().Name);
                Assert.AreEqual("Jensen", kurt.First().Lastname);
                Assert.AreEqual("Vilhjem", kurt.Last().Lastname);
            }
        }
        public void TestForeignKeyQueryTest()
        {
            using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountCreatePlugin>())
            {
                var id = Guid.NewGuid();
                var primaryContactId = new Microsoft.Xrm.Sdk.EntityReference {
                    LogicalName = Entities.Contact.EntityLogicalName, Id = Guid.NewGuid()
                };
                ctx.AddEntity(new Entities.Account {
                    AccountId = id, Name = "Kurt", PrimaryContactId = primaryContactId
                });

                var accountQuery = ctx.GetQuery <Entities.Account>();
                var kurt         = (from a in accountQuery where a.PrimaryContactId.Id == primaryContactId.Id select a).Single();

                Assert.AreEqual("Kurt", kurt.Name);

                kurt = (from a in accountQuery where a.PrimaryContactId == primaryContactId select a).Single();

                Assert.AreEqual("Kurt", kurt.Name);
            }
        }
Ejemplo n.º 6
0
        public void CreateTest()
        {
            using (var ctx = PluginExecutionFakeContext.ForType <Kipon.Solid.Plugin.Plugins.Account.AccountCreatePlugin>())
            {
                ctx.AddEntity(new Entities.Account {
                    AccountId = Guid.NewGuid(), Name = "Jens"
                });

                var target = new Entities.Account
                {
                    Name = "kurt"
                };

                ctx.OnValidation = delegate()
                {
                    Assert.IsNotNull(target.AccountId);
                    Assert.AreEqual(100M, target.CreditLimit.Value);
                    Assert.AreEqual("Jens", target.Name);
                };

                ctx.Create(target);
            }
        }