public void FindByPKNumericTest() { Assert.NotNull(dbc = new DBContext(settings.Database.ConnectionString, logger)); ContactRepository contactRepos = new ContactRepository(settings, logger, dbc); CityRepository cityRepos = new CityRepository(settings, logger, dbc); Contact contact = contactRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.NotNull(contact); City city = cityRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.NotNull(city); }
public void UpdateTest() { string oldString = String.Empty; string updateString = String.Empty; int rows = 0; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { ContactRepository contactRepos = new ContactRepository(settings, logger, db); CityRepository cityRepos = new CityRepository(settings, logger, db); StateRepository stateRepos = new StateRepository(settings, logger, db); #region Update Contact Test oldString = "No notes"; updateString = "Updated note."; Contact contact = contactRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.NotNull(contact); Assert.Equal(contact.Notes, oldString); contact.Notes = updateString; rows = contactRepos.Update(contact); Assert.Equal(1, rows); contact = contactRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.Equal(contact.Notes, updateString); #endregion #region Update City Test oldString = "Tampa"; updateString = "Tampa(Updated)"; City city = cityRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.NotNull(city); Assert.Equal(city.Name, oldString); city.Name = updateString; rows = cityRepos.Update(city); Assert.Equal(1, rows); city = cityRepos.FindByPK(new PrimaryKey() { Key = 1 }); Assert.Equal(city.Name, updateString); #endregion #region Update State Test oldString = "NA"; updateString = "NA(Updated)"; State state = stateRepos.FindByPK(new PrimaryKey() { Key = "00" }); Assert.NotNull(state); Assert.Equal(state.Name, oldString); state.Name = updateString; rows = stateRepos.Update(state); Assert.Equal(1, rows); state = stateRepos.FindByPK(new PrimaryKey() { Key = "00" }); Assert.Equal(state.Name, updateString); #endregion } }
public void DeleteTest() { int rows = 0; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { Assert.NotNull(db); ContactRepository contactRepos = new ContactRepository(settings, logger, db); CityRepository cityRepos = new CityRepository(settings, logger, db); StateRepository stateRepos = new StateRepository(settings, logger, db); #region Delete Contact Test Contact contact = contactRepos.FindByPK(new PrimaryKey() { Key = 8 }); Assert.NotNull(contact); rows = contactRepos.Delete(new PrimaryKey() { Key = 8 }); Assert.Equal(1, rows); contact = contactRepos.FindByPK(new PrimaryKey() { Key = 8 }); Assert.Null(contact); #endregion #region Delete City Test City city = cityRepos.FindByPK(new PrimaryKey() { Key = 17 }); Assert.NotNull(city); rows = cityRepos.Delete(new PrimaryKey() { Key = 17 }); Assert.Equal(1, rows); city = cityRepos.FindByPK(new PrimaryKey() { Key = 17 }); Assert.Null(city); #endregion #region Delete State Test State state = stateRepos.FindByPK(new PrimaryKey() { Key = "WA" }); Assert.NotNull(state); rows = stateRepos.Delete(new PrimaryKey() { Key = "WA" }); Assert.Equal(1, rows); state = stateRepos.FindByPK(new PrimaryKey() { Key = "WA" }); Assert.Null(state); #endregion } }
public void AddTest() { int key = 0; string naturalKey = String.Empty; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { Assert.NotNull(db); ContactRepository contactRepos = new ContactRepository(settings, logger, db); CityRepository cityRepos = new CityRepository(settings, logger, db); StateRepository stateRepos = new StateRepository(settings, logger, db); #region Add Contact Test Contact contact = new Contact() { FirstName = "New", LastName = "User", Address1 = "Address1", Address2 = "Address2", CellPhone = "8005551212", HomePhone = "8005551212", WorkPhone = "8005551212", Notes = String.Empty, ZipCode = "99999", EMail = "*****@*****.**", CityId = 1 }; ICollection <Contact> contacts = contactRepos.FindAll(); Assert.Null(contacts.Where(c => c.LastName == contact.LastName && c.FirstName == contact.FirstName).FirstOrDefault()); key = (int)contactRepos.Add(contact); Assert.True(key > 0); Assert.NotNull(contactRepos.FindByPK(new PrimaryKey() { Key = key })); #endregion #region Add City Test City city = new City() { Name = "New City", StateId = "FL" }; ICollection <City> cities = cityRepos.FindAll(); Assert.Null(cities.Where(c => c.Name == city.Name).FirstOrDefault()); key = (int)cityRepos.Add(city); Assert.True(key > 0); Assert.NotNull(cityRepos.FindByPK(new PrimaryKey() { Key = key })); #endregion #region Add State Test State newState = new State() { Id = "ZZ", Name = "New State" }; State state = stateRepos.FindByPK(new PrimaryKey() { Key = newState.Id, IsIdentity = false }); Assert.Null(state); naturalKey = (string)stateRepos.Add(newState); Assert.True(naturalKey == (string)newState.PK.Key); Assert.NotNull(stateRepos.FindByPK(new PrimaryKey() { Key = newState.Id, IsIdentity = false })); #endregion } }
public async Task DeleteTest() { int rows = 0; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { Assert.NotNull(db); ContactRepository contactRepos = new ContactRepository(settings, logger, db); CityRepository cityRepos = new CityRepository(settings, logger, db); StateRepository stateRepos = new StateRepository(settings, logger, db); ProjectContactRepository projectContactRepos = new ProjectContactRepository(settings, logger, db); #region Delete Contact Test Contact contact = await contactRepos.FindByPK(new PrimaryKey() { Key = 8 }); Assert.NotNull(contact); rows = await contactRepos.Delete(new PrimaryKey() { Key = 8 }); Assert.Equal(1, rows); contact = await contactRepos.FindByPK(new PrimaryKey() { Key = 8 }); Assert.Null(contact); #endregion #region Delete City Test City city = await cityRepos.FindByPK(new PrimaryKey() { Key = 17 }); Assert.NotNull(city); rows = await cityRepos.Delete(new PrimaryKey() { Key = 17 }); Assert.Equal(1, rows); city = await cityRepos.FindByPK(new PrimaryKey() { Key = 17 }); Assert.Null(city); #endregion #region Delete State Test State state = await stateRepos.FindByPK(new PrimaryKey() { Key = "WA" }); Assert.NotNull(state); rows = await stateRepos.Delete(new PrimaryKey() { Key = "WA" }); Assert.Equal(1, rows); state = await stateRepos.FindByPK(new PrimaryKey() { Key = "WA" }); Assert.Null(state); #endregion #region Delete ProjectContact Test ProjectContact projectContact = await projectContactRepos.FindByPK(new PrimaryKey() { CompositeKey = new object[] { 1, 1 }, IsComposite = true }); Assert.NotNull(projectContact); rows = await projectContactRepos.Delete(new PrimaryKey() { CompositeKey = new object[] { 1, 1 }, IsComposite = true }); Assert.Equal(1, rows); projectContact = await projectContactRepos.FindByPK(new PrimaryKey() { CompositeKey = new object[] { 1, 1 }, IsComposite = true }); Assert.Null(projectContact); #endregion } }
public async Task AddTest() { int key = 0; using (DBContext db = new DBContext(settings.Database.ConnectionString, logger)) { Assert.NotNull(db); ContactRepository contactRepos = new ContactRepository(settings, logger, db); CityRepository cityRepos = new CityRepository(settings, logger, db); StateRepository stateRepos = new StateRepository(settings, logger, db); ProjectContactRepository projectContactRepos = new ProjectContactRepository(settings, logger, db); #region Add Contact Test Contact contact = new Contact() { FirstName = "New", LastName = "User", Address1 = "Address1", Address2 = "Address2", CellPhone = "8005551212", HomePhone = "8005551212", WorkPhone = "8005551212", Notes = String.Empty, ZipCode = "99999", EMail = "*****@*****.**", CityId = 1 }; ICollection <Contact> contacts = await contactRepos.FindAll(); Assert.Null(contacts.Where(c => c.LastName == contact.LastName && c.FirstName == contact.FirstName).FirstOrDefault()); key = (int)await contactRepos.Add(contact); Assert.True(key > 0); Assert.NotNull(await contactRepos.FindByPK(new PrimaryKey() { Key = key })); #endregion #region Add City Test City city = new City() { Name = "New City", StateId = "FL" }; ICollection <City> cities = await cityRepos.FindAll(); Assert.Null(cities.Where(c => c.Name == city.Name).FirstOrDefault()); key = (int)await cityRepos.Add(city); Assert.True(key > 0); Assert.NotNull(await cityRepos.FindByPK(new PrimaryKey() { Key = key })); #endregion #region Add State Test State newState = new State() { Id = "ZZ", Name = "New State" }; State state = await stateRepos.FindByPK(new PrimaryKey() { Key = newState.Id }); Assert.Null(state); key = (int)await stateRepos.Add(newState); Assert.True(key > 0); Assert.NotNull(await stateRepos.FindByPK(new PrimaryKey() { Key = newState.Id })); #endregion #region Add ProjectContact Test ProjectContact projectContact = new ProjectContact() { ProjectId = 2, ContactId = 23 }; ICollection <ProjectContact> projectContacts = await projectContactRepos.FindAll(); Assert.Null(projectContacts.Where(c => c.ProjectId == projectContact.ProjectId && c.ContactId == projectContact.ContactId).FirstOrDefault()); key = (int)await projectContactRepos.Add(projectContact); // returns number of rows added Assert.True(key > 0); Assert.NotNull(await projectContactRepos.FindByPK(new PrimaryKey() { CompositeKey = new object[] { projectContact.ProjectId, projectContact.ContactId }, IsComposite = true })); #endregion } }