예제 #1
0
        public async Task AddSpotAsync_SpotNotExists_ShouldReturnTheSpot()
        {
            // Arrange

            //Act
            var actualSpot = await repository.AddSpotAsync(expectedSpot);

            //Assert
            Assert.AreEqual(expectedSpot, actualSpot);
        }
예제 #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);
        }