示例#1
0
        private void CreateMockHouses()
        {
            using (DatabaseContext context = new DatabaseContext())
            {
                filter      = new HouseSearchRequest();
                filter.City = "City";

                /*
                 *  filter.Address = "Adress";
                 *  filter.Price = 0;
                 *  filter.Skip = 10;
                 *  filter.Street = "Street";
                 *  filter.Take = 10;
                 *  filter.TypeRent = true;
                 *  filter.ZipCode = "ZipCode";
                 */
                for (int i = 0; i < 10; i++)
                {
                    House house = DomainMocksFactory.CreateHouse();
                    house.ModifyCode((i).ToString());
                    house.AddAddress("my address", "my city", "my country", "my st. number", "zip code");
                    house.AddCategory("my entry", "my description");
                    house.AssociateAgent(DomainMocksFactory.CreateAgent());
                    context.Houses.Add(house);
                }

                context.SaveChanges();
            }
        }
示例#2
0
        public void Agent_Can_Be_Created_With_DB()
        {
            using (var context = new DatabaseContext())
            {
                context.Database.Log = delegate(string s)
                {
                    Debug.WriteLine(s);
                };
                Agent agent = DomainMocksFactory.CreateAgent();
                context.Agents.Add(agent);

                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                Agent agent = context.Agents.FirstOrDefault();
                //Assert.Inconclusive("Verify all properties");
            }
        }
示例#3
0
        public void Agent_WithTwoHouses_CanRemoveOneHouse_AndKeepTheOther()
        {
            using (var context = new DatabaseContext())
            {
                //First Add House To The Agent
                House firstHouse  = DomainMocksFactory.CreateHouse();
                House secondHouse = DomainMocksFactory.CreateHouse();
                Agent mocksAgent  = DomainMocksFactory.CreateAgent();

                mocksAgent.HousesInCharge.Add(firstHouse);
                mocksAgent.HousesInCharge.Add(secondHouse);

                context.Agents.Add(mocksAgent);

                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                Agent agent = context.Agents
                              .Include(x => x.HousesInCharge)
                              .FirstOrDefault();

                //Verify that we added to houses to the agent.
                Assert.IsTrue(agent.HousesInCharge.Count == 2);

                //Then remove that house from agent.
                agent.HousesInCharge.RemoveAt(1);
                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                Agent agent = context.Agents
                              .Include(x => x.HousesInCharge)
                              .FirstOrDefault();

                //Verify that you removed house from agent.
                Assert.IsTrue(agent.HousesInCharge.Count == 1);
            }
        }
示例#4
0
        public void Agent_Can_get_House_InDB()
        {
            using (var context = new DatabaseContext())
            {
                Agent agent = DomainMocksFactory.CreateAgent();
                House house = DomainMocksFactory.CreateHouse();
                agent.AddHouse(house);

                context.Agents.Add(agent);

                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                Agent agent = context.Agents
                              .Include(x => x.HousesInCharge)
                              .FirstOrDefault();

                Assert.IsTrue(agent.HousesInCharge.Count > 0);
            }
        }
示例#5
0
        public void Agent_IsDeleted_DoesNotDelete_Houses()
        {
            using (var context = new DatabaseContext())
            {
                Agent agent = DomainMocksFactory.CreateAgent();
                House house = DomainMocksFactory.CreateHouse();

                agent.HousesInCharge.Add(house);

                context.Houses.Add(house);
                context.Agents.Add(agent);

                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                Agent agent = context.Agents
                              .Include(x => x.HousesInCharge)
                              .FirstOrDefault();
                //Verify that you have a proper agent object with house.
                Assert.IsTrue(agent.HousesInCharge.Count > 0);

                //Delete Agent object.
                context.Agents.Remove(agent);

                context.SaveChanges();
            }

            using (var context = new DatabaseContext())
            {
                House house = context.Houses.FirstOrDefault();
                Agent agent = context.Agents
                              .Include(x => x.HousesInCharge)
                              .FirstOrDefault();

                Assert.IsNotNull(house);
            }
        }
示例#6
0
 public void testInitialize()
 {
     mocksAgent = DomainMocksFactory.CreateAgent();
 }