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"; }
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); }
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); }
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")); }
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); }
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; }
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!"); }