Exemplo n.º 1
0
        public static void Main()
        {
            var customer = new Customer
            {
                CustomerID = "PHPTH",
                CompanyName = "Telerik Academy",
                ContactName = "Pesho Petrov",
                ContactTitle = "Marketing Assistant",
                Address = "31 Al. Malinov",
                City = "Sofia",
                Region = null,
                PostalCode = "2100",
                Country = "Bulgaria",
                Phone = "(359) 2444444",
                Fax = null
            };

            try
            {
                Console.WriteLine("INSERT:");
                int affectedRowsAfterInsert = DAO.InsertCustomer(customer);
                Console.WriteLine("{0} row(s) affected", affectedRowsAfterInsert);
                Console.WriteLine("MODIFY:");
                int affectedRowsAfterModify = DAO.ModifyCustomer(customer);
                Console.WriteLine("{0} row(s) affected", affectedRowsAfterModify);
                Console.WriteLine("DELETE");
                int affectedRowsAfterDelete = DAO.DeleteCustomer(customer);
                Console.WriteLine("{0} row(s) affected", affectedRowsAfterDelete);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public void AddCustomer_ShouldAddANewCustomer()
        {
            using (var db = new NorthwindEntities())
            {
                string city = "City of angels";

                var customersCountBeforeAdding = db.Customers
                                                          .Select(c => c.City == city)
                                                          .ToList()
                                                          .Count;

                Customer newCustomer = new Customer()
                {
                    CustomerID = "LBCDM",
                    CompanyName = "Telerik",
                    ContactName = "Alex Frost",
                    ContactTitle = "Very special guy",
                    Address = "31 Al.Malinov",
                    City = city,
                    Region = null,
                    PostalCode = "2000",
                    Country = "Bulgaria",
                    Phone = "55555555",
                    Fax = null
                };

                DAO.InsertCustomer(newCustomer);

                var customersCountAfterAddingOne = db.Customers
                                                       .Select(c => c.City == city)
                                                       .ToList()
                                                       .Count;

                Assert.AreEqual(customersCountBeforeAdding + 1, customersCountAfterAddingOne);

                DAO.DeleteCustomer(newCustomer);
            }
        }
Exemplo n.º 3
0
        public void AddCustomer_ShouldThrowAnExceptionWhenTryingToAddCustomersWithTheSameId()
        {
            using (var db = new NorthwindEntities())
            {
                Customer newCustomer = new Customer()
                {
                    CustomerID = "LBCDM",
                    CompanyName = "Telerik",
                    ContactName = "Alex Frost",
                    ContactTitle = "Very special guy",
                    Address = "31 Al.Malinov",
                    City = "City of angels",
                    Region = null,
                    PostalCode = "2000",
                    Country = "Bulgaria",
                    Phone = "55555555",
                    Fax = null
                };

                DAO.InsertCustomer(newCustomer);
                DAO.InsertCustomer(newCustomer);
            }
        }
Exemplo n.º 4
0
        public void ModifyCustomer_ShouldModifyCustomersComapnyNameAndCompanyTitle()
        {
            using (var db = new NorthwindEntities())
            {
                string id = "LBCDM";
                string city = "City of angels";

                Customer newCustomer = new Customer()
                {
                    CustomerID = id,
                    CompanyName = "Telerik",
                    ContactName = "Alex Frost",
                    ContactTitle = "Very special guy",
                    Address = "31 Al.Malinov",
                    City = city,
                    Region = null,
                    PostalCode = "2000",
                    Country = "Bulgaria",
                    Phone = "55555555",
                    Fax = null
                };

                DAO.InsertCustomer(newCustomer);

                DAO.ModifyCustomer(newCustomer);

                var customer = db.Customers
                                .FirstOrDefault(c => c.CustomerID == id);

                Assert.AreNotEqual(newCustomer.ContactTitle, customer.ContactTitle);
                Assert.AreNotEqual(newCustomer.CompanyName, customer.CompanyName);

                DAO.DeleteCustomer(newCustomer);
            }
        }