当前位置: 首页>>代码示例>>C#>>正文


C# CustomerRepository.Remove方法代码示例

本文整理汇总了C#中CustomerRepository.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# CustomerRepository.Remove方法的具体用法?C# CustomerRepository.Remove怎么用?C# CustomerRepository.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CustomerRepository的用法示例。


在下文中一共展示了CustomerRepository.Remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Remove_Customer_Succeed

        public void Remove_Customer_Succeed()
        {
            using (var context = new ManagementContext())
            {
                //Arrange
                var total = context.Customers.Count();
                var customer = context.Customers.First();
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                customerRepository.Remove(customer);
                unitOfWork.Save();

                //Assert
                Assert.AreEqual(context.Customers.Count(), total - 1);
            }
        }
开发者ID:panicoenlaxbox,项目名称:EntityFramework.DataLayer,代码行数:18,代码来源:CustomerRepositoryTests.cs

示例2: CustomerRepositoryRemoveItemDeleteIt

        public void CustomerRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            var customerRepository = new CustomerRepository(unitOfWork);

            var country = new Country("Spain","es-ES");
            country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            

            var address =  new Address("city", "zipCode", "addressline1", "addressline2");

            var customer = CustomerFactory.CreateCustomer("Frank", "Frank","+3444","company", country,address);
            customer.SetTheCountryReference(country.Id);
            
            customerRepository.Add(customer);
            unitOfWork.Commit();

            //Act
            customerRepository.Remove(customer);
            unitOfWork.Commit();

            var result = customerRepository.Get(customer.Id);

            //Assert
            Assert.IsNull(result);
        }
开发者ID:ljvblfz,项目名称:MicrosoftNLayerApp,代码行数:28,代码来源:CustomerRepositoryTests.cs

示例3: Main

        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "TEST";

            var uow = new UnitOfWork();
            var customerRepository = new CustomerRepository(uow);
            var orderRepository = new OrderRepository(uow);

            Console.WriteLine("SIMPLE CRUD TEST APP");
            //FindAll TEST
            Console.WriteLine("FINDALL TEST");
            Console.WriteLine("List of Customers:");
            var customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //Update TEST
            Console.WriteLine("UPDATE TEST");
            var customerEntity = customers[0];
            Console.WriteLine(string.Format("Customer current FirstName: {0}", customerEntity.FirstName));
            Console.WriteLine("ENTER Customer NEW FirstName: ");
            var newName = Console.ReadLine();
            var oldName = customerEntity.FirstName;
            customerEntity.FirstName = newName;
            Console.WriteLine("Update data? (Y/N): ");

            var keyPressed = Console.ReadKey(true).Key;
            while (keyPressed != ConsoleKey.Y && keyPressed != ConsoleKey.N) { keyPressed = Console.ReadKey(true).Key; }
            if (keyPressed == ConsoleKey.Y)
            {
                customerRepository.Update(customerEntity);
                uow.Commit();
                Console.WriteLine("Data updated!");
            }
            else
            {
                customerEntity.FirstName = oldName;
                Console.WriteLine("Change reverted!");
            }

            Console.WriteLine(string.Format("Customer Full Name: {0}", customerEntity.FullName));
            PressTo("CONTINUE");

            //Insert TEST
            Console.WriteLine("INSERT TEST");

            Console.WriteLine("ENTER NEW Customer FirstName: ");
            var newFirstName = Console.ReadLine();
            Console.WriteLine("ENTER NEW Customer LastName: ");
            var newLastName = Console.ReadLine();
            customerEntity = Customer.Create(newFirstName, newLastName);
            customerRepository.Add(customerEntity);
            uow.Commit();
            Console.WriteLine("NEW Customer CREATED!");
            Console.WriteLine("");
            Console.WriteLine("List of Customers:");
            customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //Delete TEST
            Console.WriteLine("DELETE TEST");

            Console.WriteLine("ENTER Customer's number to DELETE: ");
            int deleteIndex;
            while (!int.TryParse(Console.ReadLine(), out deleteIndex) || (deleteIndex < 0 || deleteIndex > customers.Count))
            {
                Console.WriteLine("ENTER a valid Customer's number to DELETE: ");
            }
            customerEntity = customers[deleteIndex - 1];
            customerRepository.Remove(customerEntity);
            uow.Commit();
            Console.WriteLine(string.Format("Customer '{0}' was DELETED!", customerEntity.FullName));
            Console.WriteLine("");
            Console.WriteLine("List of Customers:");
            customers = customerRepository.FindAll().ToList<Customer>();
            for (var index = 0; index < customers.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, customers[index].FullName));
            PressTo("CONTINUE");

            //FindAll TEST [Orders]
            Console.WriteLine("FINDALL TEST [Orders]");
            Console.WriteLine("Enter Customer's number to display the list of Orders:");
            int customerIndex;
            while (!int.TryParse(Console.ReadLine(), out customerIndex) || (customerIndex < 0 || customerIndex > customers.Count))
            {
                Console.WriteLine("ENTER a valid Customer's number: ");
            }
            customerEntity = customers[customerIndex - 1];
            Console.WriteLine(string.Format("{0}'s ORDERS LIST:", customerEntity.FirstName));
            var orders = orderRepository.FindAllBy(customerEntity.Id).ToList<Order>();
            for (var index = 0; index < orders.Count; index++)
                Console.WriteLine(string.Format("{0}\t{1}", index + 1, orders[index].OrderDate));
            PressTo("CONTINUE");

            //FindAll TEST [Orders] with QueryObject
            Console.WriteLine("FINDALL TEST [Orders] with QueryObject");
            Console.WriteLine("Enter Customer's FirstName to display the list of Orders:");
//.........这里部分代码省略.........
开发者ID:Kaike23,项目名称:MetadataMapper,代码行数:101,代码来源:Program.cs

示例4: CustomerRepositoryRemoveItemDeleteIt

        public void CustomerRepositoryRemoveItemDeleteIt()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            ICustomerRepository customerRepository = new CustomerRepository(unitOfWork);

            var countryId = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C");

            var customer = CustomerFactory.CreateCustomer("Frank", "Frank", countryId, new Address("city", "zipCode", "addressline1", "addressline2"));

            customer.Id = IdentityGenerator.NewSequentialGuid();
            customer.Picture = new Picture()
            {
                Id = customer.Id
            };

            customerRepository.Add(customer);
            customerRepository.UnitOfWork.Commit();

            //Act

            customerRepository.Remove(customer);
            customerRepository.UnitOfWork.Commit();

            var result = customerRepository.Get(customer.Id);

            //Assert
            Assert.IsNull(result);
        }
开发者ID:gabrielsimas,项目名称:MicrosoftNLayerApp,代码行数:29,代码来源:CustomerRepositoryTests.cs


注:本文中的CustomerRepository.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。