示例#1
0
        public void HandleShouldAddViewingToProperty()
        {
            // Arrange
            var userId = Guid.NewGuid().ToString();

            var bookViewingCommand = new BookViewingCommand()
            {
                PropertyId  = 1,
                ViewingDate = DateTime.Now,
                UserId      = userId
            };

            var property = new Domain.Models.Property
            {
                Id          = 1,
                Description = "Test Property"
            };

            _context.Properties.Find(1).Returns(property);

            // Act
            _bookViewingHandler.Handle(bookViewingCommand);

            // Assert
            var testProperty = _context.Properties.Find(1);

            Assert.That(testProperty.Viewings.Count, Is.EqualTo(1));
            Assert.That(testProperty.Viewings.First().UserId, Is.EqualTo(userId));
            Assert.That(testProperty.Viewings.First().ViewingDate, Is.EqualTo(bookViewingCommand.ViewingDate));
            Assert.That(testProperty.Viewings.First().ViewingStatus, Is.EqualTo(ViewingStatus.Pending));
        }
        public ActionResult BookViewing(BookViewingCommand bookViewingCommand)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var handler = new BookViewingCommandHandler(_context);

                    bookViewingCommand.BuyerId = User.Identity.GetUserId();

                    if (!handler.Handle(bookViewingCommand))
                    {
                        ModelState.AddModelError("ViewingDate", @"You can book only 1 viewing per day on this property!");
                        var builder   = new AvailableViewingsViewModelBuilder(_context);
                        var viewModel = builder.Build(bookViewingCommand.PropertyId, bookViewingCommand.ViewingDate);
                        viewModel.ViewingTime = bookViewingCommand.ViewingTime;
                        return(View(viewModel));
                    }

                    return(RedirectToAction("Index", "Property"));
                }
                catch (Exception e)
                {
                    return(View("Error", new HandleErrorInfo(e, GetType().Name, MethodBase.GetCurrentMethod().Name)));
                }
            }
            return(View());
        }
示例#3
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            command.BuyerId = this.HttpContext.User.Identity.GetUserId();
            var handler = new BookViewingCommandHandler(_uow);

            handler.Handle(command);
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            BookViewingCommandHandler handler = new BookViewingCommandHandler(_context);
            string buyerId = User.Identity.GetUserId();

            handler.Handle(command, buyerId);

            return(RedirectToAction("Index"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            command.userId = User.Identity.GetUserId();

            handler.Handle(command);

            return(RedirectToAction("Index", "Property"));
        }
        public ActionResult BookViewing(BookViewingCommand command)
        {
            var handler = new BookViewingCommandHandler(_context);

            // Add the user id of the buyer making the offer.
            command.UserId = User.Identity.GetUserId();

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }
        public void HandlerShouldAddViewing()
        {
            // Arrange
            var command = new BookViewingCommand();

            // Act
            _handler.Handle(command);

            // Assert
            _context.Viewings.Received(1).Add(Arg.Any <Viewing>());
        }
示例#9
0
        public ActionResult BookViewing(BookViewingCommand command)
        {
            if (ModelState.IsValid)
            {
                var handler = new BookViewingCommandHandler(_context);

                command.BuyerUserId = User.Identity.GetUserId();

                handler.Handle(command);
            }
            return(RedirectToAction("Index"));
        }
        public void HandleShouldAddViewingWithCorrectBuyerId()
        {
            // Arrange
            var command = new BookViewingCommand
            {
                BuyerUserId = "BuyerId1"
            };

            // Act
            _handler.Handle(command);

            // Assert
            _context.Viewings.Received(1).Add(Arg.Is <Viewing>(p => p.BuyerUserId == "BuyerId1"));
        }
        public void HandleShouldAddViewingWithCorrectAppointment()
        {
            //
            var command = new BookViewingCommand
            {
                Appointment = DateTime.Today.AddDays(3)
            };

            // Act
            _handler.Handle(command);

            // Assert
            _context.Viewings.Received(1).Add(Arg.Is <Viewing>(p => p.Appointment == DateTime.Today.AddDays(3)));
        }
        public void HandleShouldAddViewingWithCorrectPropertyId()
        {
            // Arrange
            var command = new BookViewingCommand
            {
                PropertyId = 25
            };

            // Act
            _handler.Handle(command);

            // Assert
            _context.Viewings.Received(1).Add(Arg.Is <Viewing>(p => p.PropertyId == 25));
        }
        public void When_User_Books_Viewing()
        {
            context = Substitute.For <IOrangeBricksContext>();
            context.Properties.Find(1).Returns(new Models.Property {
                Id = 1
            });
            context.Viewings.Returns(Substitute.For <IDbSet <Models.Viewing> >());
            BookViewingCommandHandler handler = new BookViewingCommandHandler(this.context);
            BookViewingCommand        command = new BookViewingCommand
            {
                PropertyId  = 1,
                UserId      = "test",
                ViewingTime = new DateTime(2017, 01, 03, 10, 10, 0)
            };

            handler.Handle(command);
        }
        public ActionResult Book(BookViewingViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(Book(viewModel.PropertyId));
            }

            var command = new BookViewingCommand
            {
                Appointment = viewModel.Appointment,
                PropertyId  = viewModel.PropertyId,
                BuyerUserId = User.Identity.GetUserId()
            };

            var handler = new BookViewingCommandHandler(_context);

            handler.Handle(command);

            return(RedirectToAction("Index", "Property"));
        }
示例#15
0
        public void AddViewingForProperty()
        {
            // Arrange
            var command = new BookViewingCommand
            {
                PropertyId = 1
            };

            var property = new Models.Property
            {
                Description = "Test Property",       
            };

            _properties.Find(1).Returns(property);

            // Act
            _handler.Handle(command);

            // Assert
            _context.Properties.Received(1).Find(1);
            _context.Received(1).SaveChanges();
            Assert.True(property.Viewings.Any());
        }
        public void HandleShouldAddViewing()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context);

            var property = new Models.Property {
                Id = 1, StreetName = "Some street", Description = "Great location", IsListedForSale = true
            };

            _properties.Find(1).Returns(property);

            var command = new BookViewingCommand();

            command.Appointment = DateTime.Now;
            command.PropertyId  = 1;
            command.BuyerId     = Guid.NewGuid().ToString();

            // Act
            _handler.Handle(command);

            // Assert
            Assert.IsTrue(property.Viewings.Count == 1);
        }