Esempio n. 1
0
        public void Entity_With_MultipleEntry_Associated_Collection()
        {
            var entity = new PersonWithFriends
            {
                PersonWithFriendsID = 10,
                Age     = 93,
                Name    = "Yoni",
                Friends = new List <PersonWithFriends>(new[] {
                    new PersonWithFriends {
                        PersonWithFriendsID = 99
                    },
                    new PersonWithFriends {
                        PersonWithFriendsID = 100
                    }, new PersonWithFriends {
                        PersonWithFriendsID = 101
                    }
                })
            };

            Serializer subject = SerializationTestHelper.CreateSerializer(typeof(PersonWithFriends));
            JObject    doc     = subject.Serialize("2-update", "person-with-friends", entity);

            Assert.IsNotNull(doc, "Fail to serialize simple entity");
            Assert.AreEqual(10, doc.Value <int>("_id"));
            Assert.AreEqual(93, doc.Value <int>("age"));
            Assert.AreEqual("Yoni", doc.Value <string>("name"));

            var associatedArray = (JArray)doc["friends"];

            CollectionAssert.AreEqual(new[] { 99, 100, 101 }, JArrayHelper.ArrayOf <int>(associatedArray));
        }
Esempio n. 2
0
        public void AutoRefresh()
        {
            var friend1 = new PersonWithFriends("Friend1", 40);
            var friend2 = new PersonWithFriends("Friend2", 45);

            var person = new PersonWithFriends("Person", 50);

            _source.Add(person);

            person.Friends = new[] { friend1, friend2 };

            _results.Data.Count.Should().Be(2, "Should be 2 in the cache");
            _results.Data.Items.Should().BeEquivalentTo(friend1, friend2);
        }
Esempio n. 3
0
        public void DirectRefresh()
        {
            var friends = new List <PersonWithFriends> {
                new PersonWithFriends("Friend1", 40)
            };
            var person = new PersonWithFriends("Person", 50, friends);

            _source.AddOrUpdate(person);

            friends.Add(new PersonWithFriends("Friend2", 45));
            _source.Refresh(person);

            _results.Data.Count.Should().Be(2, "Should be 2 in the cache");
            _results.Data.Lookup("Friend1").HasValue.Should().BeTrue();
            _results.Data.Lookup("Friend2").HasValue.Should().BeTrue();
        }
Esempio n. 4
0
        public void AutoRefresh()
        {
            var person = new PersonWithFriends("Person", 50);

            _source.AddOrUpdate(person);

            person.Friends = new[]
            {
                new PersonWithFriends("Friend1", 40),
                new PersonWithFriends("Friend2", 45)
            };

            _results.Data.Count.Should().Be(2, "Should be 2 in the cache");
            _results.Data.Lookup("Friend1").HasValue.Should().BeTrue();
            _results.Data.Lookup("Friend2").HasValue.Should().BeTrue();
        }
Esempio n. 5
0
        public void AutoRefreshRecursive()
        {
            var friend1 = new PersonWithFriends("Friend1", 30);
            var friend2 = new PersonWithFriends("Friend2", 35);
            var friend3 = new PersonWithFriends("Friend3", 40, new[] { friend1 });
            var friend4 = new PersonWithFriends("Friend4", 45, new[] { friend2 });

            var person = new PersonWithFriends("Person", 50, new[] { friend3 });

            _source.Add(person);

            person.Friends = new[] { friend4 };

            _results.Data.Count.Should().Be(2, "Should be 2 in the cache");
            _results.Data.Items.Should().BeEquivalentTo(friend4, friend2);
        }
Esempio n. 6
0
        public void AutoRefreshOnOtherProperty()
        {
            var friend1 = new PersonWithFriends("Friend1", 40);
            var friend2 = new PersonWithFriends("Friend2", 45);
            var friends = new List <PersonWithFriends> {
                friend1
            };
            var person = new PersonWithFriends("Person", 50, friends);

            _source.Add(person);

            friends.Add(friend2);
            person.Age = 55;

            _results.Data.Count.Should().Be(2, "Should be 2 in the cache");
            _results.Data.Items.Should().BeEquivalentTo(friend1, friend2);
        }
Esempio n. 7
0
        public void Entity_With_Empty_Associated_Collection()
        {
            var entity = new PersonWithFriends
            {
                PersonWithFriendsID = 10,
                Age     = 93,
                Name    = "Yoni",
                Friends = new List <PersonWithFriends>()
            };

            Serializer subject = SerializationTestHelper.CreateSerializer(typeof(PersonWithFriends));
            JObject    doc     = subject.Serialize("2-update", "person-with-friends", entity);

            Assert.IsNotNull(doc, "Fail to serialize simple entity");
            Assert.AreEqual(10, doc.Value <int>("_id"));
            Assert.AreEqual(93, doc.Value <int>("age"));
            Assert.AreEqual("Yoni", doc.Value <string>("name"));
            Assert.IsNull(doc["friends"]);
        }