Example #1
0
        public async Task GetSpotDefaultCategoryAsync_HasCategories_ShouldReturnTheCategory()
        {
            // Arrange
            context.Add(expectedCategory);
            context.SaveChanges();

            //Act
            var actualCategory = await repository.GetSpotDefaultCategoryAsync();

            //Assert
            Assert.AreEqual(expectedCategory, actualCategory);
        }
Example #2
0
        public async Task <Spot> AddSpotAsync(Spot spotModel, Region regionModel)
        {
            if (spotModel == null)
            {
                throw new ArgumentException("Must provide a spot.");
            }
            if (regionModel == null)
            {
                throw new ArgumentException("Must provide a region.");
            }
            if (spotModel.RegionId != regionModel.Id)
            {
                throw new ArgumentException("The region for the spot is different from the current region.");
            }

            if (spotModel.CategorySpots == null)
            {
                var category = await repository.GetSpotDefaultCategoryAsync();

                var categorySpot = new CategorySpot();
                categorySpot.CategoryId = category.Id;
                spotModel.CategorySpots = new List <CategorySpot>();
                spotModel.CategorySpots.Add(categorySpot);
            }

            var spot = await repository.GetSpotByNameAsync(spotModel.Name);

            if (spot != null)
            {
                throw new DuplicateNameException("The spot already exists.");
            }

            spot = await repository.AddSpotAsync(spotModel);

            return(spot);
        }