Inheritance: ObjectRepositoryBase
Example #1
0
        public void TestThatDeletingChildrenDoesntBreaks()
        {
            // Given
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id
                }
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();
            instance.Remove <ChildModel>(v => true);

            // Then
            // no exceptions
            var parentModel = instance.Set <ParentModel>().Single();
            var childModel  = instance.Set <ChildModel>().ToArray();

            Assert.AreEqual(parentModel.Children.Count(), 0);
            Assert.AreEqual(parentModel.OptionalChildren.Count(), 0);
            Assert.AreEqual(childModel.Length, 0);
        }
Example #2
0
        public void TestThatNoNotifyWhenValueNotChanged()
        {
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id, Property = "2"
                }
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            var child = instance.Set <ChildModel>().First();

            Assert.IsNotNull(child);
            var shouldFail = false;

            instance.ModelChanged += (a) =>
            {
                if (shouldFail)
                {
                    throw new Exception();
                }
            };

            child.Property = "3";
            shouldFail     = true;
            child.Property = "3";
            shouldFail     = false;
            child.Property = "2";
        }
Example #3
0
        public void TestThatRelationsWorks()
        {
            // Given
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id
                }
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            // Then
            // no exceptions

            var parentModel = instance.Set <ParentModel>().Single();
            var childModel  = instance.Set <ChildModel>().Single();

            Assert.AreEqual(parentModel.Children.Single(), childModel);
            Assert.AreEqual(parentModel.OptionalChildren.Count(), 0);
            Assert.AreEqual(childModel.Parent, parentModel);
            Assert.AreEqual(childModel.ParentOptional, null);
        }
Example #4
0
        public void TestThatCustomIndexesWorksAfterPropertyChange()
        {
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id, Property = "1"
                },
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id, Property = "2"
                }
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            instance.Set <ChildModel>().AddIndex(() => x => x.Property);
            var child = instance.Set <ChildModel>().Find(() => x => x.Property, "2");

            Assert.IsNotNull(child);
            Assert.AreEqual(child.Property, "2");

            child.Property = "3";

            Assert.IsNull(instance.Set <ChildModel>().Find(() => x => x.Property, "2"));

            Assert.AreEqual(child, instance.Set <ChildModel>().Find(() => x => x.Property, "3"));
        }
Example #5
0
        public void CtorShouldNotThrowException()
        {
            // Given
            var instance = new TestObjectRepository(new TestStorage());

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            // Then
            // no exceptions
        }
Example #6
0
        public void TestThatFindWorks()
        {
            // Given
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            var set = instance.Set <ParentModel>();

            Assert.AreEqual(set.Find(id), set.Single());
            Assert.AreEqual(set.Find(Guid.Empty), null);
        }
Example #7
0
        public void TestThatSingleOnUnattachedItemDoesNotThrows()
        {
            // Given
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            // Then
            // no exceptions

            var parentModel = instance.Set <ParentModel>().Single();

            var childModel = new ChildModel(new ChildEntity(Guid.NewGuid()));

            childModel.Parent = parentModel;
        }
Example #8
0
        public void TestThatPropertyUpdaterNotLeaks()
        {
            var id          = Guid.NewGuid();
            var testStorage = new TestStorage
            {
                new ParentEntity(id),
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id, Property = "1"
                },
                new ChildEntity(Guid.NewGuid())
                {
                    ParentId = id, Property = "2"
                }
            };

            var instance = new TestObjectRepository(testStorage);

            // When
            instance.WaitForInitialize().GetAwaiter().GetResult();

            instance.Set <ChildModel>().AddIndex(() => x => x.Property);
            var child = instance.Set <ChildModel>().Find(() => x => x.Property, "2");

            Assert.IsNotNull(child);
            Assert.AreEqual(child.Property, "2");

            child.Property = "3";

            var count = ModelBase.PropertyUpdater <ChildEntity, string> .Cache.Count;

            child.Property = "2";

            var newCount = ModelBase.PropertyUpdater <ChildEntity, string> .Cache.Count;

            Assert.AreEqual(count, newCount, "Memory leak!");
        }