public void BuildShouldReturnPropertiesWithMatchingDescriptionsWhenSearchTermIsProvided()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context);

            var properties = new List <Models.Property> {
                new Models.Property {
                    StreetName = "", Description = "Great location", IsListedForSale = true
                },
                new Models.Property {
                    StreetName = "", Description = "Town house", IsListedForSale = true
                }
            };

            var mockSet = Substitute.For <IDbSet <Models.Property> >()
                          .Initialize(properties.AsQueryable());

            _context.Properties.Returns(mockSet);

            var query = new PropertiesQuery
            {
                Search = "Town"
            };

            // Act
            var viewModel = builder.Build(query);

            // Assert
            Assert.That(viewModel.Properties.Count, Is.EqualTo(1));
            Assert.That(viewModel.Properties.All(p => p.Description.Contains("Town")));
        }
Exemple #2
0
        public ActionResult Index(PropertiesQuery query)
        {
            var builder   = new PropertiesViewModelBuilder(_context);
            var viewModel = builder.Build(query);

            return(View(viewModel));
        }
        public ActionResult Index(FindPropertyCommand command)
        {
            var builder   = new PropertiesViewModelBuilder(this._context);
            var viewModel = builder.Build(command);

            return(this.View(viewModel));
        }
Exemple #4
0
        public BookingsOnPropertyViewModel Build(int id)
        {
            var aProperty = _context.Properties
                            .Where(p => p.Id == id)
                            .Include(x => x.Bookings)
                            .SingleOrDefault();

            var bookings = aProperty.Bookings ?? new List <Booking>();


            return(new BookingsOnPropertyViewModel
            {
                HasBookings = bookings.Any(),
                Bookings = bookings.Select(x => new BookingViewModel
                {
                    Id = x.Id,
                    ViewingAt = x.ViewingAt,

                    IsRequested = x.Status == (int)BookingStatus.Requested,
                    Status = (BookingStatus)x.Status,

                    Property = null
                }),
                Property = PropertiesViewModelBuilder.MapViewModel(aProperty)
            });
        }
        public void BuildShouldReturnPropertiesWithMatchingStreetNamesWhenSearchTermIsProvided()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context);

            var properties = new List <Models.Property> {
                new Models.Property {
                    StreetName = "Smith Street", Description = "", IsListedForSale = true
                },
                new Models.Property {
                    StreetName = "Jones Street", Description = "", IsListedForSale = true
                }
            };

            var mockSet = Substitute.For <IDbSet <Models.Property> >()
                          .Initialize(properties.AsQueryable());

            _context.Properties.Returns(mockSet);

            var command = new FindPropertyCommand
            {
                Search = "Smith Street"
            };

            // Act
            var viewModel = builder.Build(command);

            // Assert
            Assert.That(viewModel.Properties.Count, Is.EqualTo(1));
        }
Exemple #6
0
        public ActionResult Index(PropertiesQuery query)
        {
            var builder = new PropertiesViewModelBuilder(_context);

            query.CurrentUserId = User.Identity.GetUserId();
            var viewModel = builder.Build(query);

            return(View(viewModel));
        }
        public ActionResult Index(PropertiesQuery query)
        {
            // Add user id of the user making the query.
            query.UserId = User.Identity.GetUserId();

            var builder   = new PropertiesViewModelBuilder(_context);
            var viewModel = builder.Build(query);

            return(View(viewModel));
        }
        public ActionResult Index(PropertiesQuery query)
        {
            var builder = new PropertiesViewModelBuilder(Context);

            var isSeller = User.IsInRole("Seller");

            var viewModel = builder.Build(query, isSeller);

            return(View(viewModel));
        }
Exemple #9
0
        public ActionResult Index(PropertiesQuery query)
        {
            var builder   = new PropertiesViewModelBuilder(_context);
            var viewModel = builder.Build(query);

            //now from here  we need to get status of property , which has been accepted by seller
            //that status , we need to forward to buyers to see that it has been accpeted.


            string uname = User.Identity.Name;
            // we will get the user name
            string qry = "select id  from AspNetUsers where Email='" + uname + "'";

            SqlDataAdapter adpt = new SqlDataAdapter(qry, con);
            DataSet        ds   = new DataSet();

            adpt.Fill(ds);

            string uid = ds.Tables[0].Rows[0]["id"].ToString();

            string qry1 = "select RoleId  from AspNetUserRoles where UserId='" + uid + "'";
            // acording to userid we have got role id ao we know its seller or buyer.
            SqlDataAdapter adpt1 = new SqlDataAdapter(qry1, con);
            DataSet        ds1   = new DataSet();

            adpt1.Fill(ds1);
            string RID  = ds1.Tables[0].Rows[0]["RoleId"].ToString();
            string qry2 = "select name from AspNetRoles where Id='" + RID + "'";

            SqlDataAdapter adpt2 = new SqlDataAdapter(qry2, con);
            DataSet        ds2   = new DataSet();

            adpt2.Fill(ds2);
            string rolename = ds2.Tables[0].Rows[0]["name"].ToString();

            // we have got role name and then checked role name is buyer then
            if (rolename == "Buyer")
            {
                string         qry3  = "select  Properties.id from offers, Properties   where offers.Property_id=Properties.id and Status=1";
                SqlDataAdapter adpt3 = new SqlDataAdapter(qry3, con);
                DataSet        ds3   = new DataSet();
                adpt3.Fill(ds3);

                Session["ds"] = ds3;



                // here we have done coding for whatever seller has accpeted that  offer made by buyr's and buyer can see that offer as soon
                //as soon he will see his property with message that offer has been accpeted. after that coding n Index view page of property view folder.
            }



            return(View(viewModel));
        }
Exemple #10
0
        public BookingViewModel Build(int id)
        {
            var property = _context.Properties.Find(id);

            return(new BookingViewModel
            {
                Status = BookingStatus.Requested,
                Property = PropertiesViewModelBuilder.MapViewModel(property),
                ViewingAt = DateTime.Now.ToUniversalTime()
            });
        }
        public void BuildShouldReturnPropertiesWithViewingBookedByBuyer()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context);
            var userId  = System.Guid.NewGuid().ToString();

            var viewings = new List <Viewing>
            {
                new Viewing {
                    Id = 1, ViewingDate = DateTime.Now.AddDays(1), ViewingStatus = ViewingStatus.Rejected, UserId = Guid.NewGuid().ToString()
                },
                new Viewing {
                    Id = 2, ViewingDate = DateTime.Now.AddDays(1), ViewingStatus = ViewingStatus.Confirmed, UserId = userId
                }
            };

            var viewings2 = new List <Viewing>
            {
                new Viewing {
                    Id = 3, ViewingDate = DateTime.Now.AddDays(1), ViewingStatus = ViewingStatus.Rejected, UserId = userId
                },
                new Viewing {
                    Id = 4, ViewingDate = DateTime.Now.AddDays(1), ViewingStatus = ViewingStatus.Pending, UserId = Guid.NewGuid().ToString()
                }
            };

            var properties = new List <Domain.Models.Property> {
                new Domain.Models.Property {
                    Id = 1, StreetName = "", Description = "Great location", IsListedForSale = true, Viewings = viewings
                },
                new Domain.Models.Property {
                    Id = 2, StreetName = "", Description = "Town house", IsListedForSale = true, Viewings = viewings2
                }
            };

            var mockSet = Substitute.For <IDbSet <Domain.Models.Property> >()
                          .Initialize(properties.AsQueryable());

            _context.Properties.Returns(mockSet);

            var query = new PropertiesQuery
            {
                Search = "",
                UserId = userId
            };

            // Act
            var viewModel = builder.Build(query);

            // Assert
            Assert.That(viewModel.Properties.Count, Is.EqualTo(2));
            Assert.That(viewModel.Properties.Single(p => p.Id == 1).BuyerBookedViewing != null, Is.True);
            Assert.That(viewModel.Properties.Single(p => p.Id == 2).BuyerBookedViewing != null, Is.True);
        }
        public void BuildShouldReturnPropertiesWithOfferAcceptedForBuyer()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context);
            var userId  = System.Guid.NewGuid().ToString();

            var offersAccepted = new List <Offer>
            {
                new Offer {
                    Amount = 1000, Id = 1, Status = OfferStatus.Rejected, UserId = Guid.NewGuid().ToString()
                },
                new Offer {
                    Amount = 2000, Id = 2, Status = OfferStatus.Accepted, UserId = userId
                }
            };

            var offersRejected = new List <Offer>
            {
                new Offer {
                    Amount = 1000, Id = 3, Status = OfferStatus.Rejected, UserId = userId
                },
                new Offer {
                    Amount = 2000, Id = 4, Status = OfferStatus.Pending, UserId = Guid.NewGuid().ToString()
                }
            };

            var properties = new List <Domain.Models.Property> {
                new Domain.Models.Property {
                    StreetName = "", Description = "Great location", IsListedForSale = true, Offers = offersAccepted
                },
                new Domain.Models.Property {
                    StreetName = "", Description = "Town house", IsListedForSale = true, Offers = offersRejected
                }
            };

            var mockSet = Substitute.For <IDbSet <Domain.Models.Property> >()
                          .Initialize(properties.AsQueryable());

            _context.Properties.Returns(mockSet);

            var query = new PropertiesQuery
            {
                Search = "",
                UserId = userId
            };

            // Act
            var viewModel = builder.Build(query);

            // Assert
            Assert.That(viewModel.Properties.Count, Is.EqualTo(2));
            Assert.That(viewModel.Properties.First().BuyerOfferAccepted != null, Is.True);
            Assert.That(viewModel.Properties.Last().BuyerOfferAccepted != null, Is.False);
        }
        public OffersViewModel Build(PropertiesQuery query, string buyerUserId)
        {
            List <Offer> offers = _context.Offers.Where(o => o.BuyerUserId == buyerUserId).ToList();


            if (!string.IsNullOrWhiteSpace(query.Search))
            {
                //TODO:
            }

            return(new OffersViewModel
            {
                Offers = offers.Select(o => new OfferViewModel()
                {
                    Amount = o.Amount,
                    Status = ((OfferStatus)o.Status).ToString(),
                    Property = PropertiesViewModelBuilder.MapViewModel(o.ProperyRef)
                }).ToList(),
                Search = query.Search
            });
        }
Exemple #14
0
        public void BuildShouldReturnPropertiesWithOfferStatus()
        {
            // Arrange
            var builder = new PropertiesViewModelBuilder(_context, _userId);

            var properties = new List <Models.Property> {
                new Models.Property {
                    Id = 1, StreetName = "", Description = "Great location", IsListedForSale = true, Offers = new List <Offer>()
                },
                new Models.Property {
                    Id = 2, StreetName = "", Description = "Town house", IsListedForSale = true, Offers = new List <Offer> ()
                }
            };

            properties.First().Offers = new List <Offer>()
            {
                new Offer {
                    Id = 1, Amount = 1000, BuyerUserId = _userId, Status = OfferStatus.Accepted
                }
            };

            var mockSet = Substitute.For <IDbSet <Models.Property> >()
                          .Initialize(properties.AsQueryable());

            _context.Properties.Returns(mockSet);

            var query = new PropertiesQuery
            {
                Search = ""
            };

            // Act
            var viewModel = builder.Build(query);

            // Assert
            Assert.That(viewModel.Properties.Count, Is.EqualTo(2));
            Assert.AreEqual(viewModel.Properties.First().OfferStatus, "Accepted");
        }
        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);
        }