示例#1
0
        public void Associate_GetAssociatedEntities()
        {
            ChangeSet changeSet = new ChangeSet(this.GenerateEntityOperations(true));

            MockEntity1     clientEntity1 = changeSet.ChangeSetEntries.Select(e => e.Entity).OfType <MockEntity1>().First();
            MockEntity2     clientEntity2 = changeSet.ChangeSetEntries.Select(e => e.Entity).OfType <MockEntity2>().First();
            MockStoreEntity storeEntity   = new MockStoreEntity();

            changeSet.Associate(clientEntity1, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity2, storeEntity, (c, s) => { });

            IEnumerable <MockEntity1> clientEntities1 = changeSet.GetAssociatedEntities <MockEntity1, MockStoreEntity>(storeEntity);

            Assert.IsNotNull(clientEntities1, "Expected to clientEntities1 to not be null.");
            Assert.AreEqual(1, clientEntities1.Count(), "Expected to find 1 clientEntity entry.");
            Assert.AreSame(clientEntity1, clientEntities1.Single(), "Expected to find clientEntity1.");

            IEnumerable <MockEntity2> clientEntities2 = changeSet.GetAssociatedEntities <MockEntity2, MockStoreEntity>(storeEntity);

            Assert.IsNotNull(clientEntities2, "Expected to clientEntities to not be null.");
            Assert.AreEqual(1, clientEntities2.Count(), "Expected to find 1 clientEntity entry.");
            Assert.AreSame(clientEntity2, clientEntities2.Single(), "Expected to find clientEntity2.");

            IEnumerable <object> clientEntities3 = changeSet.GetAssociatedEntities <object, MockStoreEntity>(storeEntity);

            Assert.IsNotNull(clientEntities3, "Expected to clientEntities to not be null.");
            Assert.AreEqual(2, clientEntities3.Count(), "Expected to find 2 clientEntity entries.");
            Assert.IsTrue(clientEntities3.Contains(clientEntity1), "Expected to find clientEntity1.");
            Assert.IsTrue(clientEntities3.Contains(clientEntity2), "Expected to find clientEntity2.");
        }
示例#2
0
        public void Associate_EntityTransform()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1     clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity  = new MockStoreEntity()
            {
                ID        = 1,
                FirstName = "StoreFName",
                LastName  = "StoreLName"
            };

            changeSet.Associate(
                clientEntity,
                storeEntity,
                (c, s) => c.FullName = (s.FirstName + " " + s.LastName));

            Assert.AreEqual("FName0 LName0", clientEntity.FullName, "Expected clientEntity FullName to remain unchanged.");
            Assert.AreEqual("StoreFName", storeEntity.FirstName, "Expected storeEntity FirstName to remain unchanged.");
            Assert.AreEqual("StoreLName", storeEntity.LastName, "Expected storeEntity LastName to remain unchanged.");

            changeSet.ApplyAssociatedStoreEntityTransforms();

            Assert.AreEqual("StoreFName StoreLName", clientEntity.FullName, "Expected clientEntity FullName to have changed.");
            Assert.AreEqual("StoreFName", storeEntity.FirstName, "Expected storeEntity FirstName to remain unchanged.");
            Assert.AreEqual("StoreLName", storeEntity.LastName, "Expected storeEntity LastName to remain unchanged.");
        }
示例#3
0
        public void Associate_EntityTransform_Multiple()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1     clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity1 = new MockStoreEntity()
            {
                ID        = 1,
                FirstName = "Store1FName",
                LastName  = "Store1LName"
            };
            MockStoreEntity storeEntity2 = new MockStoreEntity()
            {
                ID        = 2,
                FirstName = "Store2FName",
                LastName  = "Store2LName"
            };

            changeSet.Associate(clientEntity, storeEntity1, (c, s) => c.FullName += s.FirstName);
            changeSet.Associate(clientEntity, storeEntity2, (c, s) => c.FullName += s.FirstName);

            Assert.AreEqual("FName0 LName0", clientEntity.FullName, "Expected clientEntity FullName to remain unchanged.");
            Assert.AreEqual("Store1FName", storeEntity1.FirstName, "Expected storeEntity1 FirstName to remain unchanged.");
            Assert.AreEqual("Store1LName", storeEntity1.LastName, "Expected storeEntity1 LastName to remain unchanged.");
            Assert.AreEqual("Store2FName", storeEntity2.FirstName, "Expected storeEntity2 FirstName to remain unchanged.");
            Assert.AreEqual("Store2LName", storeEntity2.LastName, "Expected storeEntity2 LastName to remain unchanged.");

            changeSet.ApplyAssociatedStoreEntityTransforms();

            Assert.AreEqual("FName0 LName0Store1FNameStore2FName", clientEntity.FullName, "Expected clientEntity FullName to have changed.");
            Assert.AreEqual("Store1FName", storeEntity1.FirstName, "Expected storeEntity1 FirstName to remain unchanged.");
            Assert.AreEqual("Store1LName", storeEntity1.LastName, "Expected storeEntity1 LastName to remain unchanged.");
            Assert.AreEqual("Store2FName", storeEntity2.FirstName, "Expected storeEntity2 FirstName to remain unchanged.");
            Assert.AreEqual("Store2LName", storeEntity2.LastName, "Expected storeEntity2 LastName to remain unchanged.");
        }
示例#4
0
        public void Associate_GetAssociatedEntities_NotFound()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1     clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity  = new MockStoreEntity();

            changeSet.Associate(clientEntity, storeEntity, (c, s) => { });

            IEnumerable <MockEntity1> clientEntities = changeSet.GetAssociatedEntities <MockEntity1, MockStoreEntity>(new MockStoreEntity());

            Assert.IsNotNull(clientEntities, "Expected to clientEntities to not be null.");
            Assert.AreEqual(0, clientEntities.Count(), "Expected to find 0 clientEntity entries.");
        }
示例#5
0
        public void Associate_GetAssociatedEntities_Multiple()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1     clientEntity1 = (MockEntity1)changeSet.ChangeSetEntries.Skip(0).First().Entity;
            MockEntity1     clientEntity2 = (MockEntity1)changeSet.ChangeSetEntries.Skip(1).First().Entity;
            MockEntity1     clientEntity3 = (MockEntity1)changeSet.ChangeSetEntries.Skip(2).First().Entity;
            MockStoreEntity storeEntity   = new MockStoreEntity();

            changeSet.Associate(clientEntity1, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity2, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity3, storeEntity, (c, s) => { });

            IEnumerable <MockEntity1> clientEntities = changeSet.GetAssociatedEntities <MockEntity1, MockStoreEntity>(storeEntity);

            Assert.IsNotNull(clientEntities, "Expected to find a non-null return value.");
            Assert.AreEqual(3, clientEntities.Count(), "Expected to find 3 clientEntities entries.");
            Assert.IsTrue(clientEntities.Contains(clientEntity1), "Expected to find clientEntities1 in the associated entities collection.");
            Assert.IsTrue(clientEntities.Contains(clientEntity2), "Expected to find clientEntities2 in the associated entities collection.");
            Assert.IsTrue(clientEntities.Contains(clientEntity3), "Expected to find clientEntities3 in the associated entities collection.");
        }
        public void Associate_GetAssociatedEntities_Multiple()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1 clientEntity1 = (MockEntity1)changeSet.ChangeSetEntries.Skip(0).First().Entity;
            MockEntity1 clientEntity2 = (MockEntity1)changeSet.ChangeSetEntries.Skip(1).First().Entity;
            MockEntity1 clientEntity3 = (MockEntity1)changeSet.ChangeSetEntries.Skip(2).First().Entity;
            MockStoreEntity storeEntity = new MockStoreEntity();

            changeSet.Associate(clientEntity1, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity2, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity3, storeEntity, (c, s) => { });

            IEnumerable<MockEntity1> clientEntities = changeSet.GetAssociatedEntities<MockEntity1, MockStoreEntity>(storeEntity);

            Assert.IsNotNull(clientEntities, "Expected to find a non-null return value.");
            Assert.AreEqual(3, clientEntities.Count(), "Expected to find 3 clientEntities entries.");
            Assert.IsTrue(clientEntities.Contains(clientEntity1), "Expected to find clientEntities1 in the associated entities collection.");
            Assert.IsTrue(clientEntities.Contains(clientEntity2), "Expected to find clientEntities2 in the associated entities collection.");
            Assert.IsTrue(clientEntities.Contains(clientEntity3), "Expected to find clientEntities3 in the associated entities collection.");
        }
        public void Associate_GetAssociatedEntities_NotFound()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1 clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity = new MockStoreEntity();

            changeSet.Associate(clientEntity, storeEntity, (c, s) => { });

            IEnumerable<MockEntity1> clientEntities = changeSet.GetAssociatedEntities<MockEntity1, MockStoreEntity>(new MockStoreEntity());

            Assert.IsNotNull(clientEntities, "Expected to clientEntities to not be null.");
            Assert.AreEqual(0, clientEntities.Count(), "Expected to find 0 clientEntity entries.");
        }
        public void Associate_GetAssociatedEntities()
        {
            ChangeSet changeSet = new ChangeSet(this.GenerateEntityOperations(true));

            MockEntity1 clientEntity1 = changeSet.ChangeSetEntries.Select(e => e.Entity).OfType<MockEntity1>().First();
            MockEntity2 clientEntity2 = changeSet.ChangeSetEntries.Select(e => e.Entity).OfType<MockEntity2>().First();
            MockStoreEntity storeEntity = new MockStoreEntity();

            changeSet.Associate(clientEntity1, storeEntity, (c, s) => { });
            changeSet.Associate(clientEntity2, storeEntity, (c, s) => { });

            IEnumerable<MockEntity1> clientEntities1 = changeSet.GetAssociatedEntities<MockEntity1, MockStoreEntity>(storeEntity);
            Assert.IsNotNull(clientEntities1, "Expected to clientEntities1 to not be null.");
            Assert.AreEqual(1, clientEntities1.Count(), "Expected to find 1 clientEntity entry.");
            Assert.AreSame(clientEntity1, clientEntities1.Single(), "Expected to find clientEntity1.");

            IEnumerable<MockEntity2> clientEntities2 = changeSet.GetAssociatedEntities<MockEntity2, MockStoreEntity>(storeEntity);
            Assert.IsNotNull(clientEntities2, "Expected to clientEntities to not be null.");
            Assert.AreEqual(1, clientEntities2.Count(), "Expected to find 1 clientEntity entry.");
            Assert.AreSame(clientEntity2, clientEntities2.Single(), "Expected to find clientEntity2.");

            IEnumerable<object> clientEntities3 = changeSet.GetAssociatedEntities<object, MockStoreEntity>(storeEntity);
            Assert.IsNotNull(clientEntities3, "Expected to clientEntities to not be null.");
            Assert.AreEqual(2, clientEntities3.Count(), "Expected to find 2 clientEntity entries.");
            Assert.IsTrue(clientEntities3.Contains(clientEntity1), "Expected to find clientEntity1.");
            Assert.IsTrue(clientEntities3.Contains(clientEntity2), "Expected to find clientEntity2.");
        }
        public void Associate_EntityTransform_Multiple()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1 clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity1 = new MockStoreEntity()
            {
                ID = 1,
                FirstName = "Store1FName",
                LastName = "Store1LName"
            };
            MockStoreEntity storeEntity2 = new MockStoreEntity()
            {
                ID = 2,
                FirstName = "Store2FName",
                LastName = "Store2LName"
            };

            changeSet.Associate(clientEntity, storeEntity1, (c, s) => c.FullName += s.FirstName);
            changeSet.Associate(clientEntity, storeEntity2, (c, s) => c.FullName += s.FirstName);

            Assert.AreEqual("FName0 LName0", clientEntity.FullName, "Expected clientEntity FullName to remain unchanged.");
            Assert.AreEqual("Store1FName", storeEntity1.FirstName, "Expected storeEntity1 FirstName to remain unchanged.");
            Assert.AreEqual("Store1LName", storeEntity1.LastName, "Expected storeEntity1 LastName to remain unchanged.");
            Assert.AreEqual("Store2FName", storeEntity2.FirstName, "Expected storeEntity2 FirstName to remain unchanged.");
            Assert.AreEqual("Store2LName", storeEntity2.LastName, "Expected storeEntity2 LastName to remain unchanged.");

            changeSet.ApplyAssociatedStoreEntityTransforms();

            Assert.AreEqual("FName0 LName0Store1FNameStore2FName", clientEntity.FullName, "Expected clientEntity FullName to have changed.");
            Assert.AreEqual("Store1FName", storeEntity1.FirstName, "Expected storeEntity1 FirstName to remain unchanged.");
            Assert.AreEqual("Store1LName", storeEntity1.LastName, "Expected storeEntity1 LastName to remain unchanged.");
            Assert.AreEqual("Store2FName", storeEntity2.FirstName, "Expected storeEntity2 FirstName to remain unchanged.");
            Assert.AreEqual("Store2LName", storeEntity2.LastName, "Expected storeEntity2 LastName to remain unchanged.");
        }
        public void Associate_EntityTransform()
        {
            ChangeSet changeSet = this.GenerateChangeSet();

            MockEntity1 clientEntity = (MockEntity1)changeSet.ChangeSetEntries.First().Entity;
            MockStoreEntity storeEntity = new MockStoreEntity()
            {
                ID = 1,
                FirstName = "StoreFName",
                LastName = "StoreLName"
            };

            changeSet.Associate(
                clientEntity,
                storeEntity,
                (c, s) => c.FullName = (s.FirstName + " " + s.LastName));

            Assert.AreEqual("FName0 LName0", clientEntity.FullName, "Expected clientEntity FullName to remain unchanged.");
            Assert.AreEqual("StoreFName", storeEntity.FirstName, "Expected storeEntity FirstName to remain unchanged.");
            Assert.AreEqual("StoreLName", storeEntity.LastName, "Expected storeEntity LastName to remain unchanged.");

            changeSet.ApplyAssociatedStoreEntityTransforms();

            Assert.AreEqual("StoreFName StoreLName", clientEntity.FullName, "Expected clientEntity FullName to have changed.");
            Assert.AreEqual("StoreFName", storeEntity.FirstName, "Expected storeEntity FirstName to remain unchanged.");
            Assert.AreEqual("StoreLName", storeEntity.LastName, "Expected storeEntity LastName to remain unchanged.");
        }