コード例 #1
0
        public void CreateValidReserveTestOk()
        {
            var reserveRepositoryMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);

            reserveRepositoryMock.Setup(m => m.Add(It.IsAny <Reserve>()));

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(lodging);

            var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);

            touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot);
            var touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic);
            ReserveManagement reserveLogic = new ReserveManagement(reserveRepositoryMock.Object, lodgingLogic);

            Reserve reserve = new Reserve()
            {
                Name            = "Joaquin",
                LastName        = "Lamela",
                Email           = "*****@*****.**",
                CheckIn         = new DateTime(2020, 05, 25),
                CheckOut        = new DateTime(2020, 06, 10),
                QuantityOfAdult = 2,
                QuantityOfChild = 2,
                QuantityOfBaby  = 1
            };

            Reserve resultOfCreateAReserve = reserveLogic.Create(reserve, lodging.Id);

            reserveRepositoryMock.VerifyAll();
            Assert.IsTrue(reserve.Equals(resultOfCreateAReserve));
        }
コード例 #2
0
        public void CreateValidLodgingTestOk()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>()));
            lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null);

            var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);

            touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot);
            TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic);

            Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath);

            Lodging lodgingToCompare = new Lodging()
            {
                Id              = resultOfCreateALodging.Id,
                Name            = resultOfCreateALodging.Name,
                QuantityOfStars = resultOfCreateALodging.QuantityOfStars,
                Address         = resultOfCreateALodging.Address,
                Images          = resultOfCreateALodging.Images,
                PricePerNight   = resultOfCreateALodging.PricePerNight,
                IsAvailable     = resultOfCreateALodging.IsAvailable,
                TouristSpot     = resultOfCreateALodging.TouristSpot
            };

            lodgingRepositoryMock.VerifyAll();
            Assert.AreEqual(lodging, lodgingToCompare);
        }
コード例 #3
0
        public void CreateInvalidReserveWithoutLodgingTest()
        {
            var reserveRepositoryMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);

            reserveRepositoryMock.Setup(m => m.Add(It.IsAny <Reserve>()));

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientBusinessLogicException());

            var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);

            touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot);
            var touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic);
            var reserveLogic = new ReserveManagement(reserveRepositoryMock.Object, lodgingLogic);

            reserveLogic = new ReserveManagement(reserveRepositoryMock.Object, lodgingLogic);

            Reserve reserve = new Reserve()
            {
                Name            = "Joaquin",
                LastName        = "Lamela",
                Email           = "*****@*****.**",
                CheckIn         = new DateTime(2020, 05, 25),
                CheckOut        = new DateTime(2020, 06, 10),
                QuantityOfAdult = 2,
                QuantityOfChild = 2,
                QuantityOfBaby  = 1
            };

            Reserve resultOfCreateAReserve = reserveLogic.Create(reserve, lodging.Id);
        }
コード例 #4
0
        public void FailInUpdateNotExistLodgingTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientException());
            lodgingRepositoryMock.Setup(m => m.Update(It.IsAny <Lodging>()));
            LodgingManagement lodgingLogic   = new LodgingManagement(lodgingRepositoryMock.Object);
            Lodging           resultOfUpdate = lodgingLogic.UpdateLodging(lodging.Id, lodging);
        }
コード例 #5
0
        public void FailAboutUpdateAverageReviewScoreTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Update(lodging)).Throws(new ServerException());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            lodgingLogic.UpdateAverageReviewScore(lodging, 4.5);
        }
コード例 #6
0
        public void FailInGetLodgingByTouristSpotInternalErrorTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.GetAvailableLodgingsByTouristSpot(touristSpot.Id)).Throws(new ServerException());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            lodgingLogic.GetAvailableLodgingsByTouristSpot(touristSpot.Id);
        }
コード例 #7
0
        public void ClientErrorInGetLodgingTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientException());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            Lodging resultOfGetLodging = lodgingLogic.GetLodgingById(lodging.Id);
        }
コード例 #8
0
        public void RemoveInvalidLodgingNotExistTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientException());
            lodgingRepositoryMock.Setup(m => m.Remove(It.IsAny <Lodging>()));
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            lodgingLogic.RemoveLodging(lodging.Id);
        }
コード例 #9
0
        public void FailInUpdateLodgingWithAnyErrorFieldTest()
        {
            lodging.Address = "";
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(lodging);
            lodgingRepositoryMock.Setup(m => m.Update(It.IsAny <Lodging>()));
            LodgingManagement lodgingLogic   = new LodgingManagement(lodgingRepositoryMock.Object);
            Lodging           resultOfUpdate = lodgingLogic.UpdateLodging(lodging.Id, lodging);
        }
コード例 #10
0
        public void GetValidLodgingTestOk()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(lodging);
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            Lodging resultOfGetTheLodging = lodgingLogic.GetLodgingById(lodging.Id);

            Assert.AreEqual(lodging, resultOfGetTheLodging);
        }
コード例 #11
0
        public void FailInGetLodgingsWithReservesInternalErrorTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(l => l.GetLodgingsWithReserves(It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).Throws(new ServerException());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            DateTime       dateCheckIn  = new DateTime(2020, 05, 10);
            DateTime       dateCheckOut = new DateTime(2020, 06, 10);
            List <Lodging> resultOfGetLodgingsWithReserves = lodgingLogic.GetLodgingsWithReservesBetweenDates(touristSpotOfPuntaDelEste.Id, dateCheckIn, dateCheckOut);
        }
コード例 #12
0
        public void FailAboutGetAllLodgingsExceptionClientTest()
        {
            List <Lodging> lodgingsToReturn = new List <Lodging>()
            {
                lodging
            };
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.GetAll()).Throws(new ClientException());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);
            List <Lodging>    loadgingsObteinedOfGetAll = lodgingLogic.GetAllLoadings();
        }
コード例 #13
0
        public void UpdateValidLodgingTest()
        {
            lodging.Name = "San Ramon Hotel";
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(lodging);
            lodgingRepositoryMock.Setup(m => m.Update(It.IsAny <Lodging>()));
            LodgingManagement lodgingLogic   = new LodgingManagement(lodgingRepositoryMock.Object);
            Lodging           resultOfUpdate = lodgingLogic.UpdateLodging(lodging.Id, lodging);

            lodgingRepositoryMock.VerifyAll();
            Assert.IsTrue(resultOfUpdate.Name.Equals("San Ramon Hotel"));
        }
コード例 #14
0
        public void RemoveValidLodgingTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(lodging);
            lodgingRepositoryMock.Setup(m => m.Remove(It.IsAny <Lodging>()));
            lodgingRepositoryMock.Setup(m => m.GetAll()).Returns(new List <Lodging>());
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            lodgingLogic.RemoveLodging(lodging.Id);
            List <Lodging> listOfLodging = lodgingLogic.GetAllLoadings();

            lodgingRepositoryMock.VerifyAll();
            Assert.IsTrue(listOfLodging.Count == 0);
        }
コード例 #15
0
        public void CreateInvalidLodgingInternalErrorWhenSearchLodgingByNameTest()
        {
            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>()));
            lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Throws(new ServerException());

            var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);

            touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientBusinessLogicException());
            TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic);

            Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath);
        }
コード例 #16
0
        public void GetLodgingsByTouristSpotTest()
        {
            lodging.TouristSpot = touristSpot;
            List <Lodging> listOfLodgings = new List <Lodging>()
            {
                lodging, lodgingConrad
            };

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.GetAvailableLodgingsByTouristSpot(It.IsAny <Guid>())).Returns(listOfLodgings);
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            List <Lodging> resultOfSearchLodgingByTouristSpot = lodgingLogic.GetAvailableLodgingsByTouristSpot(touristSpot.Id);

            lodgingRepositoryMock.VerifyAll();
            Assert.AreEqual(lodging, resultOfSearchLodgingByTouristSpot[0]);
        }
コード例 #17
0
        public void CreateInvalidLodgingWithInvalidPriceTest()
        {
            lodging.PricePerNight = -10;

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>()));
            lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null);

            var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);

            touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot);
            TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object, touristSpotLogic);

            Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot.Id, listOfPicturesPath);
        }
コード例 #18
0
        public void CreateReviewInternalErrorWhenAddReviewFailedTest()
        {
            var reviewMock  = new Mock <IReviewRepository>(MockBehavior.Strict);
            var reserveMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);
            var lodgingMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            reviewMock.Setup(m => m.Add(It.IsAny <Review>())).Throws(new ServerException());
            reserveMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(reserve);
            reviewMock.Setup(m => m.GetReviewByReserveId(It.IsAny <Guid>())).Returns(value: null);
            reviewMock.Setup(m => m.GetAverageReviewScoreByLodging(It.IsAny <Guid>())).Returns(4.0);
            lodgingMock.Setup(m => m.Update(lodging));

            IReserveManagement reserveLogic = new ReserveManagement(reserveMock.Object);
            ILodgingManagement lodgingLogic = new LodgingManagement(lodgingMock.Object);


            ReviewManagement reviewLogic  = new ReviewManagement(reviewMock.Object, reserveLogic, lodgingLogic);
            Review           reviewResult = reviewLogic.Create(review, reserve.Id);
        }
コード例 #19
0
        public void CreateReviewThatAlredyExistForThisCodeReserveFailedTest()
        {
            var reviewMock  = new Mock <IReviewRepository>(MockBehavior.Strict);
            var reserveMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);
            var lodgingMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            reviewMock.Setup(m => m.Add(It.IsAny <Review>()));
            reserveMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(reserve);
            reviewMock.Setup(m => m.GetReviewByReserveId(It.IsAny <Guid>())).Returns(review);
            reviewMock.Setup(m => m.GetAverageReviewScoreByLodging(It.IsAny <Guid>())).Returns(4.0);
            lodgingMock.Setup(m => m.Update(lodging));

            IReserveManagement reserveLogic = new ReserveManagement(reserveMock.Object);
            ILodgingManagement lodgingLogic = new LodgingManagement(lodgingMock.Object);


            ReviewManagement reviewLogic  = new ReviewManagement(reviewMock.Object, reserveLogic, lodgingLogic);
            Review           reviewResult = reviewLogic.Create(review, reserve.Id);
        }
コード例 #20
0
        public void GetAllLodgingsTestOk()
        {
            List <Lodging> lodgingsToReturn = new List <Lodging>()
            {
                lodging
            };

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(m => m.GetAll()).Returns(lodgingsToReturn);

            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            List <Lodging> lodgingsObteinedOfGetAll = lodgingLogic.GetAllLoadings();

            lodgingRepositoryMock.VerifyAll();

            CollectionAssert.AreEqual(lodgingsToReturn, lodgingsObteinedOfGetAll);
        }
コード例 #21
0
        public void GetLodgingsWithReservesBetweenDatesTestOK()
        {
            lodging.TouristSpot = touristSpotOfPuntaDelEste;
            List <Lodging> listOfLodgings = new List <Lodging>()
            {
                lodging, lodgingConrad
            };

            var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            lodgingRepositoryMock.Setup(l => l.GetLodgingsWithReserves(It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(listOfLodgings);
            LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object);

            DateTime       dateCheckIn  = new DateTime(2020, 05, 10);
            DateTime       dateCheckOut = new DateTime(2020, 06, 10);
            List <Lodging> resultOfGetLodgingsWithReserves = lodgingLogic.GetLodgingsWithReservesBetweenDates(touristSpotOfPuntaDelEste.Id, dateCheckIn, dateCheckOut);

            lodgingRepositoryMock.VerifyAll();
            CollectionAssert.AreEqual(listOfLodgings, resultOfGetLodgingsWithReserves);
        }
コード例 #22
0
        public void CreateReviewWithNumberOfStarsGreaterThanFiveFailedTest()
        {
            review.Score = 7;

            var reviewMock  = new Mock <IReviewRepository>(MockBehavior.Strict);
            var reserveMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);
            var lodgingMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            reviewMock.Setup(m => m.Add(It.IsAny <Review>()));
            reserveMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(reserve);
            reviewMock.Setup(m => m.GetReviewByReserveId(It.IsAny <Guid>())).Returns(value: null);
            reviewMock.Setup(m => m.GetAverageReviewScoreByLodging(It.IsAny <Guid>())).Returns(4.0);
            lodgingMock.Setup(m => m.Update(lodging));

            IReserveManagement reserveLogic = new ReserveManagement(reserveMock.Object);
            ILodgingManagement lodgingLogic = new LodgingManagement(lodgingMock.Object);


            ReviewManagement reviewLogic  = new ReviewManagement(reviewMock.Object, reserveLogic, lodgingLogic);
            Review           reviewResult = reviewLogic.Create(review, reserve.Id);
        }
コード例 #23
0
        public void CreateReviewTestOk()
        {
            var reviewMock  = new Mock <IReviewRepository>(MockBehavior.Strict);
            var reserveMock = new Mock <IRepository <Reserve> >(MockBehavior.Strict);
            var lodgingMock = new Mock <ILodgingRepository>(MockBehavior.Strict);

            reviewMock.Setup(m => m.Add(It.IsAny <Review>()));
            reserveMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(reserve);
            reviewMock.Setup(m => m.GetReviewByReserveId(It.IsAny <Guid>())).Returns(value: null);
            reviewMock.Setup(m => m.GetAverageReviewScoreByLodging(It.IsAny <Guid>())).Returns(4.0);
            lodgingMock.Setup(m => m.Update(lodging));

            IReserveManagement reserveLogic = new ReserveManagement(reserveMock.Object);
            ILodgingManagement lodgingLogic = new LodgingManagement(lodgingMock.Object);


            ReviewManagement reviewLogic  = new ReviewManagement(reviewMock.Object, reserveLogic, lodgingLogic);
            Review           reviewResult = reviewLogic.Create(review, reserve.Id);

            reviewMock.VerifyAll();
            Assert.IsTrue(review.Equals(reviewResult));
        }