public void OnGetSingleTest()
        {
            var getSingleRequest = new Region { Id = "existingId" };

            var singleRegion = new Region
                                   {
                                       Id = "existingId",
                                       Name = "SomeRegion",
                                       Point = new GeoPoint { Lat = 0, Lon = 0 }
                                   };

            var regionList = new List<Region> { singleRegion };

            var expectedSingleResponse = new AdventureRegionGetResponse(getSingleRequest) { AdventureRegions = regionList };

            var mock = new Mock<IAdventureRegionRepository>();

            mock.Setup(a => a.GetAdventureRegion(getSingleRequest.Id)).Returns(singleRegion);

            var target = new AdventureRegionService { AdventureRegionRepository = mock.Object };

            var actual = target.OnGet(getSingleRequest) as AdventureRegionGetResponse;
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedSingleResponse, actual);
        }
Example #2
0
 public AdventureLocation(Region region)
 {
     Point = region.Point;
     Address = region.Address;
     Name = region.Name;
     Picture = region.Picture;
     Region = region;
 }
Example #3
0
        public bool Validate(Region item, IList<ValidationResult> validationErrorResults)
        {
            if (null == validationErrorResults)
                validationErrorResults = new List<ValidationResult>();

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

            return validationErrorResults.Count == 0;
        }
 public Region SaveAdventureRegion(Region region)
 {
     return (string.IsNullOrEmpty(region.Id)) ?
         AdventureRegionRepository.Add((Region)region) :
     AdventureRegionRepository.Update((Region)region);
 }
Example #5
0
        public void ValidateTest()
        {
            var regionBusiness = new RegionBusiness();
            IList<ValidationResult> validationErrorResults = new List<ValidationResult>();
            const bool NotValid = false;
            const bool Valid = true;
            bool isValidActual;

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

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

            // check validation of default location constructor... not valid.
            Region defaultRegion = new Region();

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

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

            // check validation
            validationErrorResults.Clear();
            isValidActual = regionBusiness.Validate(validGenericRegion, validationErrorResults);
            Assert.AreEqual(Valid, isValidActual, "Valid generic location");
        }
        public void OnPostNewTest()
        {
            const string regionname = "regionName";
            var geoPoint = new GeoPoint { Lat = 0, Lon = 0 };

            var newRegionRequest = new Region
                                       {
                                           Name = regionname,
                                           Point = geoPoint
                                       };
            var newRegion = new Region
            {
                Id = "newId",
                Name = regionname,
                Point = geoPoint
            };

            var expectedNewRegionResponse = new AdventureRegionSaveResponse(newRegionRequest)
                                                {
                                                    AdventureRegion = newRegion
                                                };

            var mock = new Mock<IAdventureRegionRepository>();
            mock.Setup(a => a.SaveAdventureRegion(newRegionRequest)).Returns(newRegion);

            var target = new AdventureRegionService {AdventureRegionRepository = mock.Object};

            var actual = target.OnPost(newRegionRequest) as AdventureRegionSaveResponse;
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedNewRegionResponse, actual);
        }
Example #7
0
 public AdventureLocation(GeoPoint geoPoint, string name)
     : base(geoPoint, name)
 {
     Region = new Region(geoPoint, name);
 }
Example #8
0
 public AdventureLocation()
 {
     Region = new Region();
 }