예제 #1
0
        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
            );
        }