public void TestGetTouristSpotHas200StatusCode()
        {
            var touristSpot = TouristSpotModel.ToEntity();

            touristSpot.Region = new Region {
                Id = touristSpot.RegionId.Value
            };
            var touristSpotCategories = new TouristSpotCategory()
            {
                Category      = Category,
                CategoryId    = Category.Id,
                TouristSpot   = touristSpot,
                TouristSpotId = touristSpot.Id
            };

            touristSpot.TouristSpotCategories = new List <TouristSpotCategory>()
            {
                touristSpotCategories
            };

            var touristSpots = new List <TouristSpot> {
                touristSpot
            };

            var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict);

            touristSpotLogicMock.Setup(m => m.Search(TouristSpotSearchModel)).Returns(touristSpots);

            var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object);
            var result = touristSpotController.Get(TouristSpotSearchModel) as OkObjectResult;

            touristSpotLogicMock.VerifyAll();

            Assert.AreEqual(result.StatusCode, 200);
        }
        public void TestGetTouristSpotByIdReturnsValidModel()
        {
            var touristSpot = TouristSpotModel.ToEntity();

            touristSpot.Region = new Region {
                Id = touristSpot.RegionId.Value
            };
            var touristSpotCategories = new TouristSpotCategory()
            {
                Category      = Category,
                CategoryId    = Category.Id,
                TouristSpot   = touristSpot,
                TouristSpotId = touristSpot.Id
            };

            touristSpot.TouristSpotCategories = new List <TouristSpotCategory>()
            {
                touristSpotCategories
            };

            TouristSpotLogicMock.Setup(m => m.Get(touristSpot.Id)).Returns(touristSpot);

            var touristSpotController = new TouristSpotController(TouristSpotLogicMock.Object);
            var result  = touristSpotController.GetById(touristSpot.Id) as OkObjectResult;
            var content = result.Value as TouristSpotDetailedInfoModel;

            TouristSpotLogicMock.VerifyAll();
            Assert.AreEqual(content, new TouristSpotDetailedInfoModel(touristSpot));
        }
Exemplo n.º 3
0
        public void Add(Category category, TouristSpot touristSpot)
        {
            bool valid = true;
            IList <TouristSpotCategory> list = this.touristSpotCategories.ToList <TouristSpotCategory>();

            foreach (var item in list)
            {
                if (category.Id == item.CategoryId && touristSpot.Id == item.TouristSpotId)
                {
                    valid = false;
                }
            }
            if (valid)
            {
                TouristSpotCategory ts = new TouristSpotCategory
                {
                    Category      = category,
                    CategoryId    = category.Id,
                    TouristSpot   = touristSpot,
                    TouristSpotId = touristSpot.Id
                };
                this.touristSpotCategories.Add(ts);
                this.myContext.SaveChanges();
            }
        }
        public void TestGetTouristSpotReturnsValidModel()
        {
            var touristSpot = TouristSpotModel.ToEntity();

            touristSpot.Region = new Region {
                Id = touristSpot.RegionId.Value
            };
            var touristSpotCategories = new TouristSpotCategory()
            {
                Category      = Category,
                CategoryId    = Category.Id,
                TouristSpot   = touristSpot,
                TouristSpotId = touristSpot.Id
            };

            touristSpot.TouristSpotCategories = new List <TouristSpotCategory>()
            {
                touristSpotCategories
            };

            var touristSpots = new List <TouristSpot> {
                touristSpot
            };

            var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict);

            touristSpotLogicMock.Setup(m => m.Search(TouristSpotSearchModel)).Returns(touristSpots);

            var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object);
            var result  = touristSpotController.Get(TouristSpotSearchModel) as OkObjectResult;
            var content = result.Value as List <TouristSpotBasicInfoModel>;

            touristSpotLogicMock.VerifyAll();
            Assert.IsTrue(content.SequenceEqual(touristSpots.Select(x => new TouristSpotBasicInfoModel(x))));
        }
Exemplo n.º 5
0
        public void TestInitialize()
        {
            TouristSpotCategory = new TouristSpotCategory();

            var category = new Category()
            {
                Id   = 1,
                Name = "category 1"
            };

            Category = category;

            var region = new Region()
            {
                Id   = 1,
                Name = "region 1"
            };

            TouristSpot = new TouristSpot()
            {
                Id                    = 1,
                Name                  = "name",
                Description           = "description",
                Image                 = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                Region                = region,
                TouristSpotCategories = new List <TouristSpotCategory>()
            };

            TouristSpot.TouristSpotCategories.Add(TouristSpotCategory);
        }
 public void AddTouristSpotToCategory(string categoryName, int touristSpotId)
 {
     try
     {
         Category            category            = ValidateExistingCategory(categoryName);
         TouristSpot         touristSpot         = ValidateExistingTouristSpot(touristSpotId);
         TouristSpotCategory touristSpotCategory = new TouristSpotCategory
         {
             TouristSpot   = touristSpot,
             TouristSpotId = touristSpot.Id,
             Category      = category,
             CategoryId    = category.Id
         };
         this.categoryRepository.Add(category, touristSpotCategory);
         this.touristSpotRepository.Add(touristSpot, touristSpotCategory);
         this.touristSpotCategoryRepository.Add(category, touristSpot);
     }
     catch (ObjectNotFoundInDatabaseException)
     {
         throw new ObjectNotFoundInDatabaseException();
     }
     catch (RepeatedObjectException)
     {
         throw new RepeatedObjectException();
     }
 }
Exemplo n.º 7
0
        public void TestInitialize()
        {
            TouristSpotsMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict);
            RegionsMock      = new Mock <IRepository <Region> >(MockBehavior.Strict);
            CategoriesMock   = new Mock <IRepository <Category> >(MockBehavior.Strict);

            var category = new Category
            {
                Id   = 1,
                Name = "category 1"
            };

            var region = new Region
            {
                Id   = 1,
                Name = "region 1"
            };

            TouristSpot = new TouristSpot()
            {
                Id                    = 1,
                Name                  = "name",
                Description           = "description",
                Image                 = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                Region                = region,
                RegionId              = region.Id,
                TouristSpotCategories = new List <TouristSpotCategory>()
            };

            var touristSpotCategory = new TouristSpotCategory
            {
                CategoryId    = category.Id,
                Category      = category,
                TouristSpotId = TouristSpot.Id,
                TouristSpot   = TouristSpot
            };

            TouristSpot.TouristSpotCategories.Add(touristSpotCategory);
        }
        private static TouristSpot CreateTouristSpot(int id, Region region, Category category)
        {
            var touristSpot = new TouristSpot
            {
                Id                    = id,
                Name                  = "name",
                Description           = "description",
                Image                 = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                Region                = region,
                TouristSpotCategories = new List <TouristSpotCategory>()
            };

            var tsc = new TouristSpotCategory
            {
                CategoryId    = category.Id,
                Category      = category,
                TouristSpotId = touristSpot.Id,
                TouristSpot   = touristSpot
            };

            touristSpot.TouristSpotCategories.Add(tsc);

            return(touristSpot);
        }
 public void Add(Category category, TouristSpotCategory touristSpotCategory)
 {
     category.TouristSpotCategories.Add(touristSpotCategory);
     myContext.SaveChanges();
 }
Exemplo n.º 10
0
 public void Add(TouristSpot touristSpot, TouristSpotCategory touristSpotCategory)
 {
     touristSpot.TouristSpotCategories.Add(touristSpotCategory);
     myContext.SaveChanges();
 }
Exemplo n.º 11
0
 public void Add(TouristSpot touristSpot, TouristSpotCategory touristSpotCategory)
 {
     this.touristSpotRepository.Add(touristSpot, touristSpotCategory);
 }
Exemplo n.º 12
0
 public void Add(Category category, TouristSpotCategory touristSpotCategory)
 {
     this.categoryRepository.Add(category, touristSpotCategory);
 }