public void UpdateCustomer_FromPOCO() { using (var cc = new CustomerContext()) { cc.Database.Delete(); cc.Database.Create(); } var repo = new Left4Edit.Models.Repo.EFCustomerRepo(); repo.AddCustomer(CreateTestCustomer_Mem().First()); repo.SaveChanges(); // Make sure the POCO customer was accepted Assert.IsTrue(repo.GetCustomers().Count() == 1 && repo.GetCustomers().First().Symbol == "ASA"); var customer = repo.GetCustomers().First(); customer.Name = "Made some Changes!"; repo.AddCredentialToCustomer( new Credential() { Domain = "Update Test", UserName = "******", Password = "******" }, customer.ID ); repo.UpdateCustomer(customer); repo.SaveChanges(); Assert.IsTrue( repo.GetCustomers().First() .Credentials.Where(c => c.Domain == "Update Test") .Count() == 1 ); Assert.IsTrue( repo.GetCustomers().Where(c => c.Name == "Made some Changes!").Count() == 1 ); }
public void EF_Customer_AddItems() { using (var cc = new CustomerContext()) { cc.Database.Delete(); cc.Database.Create(); } var repo = new Left4Edit.Models.Repo.EFCustomerRepo(); var customer = CreateTestCustomer_EF().ElementAt(0); repo.AddCustomer(customer); repo.SaveChanges(); var newCredential = repo.CreateCredential(); newCredential.Domain = "+DOMAIN"; newCredential.UserName = "******"; newCredential.Password = "******"; repo.AddCredentialToCustomer(newCredential, customer.ID); repo.SaveChanges(); var newContact = repo.CreateContact(); newContact.FirstName = "Added"; newContact.LastName = "Contact"; newContact.Email = "*****@*****.**"; repo.AddContactToCustomer(newContact, customer.ID); //repo.SaveChanges(); var newNode = repo.CreateNode(); newNode.Name = "Added node"; newNode.Address = "added.billmcg.com"; repo.AddNodeToCustomer(newNode, customer.ID); repo.AddCredentialToNode(newCredential, newNode.ID); repo.SaveChanges(); // Assert tiem var node = repo.GetNodes().Where(n => n.Name == "Added node").First(); Assert.IsTrue(node.Credentials.Any(c => c.Domain == "+DOMAIN")); var contact = repo.GetCustomerContacts(customer.ID) .Where(c => c.Email == "*****@*****.**") .First(); Assert.IsTrue(contact.LastName == "Contact"); var sharedCredential = customer.Credentials.Where(c => c.Domain == "+DOMAIN").First(); Assert.IsTrue( sharedCredential.ID == node.Credentials.Where( c => c.Domain == "+DOMAIN" ).First().ID ); }