public void Delete_Returns_False_If_Does_Not_Exist_And_Does_Not_Modify_List() { InMemoryDb db = new InMemoryDb(); InMemoryDbTable <int, Person> table = db.GetTable <int, Person>(); Repository <int, Person> repo = new Repository <int, Person>(table); List <Person> people = CreateRandomList(); repo.Add(people); // Create a new 'detached' person that does not exist. // Person doesNotExist = new Person { FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString() }; PrivateKeySetter privateKeySetter = new PrivateKeySetter(); privateKeySetter.SetKey(doesNotExist, 100); Assert.IsFalse(repo.Delete(doesNotExist)); Assert.IsTrue(repo.Count() == people.Count); foreach (Person person in people) { Assert.AreEqual(person, people[person.Id]); } }
public void Update_Returns_True_And_Modifies_Existing() { InMemoryDb db = new InMemoryDb(); InMemoryDbTable <int, Person> table = db.GetTable <int, Person>(); Repository <int, Person> repo = new Repository <int, Person>(table); List <Person> people = CreateRandomList(); repo.Add(people); // Create a new 'detached' person. // Person person1Updated = new Person { FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString() }; PrivateKeySetter privateKeySetter = new PrivateKeySetter(); privateKeySetter.SetKey(person1Updated, people[0].Id); Assert.IsTrue(repo.Update(person1Updated)); Assert.AreNotEqual(person1Updated, people[0]); Assert.IsTrue(repo.Count() == people.Count); }
public void IsKeyPrivate_Defaults_To_Expected_Convention() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); Assert.IsTrue(setter.IsKeyPrivate(test)); }
public void IsKeyPrivate_Throws_If_Property_Not_Found() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); setter.IsKeyPrivate(test, "NotFound"); }
public void IsKeyPrivate_Returns_True() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); Assert.IsTrue(setter.IsKeyPrivate(test, "PrivateSetter")); }
public void IsKeyPrivate_Returns_False() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); Assert.IsFalse(setter.IsKeyPrivate(test, "PublicSetter")); }
public void SetId_Throws_If_Property_Type_Not_Same_As_Value() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); const int idValue = 10; setter.SetKey(test, "PublicSetter", idValue); }
public void SetId_Throws_If_Property_Not_Found() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); const int idValue = 10; setter.SetKey(test, "Not Found", idValue); }
public void SetId_Defaults_To_Expected_Convention() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); const string idValue = "10"; Assert.IsTrue(setter.SetKey(test, idValue)); Assert.IsTrue(test.PrivateSetter == 0); Assert.IsTrue(test.PublicSetter == Guid.Empty); }
public void SetId_Returns_True_And_Sets_Property_With_Private_Setter() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); const int idValue = 10; Assert.IsTrue(setter.SetKey(test, "PrivateSetter", idValue)); Assert.IsTrue(test.Id == null); Assert.IsTrue(test.PrivateSetter == idValue); Assert.IsTrue(test.PublicSetter == Guid.Empty); }
public void SetId_Returns_True_And_Sets_Property_With_Public_Setter() { PrivateKeySetter setter = new PrivateKeySetter(); TestObj test = new TestObj(); Guid idValue = Guid.NewGuid(); Assert.IsTrue(setter.SetKey(test, "PublicSetter", idValue)); Assert.IsTrue(test.Id == null); Assert.IsTrue(test.PrivateSetter == 0); Assert.IsTrue(test.PublicSetter == idValue); }