public void PostModelEmptyFiles() { var before = _context.RealEstateObject.Count(); var modelMock = new Mock <IFormFile>(); var model = new RealEstateObject() { RealEstateType = RealEstateType.Apartment, Building = "1", City = "Пермь", Description = "Малоквартирный дом бизнес-класса. Все квартиры в нашем доме имеют свободную планировку. \nКвартира расположена на 3 этаже 12 этажного дома. Общая площадь квартиры 115,4 кв.м., жилая 66 кв.м., просторная прихожая, высокие потолки 2,9м. \nВ нашей квартире имеется: большая кухня-столовая, большая ванная комната с отдельной душевой кабиной и санузлом, гостиная, спальня/детская, спальня, 2 гардеробных комнаты, лоджия. На кухне, в ванной комнате и коридоре установлен теплый пол. В квартире сделан ремонт из качественных европейских материалов. \nДоступ на территорию дома ограничен для посторонних лиц. Ограждение дома оборудовано автоматическими воротами. На всей территории установлено видеонаблюдение. В подъезде, для Вашей безопасности, работает охрана.", Floor = "3/5", Region = "Пермский край", Rooms = 1, Square = 23.4, Street = "Ленина", Code = "59000000123" }; modelMock.Setup(i => i.OpenReadStream()).Returns(model.ToJsonStream()); var actual = _controller.Post(modelMock.Object, null); var result = actual as CreatedODataResult <RealEstateObject>; Assert.That(result, Is.Not.Null); var after = _context.RealEstateObject.Count(); Assert.That(after, Is.EqualTo(before + 1)); }
public IActionResult Post(IFormFile document, List <IFormFile> file) { RealEstateObject model = document.GetObjectFromForm <RealEstateObject>(); if (!TryValidateModel(model) || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (file != null) { var root = Path.Combine(_appEnvironment.WebRootPath, "photos"); Directory.CreateDirectory(root); foreach (IFormFile formFile in file) { model.RealEstateObjectFile.Add(new RealEstateObjectFile() { Name = Path.GetFileName(formFile.SaveFromForm(root)), }); } } _context.RealEstateObject.Add(model); _context.SaveChanges(); return(Created(model)); }
public async Task <List <RealEstateObject> > GetRealEstateObjects(string city, string filter) { var listAllObjects = new List <RealEstateObject>(); var result = await _client.QueryAsync(city, filter); while (result.PagingProperties.CurrentPage <= result.PagingProperties.PagesCount) { foreach (var listing in result.RealEstateObjects) { var newListing = new RealEstateObject() { Id = listing.Id, RealEstateAgentId = listing.RealEstateAgentId, RealEstateAgentName = listing.RealEstateAgentName }; listAllObjects.Add(newListing); } result = await _client.QueryAsync(city, filter, result.PagingProperties.CurrentPage + 1); } return(listAllObjects); }
public void PutWithFile() { var before = _context.RealEstateObject.Count(); //Model var modelMock = new Mock <IFormFile>(); var model = new RealEstateObject() { RealEstateType = RealEstateType.Apartment, Building = "1", City = "Пермь", Description = "Малоквартирный дом бизнес-класса. Все квартиры в нашем доме имеют свободную планировку. \nКвартира расположена на 3 этаже 12 этажного дома. Общая площадь квартиры 115,4 кв.м., жилая 66 кв.м., просторная прихожая, высокие потолки 2,9м. \nВ нашей квартире имеется: большая кухня-столовая, большая ванная комната с отдельной душевой кабиной и санузлом, гостиная, спальня/детская, спальня, 2 гардеробных комнаты, лоджия. На кухне, в ванной комнате и коридоре установлен теплый пол. В квартире сделан ремонт из качественных европейских материалов. \nДоступ на территорию дома ограничен для посторонних лиц. Ограждение дома оборудовано автоматическими воротами. На всей территории установлено видеонаблюдение. В подъезде, для Вашей безопасности, работает охрана.", Floor = "3/5", Region = "Пермский край", Rooms = 1, Square = 23.4, Street = "Ленина", Code = "59000000123", RealEstateObjectFile = new HashSet <RealEstateObjectFile>() { new RealEstateObjectFile() { Name = "test-tmp.txt" }, new RealEstateObjectFile() { Name = "test-tmp-1.txt" } } }; modelMock.Setup(i => i.OpenReadStream()).Returns(model.ToJsonStream()); //File var fileMock = new Mock <IFormFile>(); fileMock.Setup(i => i.OpenReadStream()).Returns("Some text".ToStream()); fileMock.SetupGet(i => i.FileName).Returns("some.txt"); var actual = _controller.Put(modelMock.Object, new List <IFormFile>() { fileMock.Object }, 3); var result = actual as OkObjectResult; Assert.That(result, Is.Not.Null); var after = _context.RealEstateObject.Count(); Assert.That(after, Is.EqualTo(before)); Assert.That(_context.RealEstateObjectFile.Count(i => i.RealEstateObjectId == 3), Is.EqualTo(3)); var newFile = _context.RealEstateObjectFile.LastOrDefault(i => i.RealEstateObjectId == 3); var path = Path.Combine(Path.GetTempPath(), "photos", newFile.Name); Assert.That(File.Exists(path), Is.True); File.Delete(path); }
private void AddObjectToList(RealEstateObject obj) { ListViewItem lvi = new ListViewItem(obj.Id.ToString()); lvi.SubItems.Add(obj.Address.Country); lvi.SubItems.Add(obj.Address.City); lvi.SubItems.Add(obj.Address.Street); lvi.SubItems.Add(obj.TypeOfEstate); objectsLView.Items.Add(lvi); }
public IActionResult Put(IFormFile document, List <IFormFile> file, int key) { var oldModel = _context.RealEstateObject.Find(key); if (oldModel == null) { return(NotFound()); } RealEstateObject model = document.GetObjectFromForm <RealEstateObject>(); if (!TryValidateModel(model) || !ModelState.IsValid) { return(BadRequest(ModelState)); } var root = Path.Combine(_appEnvironment.WebRootPath, "photos"); if (file != null) { Directory.CreateDirectory(root); foreach (IFormFile formFile in file) { model.RealEstateObjectFile.Add(new RealEstateObjectFile() { Name = Path.GetFileName(formFile.SaveFromForm(root)) }); } } var deleted = oldModel.RealEstateObjectFile.Select(i => i.Name) .Except(model.RealEstateObjectFile.Select(i => i.Name)); foreach (string deletedFile in deleted) { System.IO.File.Delete(Path.Combine(root, deletedFile)); } oldModel.RealEstateObjectFile = model.RealEstateObjectFile; oldModel.Building = model.Building; oldModel.City = model.City; oldModel.Code = model.Code; oldModel.Description = model.Description; oldModel.Floor = model.Floor; oldModel.Region = model.Region; oldModel.Street = model.Street; oldModel.Rooms = model.Rooms; oldModel.Square = model.Square; oldModel.RealEstateType = model.RealEstateType; _context.SaveChanges(); return(Ok(model)); }
public void PutModelInvalid() { var modelMock = new Mock <IFormFile>(); var model = new RealEstateObject(); modelMock.Setup(i => i.OpenReadStream()).Returns(model.ToJsonStream()); _controller.ValidateViewModel(model); var actual = _controller.Put(modelMock.Object, null, 100); Assert.That(actual, Is.InstanceOf <NotFoundResult>()); }
public void PostModelInvalid() { var modelMock = new Mock <IFormFile>(); var model = new RealEstateObject(); modelMock.Setup(i => i.OpenReadStream()).Returns(model.ToJsonStream()); _controller.ValidateViewModel(model); var actual = _controller.Post(modelMock.Object, null); var result = actual as BadRequestObjectResult; Assert.That(result, Is.Not.Null); }
private void MakeObjectToAdd(RealEstateObject objectToAdd) { Address address = new Address(); address.Country = countryTBox.Text; address.City = cityTBox.Text; address.Street = streetTBox.Text; address.ZipCode = zipCodeTBox.Text; objectToAdd.Address = address; objectToAdd.Price = Int32.Parse(priceTBox.Text); objectToAdd.NumberOfRooms = roomsTBox.Text; objectToAdd.TypeOfEstate = typeOfEstateCBox.Text; }
private void SearchBtn_Click(object sender, EventArgs e) { objectsLView.Items.Clear(); string citySearch = searchCityTBox.Text.ToUpper(); string typeOfEstateSearch = searchEstateCBox.Text.ToUpper(); for (int i = 0; i < estateManager.Count; i++) { RealEstateObject obj = estateManager.GetAt(i); string city = obj.Address.City.ToUpper(); string typeOfEstate = obj.TypeOfEstate.ToUpper(); if (citySearch == city && typeOfEstateSearch == typeOfEstate) { AddObjectToList(obj); } } }
private void PopulateFields(int index) { RealEstateObject obj = estateManager.GetAt(index); typeOfEstateCBox.Text = obj.TypeOfEstate; roomsTBox.Text = obj.NumberOfRooms.ToString(); priceTBox.Text = obj.Price.ToString(); LegalForm legalForm = obj.GetLegalForm(); switch (legalForm) { case LegalForm.Rental: rentalRBtn.PerformClick(); break; case LegalForm.Tenement: tenenmentRButton.PerformClick(); break; case LegalForm.Ownership: ownerShipRBtn.PerformClick(); break; } if (obj is Warehouse) { Warehouse wareHouse = (Warehouse)obj; landSizeTBox.Text = wareHouse.LandSizeInSquareMeters.ToString(); } if (obj is Apartment) { Apartment apartment = new Apartment(); apartment = (Apartment)obj; floorTBox.Text = apartment.Floor.ToString(); } streetTBox.Text = obj.Address.Street; cityTBox.Text = obj.Address.City; zipCodeTBox.Text = obj.Address.ZipCode; countryTBox.Text = obj.Address.Country; }
private void SetLegalForm(RealEstateObject objectToAdd) { string legalFormType = GetCheckedRadio(newObjectBox).Text; switch (legalFormType) { case "Tenement": objectToAdd.SetLegalForm(LegalForm.Tenement); break; case "Rental": objectToAdd.SetLegalForm(LegalForm.Rental); break; case "Ownership": objectToAdd.SetLegalForm(LegalForm.Ownership); break; } }
public void PutEmptyFiles() { var before = _context.RealEstateObject.Count(); var modelMock = new Mock <IFormFile>(); var model = new RealEstateObject() { RealEstateType = RealEstateType.House, Building = "Building is changed", City = "City is changed", Description = "Description is changed", Floor = "Floor is changed", Region = "Region is changed", Rooms = 2, Square = 100, Street = "Street is changed", Code = "Code is changed" }; modelMock.Setup(i => i.OpenReadStream()).Returns(model.ToJsonStream()); var actual = _controller.Put(modelMock.Object, null, 1); var result = actual as OkObjectResult; Assert.That(result, Is.Not.Null); var after = _context.RealEstateObject.Count(); Assert.That(after, Is.EqualTo(before)); var changed = _context.RealEstateObject.Find(1); Assert.That(changed.Description, Is.EqualTo("Description is changed")); Assert.That(changed.Street, Is.EqualTo("Street is changed")); Assert.That(changed.RealEstateType, Is.EqualTo(RealEstateType.House)); Assert.That(changed.Building, Is.EqualTo("Building is changed")); Assert.That(changed.City, Is.EqualTo("City is changed")); Assert.That(changed.Floor, Is.EqualTo("Floor is changed")); Assert.That(changed.Region, Is.EqualTo("Region is changed")); Assert.That(changed.Rooms, Is.EqualTo(2)); Assert.That(changed.Square, Is.EqualTo(100)); Assert.That(changed.Code, Is.EqualTo("Code is changed")); }
public void Post() { var before = _context.Announcement.Count(); var obj = new RealEstateObject() { RealEstateType = RealEstateType.Apartment, Building = "53", City = "Пермь", Description = "Description", Floor = "3/5", Region = "Пермский край", Rooms = 2, Square = 45, Street = "Мильчакова", Code = "59000000123" }; _context.RealEstateObject.Add(obj); var beforeObjects = _context.RealEstateObject.Count(); var actual = _controller.Post(new Announcement() { RealEstateObject = obj, Price = 100000, AnnouncementType = AnnouncementType.Lease }); var result = actual as CreatedODataResult <Announcement>; Assert.That(result, Is.Not.Null); var after = _context.Announcement.Count(); var afterObjects = _context.RealEstateObject.Count(); Assert.That(after, Is.EqualTo(before + 1)); Assert.That(afterObjects, Is.EqualTo(beforeObjects)); }