public void AppointmentIsCreatedAndItsDataIsCorrect()
        {
            var date = DateTime.Now;

            // Arrange
            var command = new BookAppointmentCommand
            {
                BuyerUserId = "1",
                Date        = date,
                PropertyId  = 1
            };

            // Act
            _handler.Handle(command);

            // Assert
            _context.Received(1).SaveChanges();

            var property = _context.Properties.FirstOrDefault(p => p.Id == 1);

            Assert.True(property.Appointments != null);
            Assert.True(property.Appointments.Count > 0);

            var notChangedProperty = _context.Properties.FirstOrDefault(p => p.Id != 1);

            Assert.True(notChangedProperty.Appointments == null ||
                        notChangedProperty.Appointments.Count == 0);

            var appointment = property.Appointments.ElementAt(0);

            Assert.True(appointment.Date == date);
            Assert.True(appointment.BuyerUserId == "1");
            Assert.True(appointment.Status == AppointmentStatus.Pending);
        }
Exemple #2
0
        public void HandleShouldAddAppointment()
        {
            // Arrange
            var command = new BookAppointmentCommand
            {
                PropertyId          = 1,
                BuyerUserId         = "111",
                AppointmentDateTime = DateTime.Now,
            };

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

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


            // Act
            _handler.Handle(command);

            // Assert
            _context.Properties.Received(1).Find(1);
            _context.Received(1).SaveChanges();
            Assert.AreNotEqual(property.Appointments, null);
        }
Exemple #3
0
        public ActionResult BookAppointment(BookAppointmentCommand command)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var handler = new BookAppointmentCommandHandler(_context);

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

                    if (!handler.Handle(command))
                    {
                        ModelState.AddModelError("", "You already booked an appointment.");
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Adding appointment failed.");
            }

            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public ActionResult BookAppointment(BookAppointmentCommand command)
        {
            var handler = new BookAppointmentCommandHandler(_context);

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

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }
        public ActionResult BookAppointment(BookAppointmentCommand command)
        {
            command.BuyerUserId = UserId;

            var handler = new BookAppointmentCommandHandler(Context);

            handler.Handle(command);

            return(RedirectToAction("Index"));
        }