public void Create_ShouldAddNewGuestReviewWithGivenParamsIntoTheDb()
        {
            //Arrange
            var hostId             = "hostId";
            var guestId            = "guestId";
            var evaluation         = 5;
            var title              = "title";
            var additionalThoughts = "somethhing";

            var db      = LendYourHomeDbMock.New();
            var service = new GuestReviewsService(db);

            //Act
            service.Create(hostId, guestId, evaluation, additionalThoughts, title);

            //Assert
            db.GuestReviews
            .Any(r => r.Title == title &&
                 r.EvaluatedGuestId == guestId &&
                 r.HostId == hostId &&
                 r.AdditionalThoughts == additionalThoughts &&
                 r.Evaluation == evaluation)
            .Should()
            .BeTrue();
        }
Esempio n. 2
0
        public void Create_ShouldAddNewReviewWithGivenParamsIntoTheDb()
        {
            //Arrange
            var userId       = "user";
            var homeId       = 1;
            var evaluation   = 5;
            var additionalTh = "something";
            var title        = "good";

            var db      = LendYourHomeDbMock.New();
            var service = new HomeReviewsService(db);

            //Act
            service.Create(userId, homeId, evaluation, additionalTh, title);

            //Assert
            db.HomeReviews
            .Any(r => r.HomeId == homeId &&
                 r.EvaluatingGuestId == userId &&
                 r.Title == title &&
                 r.Evaluation == evaluation &&
                 r.AdditionalThoughts == additionalTh)
            .Should()
            .BeTrue();
        }
        public async Task Approve_ShouldApproveBooking()
        {
            //Arrange
            var bookingId = 1;

            var db = LendYourHomeDbMock.New();

            db.Bookings.Add(new Booking
            {
                Id           = bookingId,
                CheckInDate  = DateTime.UtcNow.AddDays(10),
                CheckOutDate = DateTime.UtcNow.AddDays(11),
                IsApproved   = false
            });
            await db.SaveChangesAsync();

            var service = new BookingService(db);

            //Act
            service.Approve(bookingId);

            //Assert
            db.Bookings
            .Any(b => b.Id == bookingId && b.IsApproved == true)
            .Should()
            .BeTrue();
        }
        public void Exists_ShouldReturnFalseForNonExistingBoking()
        {
            //Arrange
            var db      = LendYourHomeDbMock.New();
            var service = new BookingService(db);

            //Act
            var result = service.Exists(1, "a");

            //Assert
            result
            .Should()
            .BeFalse();
        }
        public async Task HostBookings_WithApprovedSetToFalse_ShouldReturnOnlyPendingBookingsForGivenHosttId()
        {
            //Arrange
            var db = LendYourHomeDbMock.New();

            await this.SeedBookingsAsync(db);

            var service = new BookingService(db);

            //Act
            var result = service.HostBookings(1, 5, hostID, false);

            //Assert
            result
            .Count()
            .Should()
            .Be(3);
        }
        public async Task GuestBookings_WithApprovedSetToTrue_ShouldReturnOnlyApprovedBookingsForGivenGuestId()
        {
            //Arrange
            var db = LendYourHomeDbMock.New();

            await this.SeedBookingsAsync(db);

            var service = new BookingService(db);

            //Act
            var result = service.GuestBookings(guestId, true);

            //Assert
            result
            .Count()
            .Should()
            .Be(1);
        }
        public async Task Exists_ShouldReturnTrueForExistingBooking()
        {
            //Arrange
            var homeId    = 1;
            var bookingId = 1;

            var booking = new Booking
            {
                Id           = bookingId,
                GuestId      = guestId,
                CheckInDate  = DateTime.UtcNow.AddDays(10),
                CheckOutDate = DateTime.UtcNow.AddDays(11)
            };

            booking.Home = new Home
            {
                Id      = homeId,
                OwnerId = hostID,
                Additionalnformation = "info",
                Address       = "address",
                Bathrooms     = 1,
                Bedrooms      = 1,
                City          = "Sofia",
                Country       = "Bulgaria",
                IsActiveOffer = true,
                Sleeps        = 1,
                PricePerNight = 10
            };

            var db = LendYourHomeDbMock.New();

            db.Bookings.Add(booking);
            await db.SaveChangesAsync();

            var service = new BookingService(db);

            //Act
            var result = service.Exists(bookingId, hostID);

            //Assert
            result
            .Should()
            .BeTrue();
        }
        public async Task GetReceivedReviews_ShouldReturnOnlyTheReviewsReceivedByGuestWithGivenGuestId()
        {
            //Arrange
            var guestId = "guestId";

            var db           = LendYourHomeDbMock.New();
            var guestReview1 = new GuestReview
            {
                Title = "title",
                AdditionalThoughts = "thounghts",
                SubmitDate         = DateTime.MinValue,
                HostId             = "hostId",
                EvaluatedGuestId   = guestId
            };

            var guestReview2 = new GuestReview
            {
                Title = "title",
                AdditionalThoughts = "thounghts",
                SubmitDate         = DateTime.MinValue,
                HostId             = "hostId",
                EvaluatedGuestId   = "someOtherID"
            };

            db.GuestReviews.Add(guestReview1);
            db.GuestReviews.Add(guestReview2);
            await db.SaveChangesAsync();

            var service = new GuestReviewsService(db);

            //Act
            var result = service.GetReceivedReviews(guestId, 1, int.MaxValue);

            //Assert
            result
            .Count()
            .Should()
            .Be(1);
        }
        public void Create_ShouldAddNewBookingWithTeGivenParamsIntoTheDb()
        {
            //Arrange
            var homeId       = 1;
            var checkInDate  = DateTime.UtcNow.AddDays(10);
            var checkOutDate = DateTime.UtcNow.AddDays(11);

            var db      = LendYourHomeDbMock.New();
            var service = new BookingService(db);

            //Act
            service.Create(guestId, homeId, checkInDate, checkOutDate);

            //Assert
            db.Bookings
            .Any(b => b.GuestId == guestId &&
                 b.HomeId == homeId &&
                 b.CheckInDate == checkInDate &&
                 b.CheckOutDate == checkOutDate)
            .Should()
            .BeTrue();
        }