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(); } }
public void Agent_Has_HouseAssociated() { House tempMocksHouse = DomainMocksFactory.CreateHouse(); mocksAgent.HousesInCharge.Add(tempMocksHouse); Assert.IsTrue(mocksAgent.HousesInCharge.Count > 0); }
public void Agent_RemoveHouse_AssociationsAreRemoved() { House tempMocksHouse = DomainMocksFactory.CreateHouse(); mocksAgent.HousesInCharge.Add(tempMocksHouse); Assert.IsTrue(mocksAgent.HousesInCharge.Count > 0); mocksAgent.HousesInCharge.Remove(tempMocksHouse); Assert.IsTrue(mocksAgent.HousesInCharge.Count == 0); }
public void House_CanBe_Saved() { using (DatabaseContext context = new DatabaseContext()) { House house = DomainMocksFactory.CreateHouse(); context.Houses.Add(house); context.SaveChanges(); } using (DatabaseContext context = new DatabaseContext()) { House house = context.Houses.FirstOrDefault(); Assert.IsNotNull(house); } }
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); } }
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); } }
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); } }
public void House_CanBe_Modified() { using (DatabaseContext context = new DatabaseContext()) { House house = DomainMocksFactory.CreateHouse(); context.Houses.Add(house); context.SaveChanges(); } using (DatabaseContext context = new DatabaseContext()) { House house = context.Houses.FirstOrDefault(); house.ModifyName("Modified"); context.SaveChanges(); } using (DatabaseContext context = new DatabaseContext()) { House house = context.Houses.FirstOrDefault(); Assert.IsTrue(house.Name == "Modified"); } }
public void House_IsProperlyMapped() { using (DatabaseContext context = new DatabaseContext()) { House house = DomainMocksFactory.CreateHouse(); house.AddCategory("For Rent", "This house is for rent"); house.AddAddress("My street", "my city", "my country", "my number", "zip code"); context.Houses.Add(house); context.SaveChanges(); } using (DatabaseContext context = new DatabaseContext()) { House house = context.Houses .Include("Category") .Include("Address") .FirstOrDefault(); Assert.IsTrue(house.Name == DomainMocksFactory.HOUSE_NAME); Assert.IsTrue(house.Description == DomainMocksFactory.HOUSE_DESC); Assert.IsTrue(house.Address.Address1 == "My street"); } }
public void House_IsDeleted_ButCustomerIsNot() { using (var context = new DatabaseContext()) { House house = DomainMocksFactory.CreateHouse(); Customer customer = house.Owner; context.Houses.Add(house); context.Customers.Add(customer); context.SaveChanges(); } using (var context = new DatabaseContext()) { House house = context.Houses .Include(x => x.Owner) .FirstOrDefault(); Assert.IsNotNull(house); context.Houses.Remove(house); context.SaveChanges(); } using (var context = new DatabaseContext()) { House house = context.Houses .Include(x => x.Owner) .FirstOrDefault(); Customer customer = context.Customers.FirstOrDefault(); Assert.IsNotNull(customer); Assert.IsNull(house); } }
public void TestInitialize() { mockHouse = DomainMocksFactory.CreateHouse(); }
public void Customer_HasOneHouseAssociated() { House tempHouseForCustomer = DomainMocksFactory.CreateHouse(); Assert.IsTrue(tempHouseForCustomer.Owner.Houses.Contains(tempHouseForCustomer)); }