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);
        }
示例#2
0
        public void HandleShouldAddViewingAppointment()
        {
            var property = new Models.Property
            {
                Description     = "Test Property",
                IsListedForSale = false
            };

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

            var appointmentTime = new DateTime(2017, 4, 30, 12, 0, 0);

            var command = new MakeViewingAppointmentCommand();

            command.PropertyId      = 1;
            command.AppointmentTime = appointmentTime;
            command.BuyerUserId     = "Test Buyer";

            _handler.Handle(command);

            _context.Properties.Received(1).Find(1);
            _context.Received(1).SaveChanges();
            Assert.True(property.ViewingAppointments.Count == 1);
            Assert.True(property.ViewingAppointments.First().AppointmentTime == appointmentTime);
            Assert.True(property.ViewingAppointments.First().BuyerUserId == "Test Buyer");
        }
示例#3
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);
        }
        public void HandleShouldAddOffer()
        {
            // Arrange
            var command = new MakeOfferCommand
            {
                PropertyId  = 1,
                BuyerUserId = "111",
                Offer       = 1000,
            };

            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.Offers, null);
        }
        public void HandleShouldUpdatePropertyToBeListedForSale()
        {
            // Arrange
            var command = new ListPropertyCommand
            {
                PropertyId = 1
            };

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

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

            // Act
            // WHEN the property is listed for sale
            _handler.Handle(command);

            // Assert
            _context.Properties.Received(1).Find(1);
            // AND the changes are saved
            _context.Received(1).SaveChanges();
            // THEN the property is listed for sale
            Assert.True(property.IsListedForSale);
        }
示例#6
0
        public void OfferIsAccepted()
        {
            // Arrange
            var command = new AcceptOfferCommand
            {
                PropertyId = 2,
                OfferId    = 6
            };

            // Act
            _handler.Handle(command);

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

            Assert.True(_context.Offers.Count(o => o.Status == OfferStatus.Accepted) == 1);

            var offer = _context.Offers.FirstOrDefault(o => o.Id == 6);

            Assert.True(offer.Status == OfferStatus.Accepted);
        }
示例#7
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());
        }
示例#8
0
        public void OfferIsCreatedAndItsDataIsCorrect()
        {
            // Arrange
            var command = new MakeOfferCommand
            {
                BuyerUserId = "1",
                Offer       = 1,
                PropertyId  = 1
            };

            // Act
            _handler.Handle(command);

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

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

            Assert.True(property.Offers != null);
            Assert.True(property.Offers.Count > 0);
            Assert.True(property.Offers.ElementAt(0).Amount == 1);
            Assert.True(property.Offers.ElementAt(0).BuyerUserId == "1");
        }
示例#9
0
        public void HandleShouldUpdatePropertyToBeListedForSale()
        {
            // Arrange
            var command = new ListPropertyCommand
            {
                PropertyId = 1
            };

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

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

            // Act
            _handler.Handle(command);

            // Assert
            _context.Properties.Received(1).Find(1);
            _context.Received(1).SaveChanges();
            Assert.True(property.IsListedForSale);
        }
示例#10
0
        public void HandleShouldAddOffer()
        {
            var property = new Models.Property
            {
                Description     = "Test Property",
                IsListedForSale = false
            };

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

            var command = new MakeOfferCommand();

            command.PropertyId  = 1;
            command.Offer       = 9999;
            command.BuyerUserId = "Test Buyer";

            _handler.Handle(command);

            _context.Properties.Received(1).Find(1);
            _context.Received(1).SaveChanges();
            Assert.True(property.Offers.Count == 1);
            Assert.True(property.Offers.First().Amount == 9999);
            Assert.True(property.Offers.First().BuyerUserId == "Test Buyer");
        }