コード例 #1
0
        public void CreateInvalidLodgingWithoutQuantityOfStarsTest()
        {
            lodging.QuantityOfStars = 0;

            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);

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

            Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot, listOfPicturesPath);
        }
コード例 #2
0
        public void CreateValidLodgingWithoutTouristSpotTest()
        {
            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>())).Throws(new ClientBusinessLogicException());
            touristSpotRepositoryMock.Setup(m => m.GetTouristSpotByName(It.IsAny <string>())).Returns(value: null);
            touristSpotRepositoryMock.Setup(m => m.Add(It.IsAny <TouristSpot>()));

            var regionMock = new Mock <IRepository <Region> >(MockBehavior.Strict);

            regionMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(region);
            RegionManagement regionLogic = new RegionManagement(regionMock.Object);

            var categoryMock = new Mock <ICategoryRepository>(MockBehavior.Strict);

            categoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(aCategory);
            CategoryManagement categoryLogic = new CategoryManagement(categoryMock.Object);

            TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object, regionLogic, categoryLogic);

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

            Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot, 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);
        }