public void BeforeEach() { fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize <Spot>(c => c .Without(x => x.Region)); fixture.Customize <Lodgment>(c => c .Without(x => x.Spot) .Without(y => y.Bookings) .Without(y => y.Reviews)); fixture.Customize <CategorySpot>(c => c .Without(x => x.Category) .Without(x => x.Spot)); moqRepository = new Mock <ISpotsRepository>(MockBehavior.Strict); moqLodgmentsService = new Mock <ILodgmentsService>(MockBehavior.Strict); moqStorageService = new Mock <IStorageService>(MockBehavior.Strict); moqReportsService = new Mock <IReportsService>(MockBehavior.Strict); expectedSpot = fixture.Create <Spot>(); spot = fixture.Create <Spot>(); spotId = fixture.Create <int>(); existSpot = fixture.Create <Spot>(); existCategory = fixture.Create <Category>(); expectedCategorySpot = fixture.Create <CategorySpot>(); existRegion = fixture.Create <Region>(); region = fixture.Create <Region>(); expectedLodgment = fixture.Create <Lodgment>(); lodgment = fixture.Create <Lodgment>(); expectedLodgments = fixture.CreateMany <Lodgment>(); expectedSpots = fixture.CreateMany <Spot>(); lodgmentId = fixture.Create <int>(); paging = fixture.Create <PagingModel>(); lodgmentOptions = new LodgmentOptionsModel() { CheckIn = DateTime.Now.Ticks, CheckOut = DateTime.Now.Ticks + (TimeSpan.TicksPerDay * fixture.Create <int>()), AmountOfAdults = fixture.Create <byte>(), AmountOfUnderAge = fixture.Create <byte>(), AmountOfBabies = fixture.Create <byte>() }; expectedPaginatedLodgments = fixture.Create <PaginatedModel <Lodgment> >(); expectedPaginatedSpots = fixture.Create <PaginatedModel <Spot> >(); service = new SpotsService(moqRepository.Object, moqLodgmentsService.Object, moqStorageService.Object, moqReportsService.Object); paginatedSpots = fixture.Create <PaginatedModel <Spot> >(); }
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); }