public void NewHousingPropertyViewModelHasEmptyPhotos()
        {
            HousingPropertyViewModel viewModel = new HousingPropertyViewModel();

            viewModel.UploadedPhotos.Should().NotBeNull();
            viewModel.UploadedPhotos.Should().BeEmpty();
        }
Esempio n. 2
0
        public async Task TransfereeInsertProperty_ValidInsertRequest_CreatesRecords()
        {
            // Arrange
            Order order = BuildOrder();

            Context.Orders.Add(order);
            Context.SaveChanges();
            Context.Entry(order).Reload();

            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.PropertyStreet1 = "abc";
            propertyVM.PropertyStreet2 = "apt 123";
            propertyVM.OrderId         = order.Id;

            // Act
            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUserAndRole(transferee.Id, transferee.UserName, UserRoles.Transferee);
            HttpStatusCodeResult result = (HttpStatusCodeResult)controller.Create(propertyVM);

            // Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.Created);

            Context.Entry(order).Reload();
            order.HomeFinding.HomeFindingProperties.Count().Should().Be(1);

            HomeFindingProperty hfp      = order.HomeFinding.HomeFindingProperties.First();
            Property            property = hfp.Property;

            property.Street1.Should().Be(propertyVM.PropertyStreet1);
            property.Street2.Should().Be(propertyVM.PropertyStreet2);
        }
        public void UpdateHousingProperty_ValidOrder_ReturnFound()
        {
            var propertyId = "1";

            HomeFindingProperty p1 = new HomeFindingProperty();

            p1.Deleted  = false;
            p1.Property = new Property()
            {
                Id = propertyId, Amount = 10, NumberOfBathrooms = 5, NumberOfBedrooms = 2, SquareFootage = 2343
            };
            p1.ViewingDate = DateTime.Now.AddDays(10);

            _mockHomeFindingPropertiesRepository.Setup(r => r.GetHomeFindingPropertyById(propertyId)).Returns(p1);


            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel()
            {
                Id = propertyId, PropertyNumberOfBathrooms = 10, PropertyNumberOfBedrooms = 12, PropertyAmount = 2002, PropertySquareFootage = 1023
            };

            var result = _controller.UpdateHousingProperty(propertyVM) as IHttpActionResult;

            result.Should().BeOfType <System.Web.Http.Results.OkResult>();
            p1.Property.NumberOfBedrooms.Equals(propertyVM.PropertyNumberOfBedrooms);
            p1.Property.NumberOfBathrooms.Equals(propertyVM.PropertyNumberOfBathrooms);
            p1.Property.Amount.Should().Equals(propertyVM.PropertyAmount);
            p1.Property.SquareFootage.Equals(propertyVM.PropertySquareFootage);
        }
Esempio n. 4
0
        public void TransfereeUpdateHomeFindingProperty_DoesNotWipeOutOtherDataFromIncompleteViewModel()
        {
            // Arrange
            Order order = BuildOrder(false);

            Context.Orders.Add(order);
            HomeFindingProperty hfp = order.HomeFinding.HomeFindingProperties.First();

            Context.SaveChanges();

            // Act
            var expectedStreet = hfp.Property.Street1;
            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.Id    = hfp.Id;
            propertyVM.Liked = null;
            // This ViewModel doesn't have anything for the property meaning nothing gets updated
            // Note: This is more of a test of the Mapper instead of the controller

            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUserAndRole(transferee.Id, transferee.UserName, UserRoles.Transferee);
            HttpStatusCodeResult response = (HttpStatusCodeResult)controller.UpdateLiked(propertyVM);

            // Assert
            Context.Entry(hfp).Reload();
            hfp.Property.Street1.Should().Be(expectedStreet);
        }
Esempio n. 5
0
        public void TransfereeUpdateHomeFindingProperty_UpdatesNull()
        {
            // Arrange
            Order order = BuildOrder(false);

            Context.Orders.Add(order);
            HomeFindingProperty hfp = order.HomeFinding.HomeFindingProperties.First();

            hfp.Liked = true; // ensure this is already liked
            Context.SaveChanges();

            // Act
            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.Id    = hfp.Id;
            propertyVM.Liked = null;

            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUserAndRole(transferee.Id, transferee.UserName, UserRoles.Transferee);
            HttpStatusCodeResult response = (HttpStatusCodeResult)controller.UpdateLiked(propertyVM);

            // Assert
            Context.Entry(hfp).Reload();
            hfp.Liked.Should().BeNull();
        }
Esempio n. 6
0
        public void UpdateHomeFindingProperty_UpdatesDisliked()
        {
            // Arrange
            Order order = BuildOrder(false);

            Context.Orders.Add(order);
            HomeFindingProperty hfp = order.HomeFinding.HomeFindingProperties.First();

            hfp.Liked = null; // ensure this isn't already disliked
            Context.SaveChanges();

            // Act
            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.Id    = hfp.Id;
            propertyVM.Liked = false;

            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUser(dsc.Id, dsc.UserName);
            HttpStatusCodeResult response = (HttpStatusCodeResult)controller.UpdateLiked(propertyVM);

            // Assert
            Context.Entry(hfp).Reload();
            hfp.Liked.Should().BeFalse();
        }
Esempio n. 7
0
        public void TransfereeUpdateHomeFindingProperty_UpdatesViewingDate()
        {
            // Arrange
            Order order = BuildOrder(false);

            Context.Orders.Add(order);
            HomeFindingProperty hfp = order.HomeFinding.HomeFindingProperties.First();

            hfp.ViewingDate = null; // ensure this isn't already scheduled
            Context.SaveChanges();

            // Act
            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.Id          = hfp.Id;
            propertyVM.ViewingDate = DateTime.Now;

            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUserAndRole(transferee.Id, transferee.UserName, UserRoles.Transferee);
            HttpStatusCodeResult response = (HttpStatusCodeResult)controller.UpdateViewingDate(propertyVM);

            // Assert
            Context.Entry(hfp).Reload();
            hfp.ViewingDate.Should().BeSameDateAs(propertyVM.ViewingDate.Value);
        }
        public ActionResult PropertyPartial(string id)
        {
            HomeFindingProperty homeFindingProperty;

            homeFindingProperty = _unitOfWork.HomeFindingProperties.GetHomeFindingPropertyById(id);

            HousingPropertyViewModel viewModel = _mapper.Map <HomeFindingProperty, HousingPropertyViewModel>(homeFindingProperty);

            return(PartialView("~/views/orders/partials/_PropertyDetails.cshtml", viewModel));
        }
Esempio n. 9
0
        public ActionResult Create(HousingPropertyViewModel propertyVM)
        {
            var userId = User.Identity.GetUserId();

            Order order = _unitOfWork.Orders.GetOrderFor(userId, propertyVM.OrderId, User.GetUserRole());

            if (order == null || !order.HasHomeFinding)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            HomeFindingProperty homeFindingProperty = new HomeFindingProperty();

            // mapping wipes out the Id - this is hack to resolve that
            propertyVM.Id       = homeFindingProperty.Id;
            propertyVM.CurrUser = User;
            _mapper.Map <HousingPropertyViewModel, HomeFindingProperty>(propertyVM, homeFindingProperty);

            HomeFinding homeFinding = order.HomeFinding;

            homeFinding.HomeFindingProperties.Add(homeFindingProperty);

            foreach (var postedFile in propertyVM.UploadedPhotos)
            {
                if (postedFile != null)
                {
                    try
                    {
                        var storageId = _imageStore.SaveImage(postedFile.InputStream);
                        var urlStr    = _imageStore.UriFor(storageId).AbsoluteUri;
                        var photo     = new Photo(storageId, urlStr);
                        homeFindingProperty.Property.Photos.Add(photo);
                    }
                    catch (Exception e)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable));
                    }
                }
            }

            try
            {
                _unitOfWork.Complete();
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.Created));
        }
        public ActionResult UpdateViewingDate(HousingPropertyViewModel propertyVM)
        {
            HomeFindingProperty homeFindingProperty;

            homeFindingProperty = _unitOfWork.HomeFindingProperties.GetHomeFindingPropertyById(propertyVM.Id);

            // !!!: Do NOT use automapper here. There are issues with mapping back from the VM and in the essence of time I couldn't find a good solution
            // AutoMapper might not be the best best tool for two way mapping
            // https://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/
            homeFindingProperty.ViewingDate = propertyVM.ViewingDate;

            _unitOfWork.Complete();

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }
Esempio n. 11
0
        public ActionResult PropertyPartial(string id)
        {
            HomeFindingProperty homeFindingProperty;

            homeFindingProperty = _unitOfWork.HomeFindingProperties.GetHomeFindingPropertyById(id);

            if (homeFindingProperty == null || !homeFindingProperty.HomeFinding.Order.HasHomeFinding)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            HousingPropertyViewModel viewModel = _mapper.Map <HomeFindingProperty, HousingPropertyViewModel>(homeFindingProperty);

            return(PartialView("~/views/orders/partials/_PropertyDetails.cshtml", viewModel));
        }
Esempio n. 12
0
        public async Task TransfereeInsertProperty_WithPhotos_AddsPhotosToBlobStorage()
        {
            // Arrange
            Order order = BuildOrder();

            Context.Orders.Add(order);
            Context.SaveChanges();
            Context.Entry(order).Reload();

            HousingPropertyViewModel propertyVM = new HousingPropertyViewModel();

            propertyVM.PropertyStreet1 = "abc";
            propertyVM.PropertyStreet2 = "apt 123";
            propertyVM.OrderId         = order.Id;
            var stream = Assembly.GetExecutingAssembly()
                         .GetManifestResourceStream("Odin.IntegrationTests.Resources.odin_login.png");
            var postedFile  = new HttpPostedFileBaseTesting(stream, "image/png", "odin_login.png");
            var postedFile2 = new HttpPostedFileBaseTesting(stream, "image/png", "odin_login.png");

            propertyVM.UploadedPhotos = new List <HttpPostedFileBase> {
                postedFile, postedFile2
            };

            // Act
            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

            controller.MockCurrentUserAndRole(transferee.Id, transferee.UserName, UserRoles.Transferee);
            controller.Create(propertyVM);

            // Assert
            Context.Entry(order).Reload();
            HomeFindingProperty hfp      = order.HomeFinding.HomeFindingProperties.First();
            Property            property = hfp.Property;

            property.Photos.Count().Should().Be(2);

            Photo      propertyPhoto  = property.Photos.First();
            ICloudBlob imageReference = imageStore.ImageBlobFor(propertyPhoto.StorageId);

            imageReference.Should().NotBeNull();

            // Cleanup so we don't flood the azure container
            foreach (Photo p in property.Photos)
            {
                ICloudBlob imageBlob = imageStore.ImageBlobFor(p.StorageId);
                imageBlob.Delete();
            }
        }
Esempio n. 13
0
        public IHttpActionResult UpdateHousingProperty(HousingPropertyViewModel propertyVM)
        {
            HomeFindingProperty homeFindingProperty;

            homeFindingProperty = _unitOfWork.HomeFindingProperties.GetHomeFindingPropertyById(propertyVM.Id);

            var prop = homeFindingProperty.Property;

            prop.Amount            = propertyVM.PropertyAmount;
            prop.NumberOfBathrooms = propertyVM.PropertyNumberOfBathrooms;
            prop.NumberOfBedrooms  = propertyVM.PropertyNumberOfBedrooms;
            prop.SquareFootage     = propertyVM.PropertySquareFootage;

            _unitOfWork.Complete();

            return(Ok());
        }
Esempio n. 14
0
        public ActionResult HousingPartial(string id)
        {
            var userId = User.Identity.GetUserId();

            Order order = _unitOfWork.Orders.GetOrderFor(userId, id, User.GetUserRole());

            ViewBag.CurrentUser  = userId;
            ViewBag.IsConsultant = User.IsInRole(UserRoles.Consultant);
            HousingViewModel         viewModel = new HousingViewModel(order, _mapper, User);
            HousingPropertyViewModel sel       = viewModel.Properties.Where(p => p.selected == true).FirstOrDefault();

            if (sel == null)
            {
                return(PartialView("~/views/orders/partials/_Housing.cshtml", viewModel));
            }
            ViewBag.pmEmail = order.ProgramManager.Email;
            return(PartialView("~/views/orders/partials/_SelectedProperty.cshtml", sel));
        }
        public void TestMappingOfPropertyPhotos()
        {
            string fakeStorageId         = "StorageId";
            string fakePhotoUrl          = "photoURL";
            Photo  fakePhoto             = new Photo(fakeStorageId, fakePhotoUrl);
            HomeFindingProperty hfp      = HomeFindingPropertiesBuilder.New().First();
            Property            property = hfp.Property;

            property.Photos.Add(fakePhoto);
            order.HomeFinding.HomeFindingProperties.Add(hfp);

            HousingViewModel         viewModel         = new HousingViewModel(order, mapper);
            HousingPropertyViewModel propertyViewModel = viewModel.Properties.ElementAt(0);

            propertyViewModel.PropertyPhotos.Should().NotBeNull();
            propertyViewModel.PropertyPhotos.Should().NotBeEmpty();

            PhotoViewModel photoVM = propertyViewModel.PropertyPhotos.ElementAt(0);

            photoVM.PhotoUrl.Should().Be(fakePhotoUrl);
            photoVM.StorageId.Should().Be(fakeStorageId);
        }
Esempio n. 16
0
        public ActionResult UpdateLiked(HousingPropertyViewModel propertyVM)
        {
            HomeFindingProperty homeFindingProperty;

            homeFindingProperty = _unitOfWork.HomeFindingProperties.GetHomeFindingPropertyById(propertyVM.Id);

            if (homeFindingProperty == null || !homeFindingProperty.HomeFinding.Order.HasHomeFinding)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            // !!!: Do NOT use automapper here. There are issues with mapping back from the VM and in the essence of time I couldn't find a good solution
            // AutoMapper might not be the best best tool for two way mapping
            // https://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/

            // for now only support a subset of updated values
            homeFindingProperty.Liked = propertyVM.Liked;

            _unitOfWork.Complete();

            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }