Example #1
0
        public bool Validate(AdventureLocation item, IList<ValidationResult> validationErrorResults)
        {
            if (null == validationErrorResults)
                validationErrorResults = new List<ValidationResult>();

            bool spotIsValidated = base.Validate(item, validationErrorResults);

            if (null == item || null == item.Region )
            {
                validationErrorResults.Add(new ValidationResult("A Region is required", new[] { "Region" }));
            }

            return validationErrorResults.Count == 0;
        }
        public void OnGetSingleTest()
        {
            var locationRequest = new AdventureLocation { Id = "existingId" };

            IList<AdventureLocation> locationList = new List<AdventureLocation>();
            locationList.Add(locationRequest);

            var mock = new Mock<IAdventureLocationRepository>();
            mock.Setup(a => a.GetAdventureLocation(locationRequest.Id)).Returns(locationRequest);

            var target = new AdventureLocationService { AdventureLocationRepository = mock.Object };

            var expected = new AdventureLocationGetResponse(locationRequest);
            expected.AdventureLocations.Add(locationRequest);

            // check get single
            var actual = target.OnGet(locationRequest) as AdventureLocationGetResponse;
            Assert.AreEqual(expected, actual);
        }
        public void OnGetListTest()
        {
            var adventureLocation = new AdventureLocation { Id = "existingId" };
            var locationListRequest = new AdventureLocation();

            IList<AdventureLocation> locationList = new List<AdventureLocation>();
            locationList.Add(adventureLocation);

            var mock = new Mock<IAdventureLocationRepository>();
            mock.Setup(a => a.GetAdventureLocations()).Returns(locationList);

            var target = new AdventureLocationService { AdventureLocationRepository = mock.Object };

            var expectedList = new AdventureLocationGetResponse(locationListRequest)
            {
                AdventureLocations = locationList
            };

            // check get list
            var actual = target.OnGet(locationListRequest) as AdventureLocationGetResponse;
            Assert.AreEqual(expectedList, actual);
        }
Example #4
0
        public void ValidateTest()
        {
            var locationBusiness = new LocationBusiness();
            IList<ValidationResult> validationErrorResults = new List<ValidationResult>();
            const bool NotValid = false;
            const bool Valid = true;
            bool isValidActual;

            // check validation of null location... not valid.
            AdventureLocation nullLocation = null;

            isValidActual = locationBusiness.Validate(nullLocation, null);
            Assert.AreEqual(NotValid, isValidActual, "null is not valid, null result parameter");

            // check  validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(nullLocation, validationErrorResults);
            Assert.AreEqual(NotValid, isValidActual, "null is not valid");

            // check validation of default location constructor... not valid.
            AdventureLocation defaultLocation = new AdventureLocation();

            // check validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(defaultLocation, validationErrorResults);
            Assert.AreEqual(NotValid, isValidActual, "newly constructed empty class is not valid");

            // Check validation of a seemly normal location.
            AdventureLocation validGenericLocation = new AdventureLocation(new GeoPoint { Lat = 0.0, Lon = 0.0 }, "Location");
            validGenericLocation.Region.Id = "not empty";

            // check validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(validGenericLocation, validationErrorResults);
            Assert.AreEqual(Valid, isValidActual, "Valid generic location");

            locationBusiness.Dispose();
        }
        public void OnPostNewTest()
        {
            var geoPoint = new GeoPoint { Lat = 0, Lon = 0 };
            const string name = "Name";
            var newLocationRequest = new AdventureLocation(geoPoint, name);
            var newLocationResponse = new AdventureLocation(geoPoint, name) { Id = "newId" };
            var expectedNewResponse = new AdventureLocationSaveResponse(newLocationRequest) { AdventureLocation = newLocationResponse };

            var mock = new Mock<IAdventureLocationRepository>();
            mock.Setup(a => a.SaveAdventureLocation(newLocationRequest)).Returns(newLocationResponse);

            var target = new AdventureLocationService { AdventureLocationRepository = mock.Object };

            var actual = target.OnPost(newLocationRequest) as AdventureLocationSaveResponse;
            Assert.AreEqual(expectedNewResponse, actual);
        }
        public AdventureLocation SaveAdventureLocation(AdventureLocation model)
        {
            var response = new AdventureLocationSaveResponse(model);

            response.AdventureLocation = (string.IsNullOrEmpty(model.Id))
                       ? AdventureLocationRepository.Add(model)
                       : AdventureLocationRepository.Update(model);

            return response.AdventureLocation;
        }
        public AdventureLocation SaveAdventureLocation(AdventureLocation model)
        {
            var response = Client.Post<AdventureLocationSaveResponse>("/Adventure/Locations/" + model.Id, model);

            return response.AdventureLocation;
        }
 public AdventureLocationDeleteResponse(AdventureLocation request)
     : base(request)
 {
 }
        public void OnPostNewTest()
        {
            const string adventurename = "AdventureName";
            var adventureDate = DateTime.Now;
            var adventureDuration = new TimeSpan(0, 0, 1);

            var adventureType = new AdventureType { Id = "typeId", Name = "AdventureType" };

            var adventureLocation = new AdventureLocation(new GeoPoint { Lat = 0, Lon = 0 }, "AdventureLocation");

            var newReviewRequest = new AdventureReview
                                                   {
                                                       AdventureName = adventurename,
                                                       AdventureDate = adventureDate,
                                                       AdventureDuration = adventureDuration,
                                                       AdventureType = adventureType,
                                                       AdventureLocation = adventureLocation
                                                   };

            var newReviewRequestOutput = new AdventureReview
                                                         {
                                                             Id = "newId",
                                                             AdventureName = adventurename,
                                                             AdventureDate = adventureDate,
                                                             AdventureDuration = adventureDuration,
                                                             AdventureType = adventureType,
                                                             AdventureLocation = adventureLocation
                                                         };

            var expectedNewReviewResponse = new AdventureReviewSaveResponse(newReviewRequest)
                                                                        {
                                                                            AdventureReview = newReviewRequestOutput
                                                                        };

            var mock = new Mock<IAdventureReviewRepository>();
            mock.Setup(a => a.SaveAdventureReview(newReviewRequest)).Returns(expectedNewReviewResponse.AdventureReview);

            var target = new AdventureReviewService { AdventureReviewRepository = mock.Object };

            // new review
            var actual = target.OnPost(newReviewRequest) as AdventureReviewSaveResponse;
            Assert.AreEqual(expectedNewReviewResponse, actual);
        }