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 UpdateCustomer()
        {
            using (var cc = new CustomerContext())
            {
                cc.Database.Delete();
                cc.Database.Create();
            }

            var repo = new Left4Edit.Models.Repo.EFCustomerRepo();
            repo.AddCustomer(CreateTestCustomer_EF().First());
            repo.SaveChanges();
            var customer = repo.GetCustomers().First();

            Int32 customerKey = customer.ID;
            String customerName = customer.Name;
            String newCustomerName = "APPLE SAUCE!";

            customer.Name = newCustomerName;
            repo.UpdateCustomer(customer);
            repo.SaveChanges();

            customer = repo.GetCustomer(customerKey);
            Assert.IsTrue(customer.Name == newCustomerName);
        }
        public void EF_Customer_Poco_Add()
        {
            using (var cc = new CustomerContext())
            {
                cc.Database.Delete();
                cc.Database.Create();
            }
            Left4Edit.Models.Repo.ICustomerRepo repo =
                new Left4Edit.Models.Repo.EFCustomerRepo();

            Customer pocoCustomer = new Customer()
            {
                Name = "Poco Inc",
                Symbol = "POI",
                Contacts = new List<Contact>()
                {
                    new Contact()
                    {
                        FirstName = "No way",
                        LastName = "This works!",
                        Email = "*****@*****.**"
                    }
                }
            };

            repo.AddCustomer(pocoCustomer);
            repo.SaveChanges();

            Assert.IsTrue(repo.GetCustomers().First().Name == "Poco Inc");
            Assert.IsTrue(repo.GetCustomers().First().Contacts.First().FirstName == "No way");
        }
        public void EF_Customer_GetCustomer()
        {
            using (var cc = new CustomerContext())
            {
                cc.Database.Delete();
                cc.Database.Create();
            }
            Left4Edit.Models.Repo.ICustomerRepo repo = new Left4Edit.Models.Repo.EFCustomerRepo();
            repo.AddCustomer(CreateTestCustomer_EF().First());
            repo.SaveChanges();

            var cust = repo.GetCustomer(repo.GetCustomers().First().ID);
            Assert.IsNotNull(cust);
            Assert.IsNotNull(cust.Credentials);
            Assert.IsNotNull(cust.Contacts);
            Assert.IsNotNull(cust.Nodes);
            Assert.IsNotNull(
                cust.Nodes.Where(n => n.Address == "node1.billmcg.com")
                    .First().Credentials
            );
        }
        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
            );
        }
        public void DeleteCustomer_FromPOCO()
        {
            using (var cc = new CustomerContext())
            {
                cc.Database.Delete();
                cc.Database.Create();
            }

            var repo = new Left4Edit.Models.Repo.EFCustomerRepo();
            repo.AddCustomer(CreateTestCustomer_EF().First());
            repo.SaveChanges();

            var existingCustomer = repo.GetCustomers().First();
            Customer customerToDelete = new Customer()
            {
                ID = existingCustomer.ID,
                Name = "Test Customer",
                Symbol = "ASA"
            };

            repo.DeleteCustomer(customerToDelete);
            repo.SaveChanges();

            Assert.IsTrue(repo.GetCustomers().Count() == 0);
        }