コード例 #1
0
        public void AddReviewTestOk()
        {
            Accommodation accommodation = new Accommodation()
            {
                Id     = 2,
                Name   = "abz",
                SpotId = 1
            };
            Booking booking = new Booking()
            {
                Id = 2
            };
            Review review = new Review()
            {
                Id = 1
            };
            var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict);
            var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict);
            var mockReview        = new Mock <IReviewRepository>(MockBehavior.Strict);
            var mockBooking       = new Mock <IBookingRepository>(MockBehavior.Strict);

            mockBooking.Setup(p => p.GetById(It.IsAny <int>())).Returns(booking);
            mockReview.Setup(p => p.AddAndSave(It.IsAny <Review>())).Returns(review);
            var logic = new AccommodationLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockReview.Object, mockBooking.Object);

            logic.AddReview(review);

            mockAccommodation.VerifyAll();
        }
コード例 #2
0
        public void AddReviewTest()
        {
            Accommodation accom = new Accommodation()
            {
                Id   = 1,
                Name = "a"
            };
            Booking booking = new Booking()
            {
                Id = 1,
                AccommodationId = 1,
                HeadGuest       = new Tourist()
                {
                    Id       = 1,
                    Email    = "*****@*****.**",
                    Name     = "a",
                    LastName = "a"
                }
            };
            Review review = new Review()
            {
                Id        = 5,
                BookingId = 1,
                Comment   = "test",
                Score     = 1,
            };
            var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict);
            var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict);
            var mockReview        = new Mock <IReviewRepository>(MockBehavior.Strict);
            var mockBooking       = new Mock <IBookingRepository>(MockBehavior.Strict);

            mockReview.Setup(p => p.AddAndSave(It.IsAny <Review>())).Returns(review);
            mockBooking.Setup(a => a.GetById(It.IsAny <int>())).Returns(booking);
            var logic = new AccommodationLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockReview.Object, mockBooking.Object);

            var result = logic.AddReview(review);

            mockAccommodation.VerifyAll();
            mockTouristicSpot.VerifyAll();
            Assert.IsTrue(result.Equals(review));
        }