public void GetTable_ReturnsExistingTable() { InMemoryDb db = new InMemoryDb(); Assert.IsTrue(db.TableCount() == 0); InMemoryDbTable <int, Person> people = db.GetTable <int, Person>(); Assert.IsNotNull(people); Assert.IsTrue(people.Count() == 0); Assert.IsTrue(db.TableCount() == 1); InMemoryDbTable <int, Address> address = db.GetTable <int, Address>(); Assert.IsNotNull(address); Assert.IsTrue(db.TableCount() == 2); Person person = new Person { FirstName = "first name", LastName = "last name" }; people.Add(person); Assert.IsTrue(people.Count() == 1); InMemoryDbTable <int, Person> peopleCopy = db.GetTable <int, Person>(); Assert.IsNotNull(peopleCopy); Assert.IsTrue(peopleCopy.Count() == 1); }
public void Create_Adds_Entities_To_The_Table_And_Sets_Int_Key() { 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(); // create int expectedCount = 0; foreach (Person person in people) { Assert.IsTrue(table.Count() == expectedCount++); Assert.IsTrue(repo.Add(person)); Assert.IsTrue(table.Count() == expectedCount); Assert.IsTrue(person.Id == expectedCount - 1); } }
public void Create_Adds_Entity_To_The_Table_And_Sets_String_Key() { InMemoryDb db = new InMemoryDb(); InMemoryDbTable <string, StringKey> table = db.GetTable <string, StringKey>(); Repository <string, StringKey> repo = new Repository <string, StringKey>(table); StringKey entity = new StringKey(); // create Assert.IsTrue(repo.Add(entity)); Assert.IsTrue(table.Count() == 1); Assert.IsTrue(entity.Id != null); }
public void Create_Adds_Entity_To_The_Table_And_Sets_Guid_Key() { InMemoryDb db = new InMemoryDb(); InMemoryDbTable <Guid, GuidKey> table = db.GetTable <Guid, GuidKey>(); Repository <Guid, GuidKey> repo = new Repository <Guid, GuidKey>(table); GuidKey entity = new GuidKey(); // create Assert.IsTrue(repo.Add(entity)); Assert.IsTrue(table.Count() == 1); Assert.IsTrue(entity.Id != Guid.Empty); }
public void Create_Adds_A_List_Of_Entities_To_The_Table() { 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(); // create Assert.IsTrue(repo.Add(people)); Assert.IsTrue(table.Count() == people.Count); Assert.IsTrue(repo.Count() == people.Count); Assert.IsTrue(repo.All().Count() == people.Count); }