Esempio n. 1
0
        public void ImportTestWithNonExistentCategory()
        {
            ImporterModel importerModel = new ImporterModel()
            {
                Name       = "Test",
                Parameters = new List <ValueParameter>()
                {
                    new ValueParameter()
                    {
                        Name  = "Path",
                        Value = "Path test"
                    }
                }
            };
            Region region = new Region()
            {
                Id   = 1,
                Name = "Region name"
            };
            var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict);
            var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict);
            var mockRegion        = new Mock <IRepository <Region> >(MockBehavior.Strict);

            mockRegion.Setup(p => p.GetById(It.IsAny <int>())).Returns(region);
            var mockCategory = new Mock <IRepository <Category> >(MockBehavior.Strict);

            mockCategory.Setup(p => p.GetById(It.IsAny <int>())).Returns <Category>(null);
            var logic = new ImporterLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockRegion.Object, mockCategory.Object);

            var result = logic.Import(importerModel);
        }
Esempio n. 2
0
        public void ImportTestWithAlreadyExistsAccommodation()
        {
            ImporterModel importerModel = new ImporterModel()
            {
                Name       = "Test",
                Parameters = new List <ValueParameter>()
                {
                    new ValueParameter()
                    {
                        Name  = "Path",
                        Value = "Path test"
                    }
                }
            };
            Region region = new Region()
            {
                Id   = 1,
                Name = "Region name"
            };
            Category category = new Category()
            {
                Id   = 1,
                Name = "Category name"
            };
            Accommodation accommodation = new Accommodation()
            {
                Name          = "Accommodation name",
                Address       = "Accommodation address",
                ContactNumber = "Accommodation contactNumber",
                Full          = false,
                Images        = new List <AccommodationImage>()
                {
                    new AccommodationImage()
                    {
                        Image = "AccommodationImage image"
                    }
                },
                Information   = "Accommodation information",
                PricePerNight = 1
            };
            var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict);

            mockAccommodation.Setup(p => p.GetByName(It.IsAny <string>())).Returns(accommodation);
            var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict);
            var mockRegion        = new Mock <IRepository <Region> >(MockBehavior.Strict);

            mockRegion.Setup(p => p.GetById(It.IsAny <int>())).Returns(region);
            var mockCategory = new Mock <IRepository <Category> >(MockBehavior.Strict);

            mockCategory.Setup(p => p.GetById(It.IsAny <int>())).Returns(category);
            var logic = new ImporterLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockRegion.Object, mockCategory.Object);

            var result = logic.Import(importerModel);
        }
Esempio n. 3
0
        public void ImportTestWithNewTouristicSpot()
        {
            ImporterModel importerModel = new ImporterModel()
            {
                Name       = "Test",
                Parameters = new List <ValueParameter>()
                {
                    new ValueParameter()
                    {
                        Name  = "Path",
                        Value = "Path test"
                    }
                }
            };
            Region region = new Region()
            {
                Id   = 1,
                Name = "Region name"
            };
            Category category = new Category()
            {
                Id   = 1,
                Name = "Category name"
            };
            TouristicSpot touristicSpot = new TouristicSpot()
            {
                Name        = "TouristicSpot name",
                Description = "TouristicSpot description",
                Image       = "TouristicSpot image",
                RegionId    = 1,
                Categories  = new List <CategoryTouristicSpot>()
                {
                    new CategoryTouristicSpot()
                    {
                        CategoryId = 1
                    }
                }
            };
            Accommodation accommodation = new Accommodation()
            {
                Name          = "Accommodation name",
                Address       = "Accommodation address",
                ContactNumber = "Accommodation contactNumber",
                Full          = false,
                Images        = new List <AccommodationImage>()
                {
                    new AccommodationImage()
                    {
                        Image = "AccommodationImage image"
                    }
                },
                Information   = "Accommodation information",
                PricePerNight = 1
            };
            AccommodationModelOut accommodationModelOut = new AccommodationModelOut(accommodation, (0, new List <Review>()));
            var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict);

            mockAccommodation.Setup(p => p.GetByName(It.IsAny <string>())).Returns <Accommodation>(null);
            mockAccommodation.Setup(p => p.AddAndSave(It.IsAny <Accommodation>())).Returns(accommodation);
            var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict);

            mockTouristicSpot.SetupSequence(p => p.GetByName(It.IsAny <string>())).Returns((TouristicSpot)null).Returns(touristicSpot);
            mockTouristicSpot.Setup(p => p.AddAndSave(It.IsAny <TouristicSpot>())).Returns(touristicSpot);
            var mockRegion = new Mock <IRepository <Region> >(MockBehavior.Strict);

            mockRegion.Setup(p => p.GetById(It.IsAny <int>())).Returns(region);
            var mockCategory = new Mock <IRepository <Category> >(MockBehavior.Strict);

            mockCategory.Setup(p => p.GetById(It.IsAny <int>())).Returns(category);
            var logic = new ImporterLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockRegion.Object, mockCategory.Object);

            var result = logic.Import(importerModel);

            mockAccommodation.VerifyAll();
            mockCategory.VerifyAll();
            mockTouristicSpot.VerifyAll();
            mockRegion.VerifyAll();
            Assert.AreEqual(accommodationModelOut, result);
        }