Ejemplo n.º 1
0
        public void Include_Test()
        {
            using (var db = new LiteDatabase(DB.Path()))
            {
                var customers = db.GetCollection<Customer>("customers");
                var orders = db.GetCollection<Order>("orders");

                var customer = new Customer
                {
                    Name = "John Doe"
                };

                // insert and set customer.Id
                customers.Insert(customer);

                var order = new Order
                {
                    Customer = new DbRef<Customer>(customers, customer.Id)
                };

                orders.Insert(order);

                var query = orders
                    .Include((x) => x.Customer.Fetch(db))
                    .FindAll()
                    .Select(x => new { CustomerName = x.Customer.Item.Name })
                    .FirstOrDefault();

                Assert.Equal(customer.Name, query.CustomerName);

            }
        }
        public void TestEntLibValidation()
        {
            var valFactory = ServiceFactory.GetInstance<ValidatorFactory>();

            var myCustomer = new Customer();
            myCustomer.CustomerId = -2;
            myCustomer.CustomerName = "This is testname for current product";
            Validator<Customer> customerValidator = valFactory.CreateValidator<Customer>();
            ValidationResults results = customerValidator.Validate(myCustomer);

            Console.WriteLine(results.ToString());

            // Check if the ValidationResults detected any validation errors.
            if (results.IsValid)
            {
                Console.WriteLine("There were no validation errors.");
            }
            else
            {
                Console.WriteLine("The following {0} validation errors were detected:", results.Count);

                // Iterate through the collection of validation results.
                foreach (ValidationResult item in results)
                {
                    // Show the target member name and current value.
                    Console.WriteLine(
                        "Target:'{0}' Key:'{1}' Tag:'{2}' Message:'{3}'", item.Target, item.Key, item.Tag, item.Message);
                }
            }

            Assert.False(results.IsValid);
        }
Ejemplo n.º 3
0
        public void TestDelete()
        {
            //arrange
            var mockobject = new Mock<IRepository<Customer>>();
            mockobject.Setup(r => r.Delete(It.IsAny<Customer>())).Verifiable();

            var customer = new Customer() { CustomerId = 1 };
            var mockRepository = mockobject.Object;

            //act
            mockRepository.Delete(customer);

            //assert
            mockobject.Verify(e => e.Delete(customer));
        }
Ejemplo n.º 4
0
 public void InsertionFonctionnelle()
 {
     Database.SetInitializer(new DropCreateDatabaseAlways<CompanyContext>());
     CompanyContext Context = new CompanyContext();
     Customer client = new Customer() {
         AccountBalance = 125.36,
         AdresseLine2 = "n°25",
         AdressLine1 = "rue du haaa",
         City = "Bruxelles",
         EMail="*****@*****.**",
         Name="machin",
         PostCode = "1000",
         Remark = "bla,bla,bla"
     };
     Context.listCustomer.Add(client);
     Context.SaveChanges();
     Assert.AreEqual(1, HasCustomer());
 }
Ejemplo n.º 5
0
        public void TestFind()
        {
            //arrange
            var mockobject = new Mock<IRepository<Customer>>();
            mockobject.Setup(r => r.Add(It.IsAny<Customer>()));

            var customer = new Customer() { CustomerId = 1 };
            mockobject.Setup<IEnumerable<Customer>>(r => r.Find(c => c.CustomerId == customer.CustomerId))
                .Returns(new List<Customer>() { customer });

            var mockPagedlist = new PagedList<Customer>() { PageSize = 10, PageIndex = 1, TotalCount = 50 };
            for (int i = 0; i <= 10; i++)
            {
                mockPagedlist.Add(customer);
            }

            mockobject.Setup<IEnumerable<Customer>>(r => r.Find<int>(c => c.CustomerId == customer.CustomerId,c=>c.CustomerId,1,10))
                .Returns(mockPagedlist);

            var mockRepository = mockobject.Object;

            //act
            var clist = mockRepository.Find(c => c.CustomerId == customer.CustomerId);
            var cPagedlist = mockRepository.Find<int>(c => c.CustomerId == customer.CustomerId,c=>c.CustomerId,1,10);

            //assert
            Assert.NotNull(clist);
            Assert.True(clist.Count() > 0);

            Assert.NotNull(cPagedlist);
            Assert.Equal(10, cPagedlist.PageSize);
            Assert.Equal(1, cPagedlist.PageIndex);
            Assert.Equal(50, cPagedlist.TotalCount);
        }
Ejemplo n.º 6
0
        public void TestObjectContext_ChangeObjectState()
        {
            //arrange
            var mockobject = new Mock<IObjectContext>();
            mockobject.Setup(i => i.ChangeObjectState(It.IsAny<Object>(), It.IsAny<EntityState>())).Verifiable();

            var mockobjectset = new Mock<IObjectSet<Customer>>();
            mockobject.Setup(i => i.CreateObjectSet<Customer>()).Returns(mockobjectset.Object);

            var customer = new Customer() { CustomerId = 1 };
            var mockObjectContext = mockobject.Object;

            //act
            mockObjectContext.ChangeObjectState(customer, EntityState.Modified);
            var objectset = mockObjectContext.CreateObjectSet<Customer>();

            //assert
            mockobject.VerifyAll();
            Assert.NotNull(objectset);
        }
Ejemplo n.º 7
0
        public void TestSingle()
        {
            //arrange
            var mockobject = new Mock<IRepository<Customer>>();
            mockobject.Setup(r => r.Single(It.IsAny<Expression<Func<Customer, bool>>>()));

            var customer = new Customer() { CustomerId = 2 };
            var mockRepository = mockobject.Object;

            //act
            mockRepository.Single(c=>c.CustomerId==2);

            //assert
            mockobject.Verify(r=> r.Single(c => c.CustomerId == 2));
        }