public void TransfereeDeleteHomeFindingProperty_SoftDeletesTheRecord()
        {
            // Arrange
            Order order = BuildOrder(false);

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

            // Act
            HomeFindingPropertiesController controller = SetUpHomeFindingPropertiesController();

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

            HomeFindingProperty  hfp      = order.HomeFinding.HomeFindingProperties.First();
            HttpStatusCodeResult response = (HttpStatusCodeResult)controller.Delete(hfp.Id);

            Context.Entry(order).Reload();

            // Assert
            // Soft delete does not remove the association
            order.HomeFinding.HomeFindingProperties.Count().Should().Be(1);

            HomeFindingProperty loadedHfp = order.HomeFinding.HomeFindingProperties.First();

            loadedHfp.Deleted.Should().BeTrue();

            HttpStatusCodeResult expectedCode = new HttpStatusCodeResult(HttpStatusCode.NoContent);

            response.StatusCode.Should().Be(expectedCode.StatusCode);
        }
        public void InsertMessage_ValidProperty_ShouldAddMessageAnd_2Notifications_If_Manager()
        {
            _controller.MockCurrentUserAndRole("9", _userName, UserRoles.ProgramManager);

            var   orderId = "1";
            Order order   = new Order()
            {
                Id = orderId
            };
            var consultant = new Consultant()
            {
                SeContactUid = 1
            };
            var tEmail     = "*****@*****.**";
            var transferee = new Transferee()
            {
                Id = "1", Email = tEmail
            };

            _mockConsultantsRepository.Setup(c => c.GetConsultantBySeContactUid(1)).Returns(consultant);
            _mockTransfereesRepository.Setup(t => t.GetTransfereeByEmail(tEmail)).Returns(transferee);
            _mockRepository.Setup(o => o.GetOrderById(orderId)).Returns(order);
            order.Consultant = consultant;
            order.Transferee = transferee;
            var propId = "1";
            HomeFindingProperty prop = new HomeFindingProperty()
            {
                Id = propId
            };

            _mockHFPRepository.Setup(r => r.GetHomeFindingPropertyById(propId)).Returns(prop);
            Message mess = new Message()
            {
                HomeFindingPropertyId = propId
            };
            MessageDto dto = new MessageDto()
            {
                HomeFindingPropertyId = propId, OrderId = orderId
            };

            var result = _controller.UpsertPropertyMessage(dto);

            prop.Messages.Count.Should().Be(1);

            var rl = _controller.User.IsInRole(UserRoles.ProgramManager);

            rl.Should().BeTrue();

            consultant.UserNotifications.Count().Should().Be(1);

            transferee.UserNotifications.Count().Should().Be(1);

            result.Should().BeOfType <System.Web.Http.Results.OkResult>();
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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();
            }
        }
        public void InsertMessage_ValidProperty_ShouldAddMessageAnd_Consultant_Notification_If_Transferee()
        {
            _controller.MockCurrentUserAndRole(_userId, _userName, UserRoles.Transferee);

            var   orderId = "1";
            Order order   = new Order()
            {
                Id = orderId
            };
            var consultant = new Consultant()
            {
                SeContactUid = 1
            };

            _mockConsultantsRepository.Setup(c => c.GetConsultantBySeContactUid(1)).Returns(consultant);
            _mockRepository.Setup(o => o.GetOrderById(orderId)).Returns(order);
            order.Consultant = consultant;

            var propId = "1";
            HomeFindingProperty prop = new HomeFindingProperty()
            {
                Id = propId
            };

            _mockHFPRepository.Setup(r => r.GetHomeFindingPropertyById(propId)).Returns(prop);
            Message mess = new Message()
            {
                HomeFindingPropertyId = propId
            };
            MessageDto dto = new MessageDto()
            {
                HomeFindingPropertyId = propId, OrderId = orderId
            };

            var result = _controller.UpsertPropertyMessage(dto);

            prop.Messages.Count.Should().Be(1);

            var rl = _controller.User.IsInRole(UserRoles.Transferee);

            rl.Should().BeTrue();

            consultant.UserNotifications.Count().Should().Be(1);

            result.Should().BeOfType <System.Web.Http.Results.OkResult>();
        }
        public void InsertMessage_ValidProperty_ShouldAddMessage_No_Notification_If_Not_EE_MAN_CON()
        {
            _controller.MockCurrentUser(_userId, _userName);
            var   orderId = "1";
            Order order   = new Order()
            {
                Id = orderId
            };
            var consultant = new Consultant()
            {
                SeContactUid = 1
            };

            _mockRepository.Setup(o => o.GetOrderById(orderId)).Returns(order);
            var propId = "1";
            HomeFindingProperty prop = new HomeFindingProperty()
            {
                Id = propId
            };

            _mockHFPRepository.Setup(r => r.GetHomeFindingPropertyById(propId)).Returns(prop);
            Message mess = new Message()
            {
                HomeFindingPropertyId = propId
            };
            MessageDto dto = new MessageDto()
            {
                HomeFindingPropertyId = propId, OrderId = orderId
            };

            var result = _controller.UpsertPropertyMessage(dto);
            var rl     = _controller.User.IsInRole(UserRoles.Transferee);

            rl.Should().BeFalse();
            var rlC = _controller.User.IsInRole(UserRoles.Consultant);

            rlC.Should().BeFalse();
            var rlM = _controller.User.IsInRole(UserRoles.ProgramManager);

            rlM.Should().BeFalse();
            consultant.UserNotifications.Count().Should().Be(0);
            prop.Messages.Count.Should().Be(1);
        }
        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);
        }
        public void GetUpcomingHomeFindingPropertiesByOrderId_ReturnsOnlyFutureProperties()
        {
            HomeFinding homeFinding = HomeFindingBuilder.New();

            HomeFindingProperty yesterdayHFP = HomeFindingPropertiesBuilder.New().First();

            yesterdayHFP.ViewingDate = DateTime.Now.AddDays(-1);
            yesterdayHFP.HomeFinding = homeFinding;

            HomeFindingProperty tomorrowHFP = HomeFindingPropertiesBuilder.New().First();

            tomorrowHFP.ViewingDate = DateTime.Now.AddDays(1);
            tomorrowHFP.HomeFinding = homeFinding;

            HomeFindingProperty nextWeekHFP = HomeFindingPropertiesBuilder.New().First();

            nextWeekHFP.ViewingDate = DateTime.Now.AddDays(7);
            nextWeekHFP.HomeFinding = homeFinding;

            HomeFindingProperty noShowingHFP = HomeFindingPropertiesBuilder.New().First();

            noShowingHFP.ViewingDate = null;
            noShowingHFP.HomeFinding = homeFinding;

            var hfps = new[] { yesterdayHFP, tomorrowHFP, nextWeekHFP, noShowingHFP };

            SetupRepositoryWithSource(hfps);

            // Act
            IEnumerable <HomeFindingProperty> upcomingViewings = _homeFindingPropertiesRepository.GetUpcomingHomeFindingPropertiesByHomeFindingId(homeFinding.Id);

            // Assert
            upcomingViewings.Count().Should().Be(2);
            upcomingViewings.Should().NotContain(yesterdayHFP);
            upcomingViewings.Should().NotContain(noShowingHFP);
            upcomingViewings.Should().Contain(tomorrowHFP);
            upcomingViewings.Should().Contain(nextWeekHFP);
        }
Exemplo n.º 9
0
        public ActionResult MessagePartial(string id)
        {
            PropertyMessagesViewModel viewModel = new PropertyMessagesViewModel();
            HomeFindingProperty       property  = getPropertyById(id);

            if (property == null)
            {
                return(HttpNotFound());
            }
            viewModel.messages = GetMessagesByPropertyId(property.Id);
            if (viewModel.messages == null)
            {
                return(HttpNotFound());
            }
            if (viewModel.messages.Count() > 0)
            {
                viewModel.latest = viewModel.messages.First().MessageDate;
            }
            viewModel.Id = property.Id;
            var userId = User.Identity.GetUserId();

            ViewBag.CurrentUser = userId;
            return(PartialView("~/views/Orders/Partials/_Message.cshtml", viewModel));
        }
        public void markMessagesAsRead_ValidUserNotification_ReturnOkWithMessageIsRead_True()
        {
            _controller.MockCurrentUser(_userId, _userName);
            var propId = "1";
            HomeFindingProperty prop = new HomeFindingProperty()
            {
                Id = propId
            };

            _mockHFPRepository.Setup(r => r.GetHomeFindingPropertyById(propId)).Returns(prop);

            Message mess = new Message()
            {
                HomeFindingPropertyId = propId
            };

            prop.Messages.Add(mess);
            _mockMessageRepository.Setup(r => r.GetMessagesByPropertyId(propId)).Returns(prop.Messages);

            var result = _controller.markMessageRead(propId) as IHttpActionResult;

            result.Should().BeOfType <System.Web.Http.Results.OkResult>();
            mess.IsRead.Should().Be(true);
        }
        public void NewHomeFindingPropertyLikedIsNull()
        {
            HomeFindingProperty hfp = new HomeFindingProperty();

            hfp.Liked.Should().BeNull();
        }