Пример #1
0
        public void NotTest()
        {
            var u1 = new Customer("test1", 11);

            ISpecification<Customer> spec = Specification<Customer>.Eval(o => o.Name == "test1").Not();
            Assert.IsFalse(spec.IsSatisfiedBy(u1));
        }
Пример #2
0
        public void InitModel()
        {
            Helper.ResetDB();

            itemCategory = new ItemCategory {CategoryName = "日常用品"};
            item1 = new Item {Category = itemCategory, ItemName = "洗衣粉"};
            item2 = new Item {Category = itemCategory, ItemName = "肥皂"};

            customerScott = new Customer("scott", 11);
            orderItem1 = new OrderItem {Item = item1, Quantity = 1};
            orderItem2 = new OrderItem {Item = item2, Quantity = 2};
            address1 = new PostalAddress {City = "苏州", Phone = "15", Street = "莲花新训"};

            customersOrder1 = new Order
                {
                    CreatedDate = DateTime.Now,
                    Customer = customerScott,
                    OrderName = "账单1",
                    Items = new List<OrderItem> {orderItem1, orderItem2},
                    postalAddress = address1
                };
            customersOrder2 = new Order
                {
                    CreatedDate = DateTime.Now,
                    Customer = customerScott,
                    OrderName = "账单2",
                    Items = new List<OrderItem> {orderItem1},
                    postalAddress = address1
                };
        }
Пример #3
0
        public void AndTest()
        {
            var u1 = new Customer("test1", 11);
            var u2 = new Customer("qianlifeng", 11);

            ISpecification<Customer> left = Specification<Customer>.Eval(o => o.Name == "qianlifeng");
            ISpecification<Customer> right = Specification<Customer>.Eval(o => o.Age == 11);
            ISpecification<Customer> spec = left.And(right);
            Assert.IsTrue(spec.IsSatisfiedBy(u2));
        }
Пример #4
0
        public void NHibernateRepositoryTest_GetSignalAggregateRoot()
        {
            using (var ctx = application.ObjectContainer.GetService<IRepositoryContext>())
            {
                IRepository<Customer> customerRepository = ctx.GetRepository<Customer>();
                var u1 = new Customer("scott1", 12);
                var u2 = new Customer("scott2", 12);
                var u3 = new Customer("scott3", 12);
                customerRepository.Add(u1);
                customerRepository.Add(u2);
                customerRepository.Add(u3);
                ctx.Commit();

                Customer customers = customerRepository.GetSignal(Specification<Customer>.Eval(o => o.Name == "scott1"));
                Assert.IsNotNull(customers);
                Assert.AreEqual("scott1", customers.Name);

                customers = customerRepository.GetSignal(Specification<Customer>.Eval(o => o.Name == "scott112131313"));
                Assert.IsNull(customers);
            }
        }
Пример #5
0
        public void NHibernateRepositoryTest_GetAllAggregateRootToRepository_Specifiaction()
        {
            using (var ctx = application.ObjectContainer.GetService<IRepositoryContext>())
            {
                IRepository<Customer> customerRepository = ctx.GetRepository<Customer>();
                var u1 = new Customer("scott1", 12);
                var u2 = new Customer("scott2", 12);
                var u3 = new Customer("scott3", 12);
                customerRepository.Add(u1);
                customerRepository.Add(u2);
                customerRepository.Add(u3);
                ctx.Commit();

                IEnumerable<Customer> customers =
                    customerRepository.GetAll(Specification<Customer>.Eval(o => o.Name.Contains("3")));

                Assert.IsNotNull(customers);
                Assert.AreEqual(1, customers.Count());
                Assert.AreEqual("scott3", customers.First().Name);
            }
        }