public void ThenAGeocacheWithEmptyNameShouldBeInvalid()
        {
            // Arrange
            cache = new Geocache { Name = string.Empty, Coordinate = new Coordinate(-90, 90) };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("Name", validationResults.First().MemberNames.First());
            Assert.AreEqual("The Name field is required.", validationResults.First().ErrorMessage);
        }
        public void ThenAGeocacheWithNameLongerThan50CharactersShouldBeInvalid()
        {
            // Arrange
            cache = new Geocache {
                Name = new string('a', 51),
                Coordinate = new Coordinate(-90, 90)
            };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("Name", validationResults.First().MemberNames.First());
            Assert.AreEqual("The field Name must be a string or array type with a maximum length of '50'.", validationResults.First().ErrorMessage);
        }
        public void ThenAGeocacheWithNameContainingNonAlphanumericOrWhiteSpaceCharactersShouldBeInvalid()
        {
            // Arrange
            cache = new Geocache
            {
                Name = "Geo-cache?",
                Coordinate = new Coordinate(-90, 90)
            };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("Name", validationResults.First().MemberNames.First());
            Assert.AreEqual("The field Name can only contain alphanumeric characters or spaces.", validationResults.First().ErrorMessage);
        }
        public void ThenAGeocacheWithLatitudeOutsideof0to90OShouldBeInvalid()
        {
            // Arrange
            cache = new Geocache
            {
                Name = "Name",
                Coordinate = new Coordinate(-91.0, 0.0)
            };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("Latitude", validationResults.First().MemberNames.First());
            Assert.AreEqual("The field Latitude must range from -90.0 to 90.0.", validationResults.First().ErrorMessage);
        }
        public void ThenAGeocacheWithValidNameAndValidCoordinatesIsValid()
        {
            // Arrange
            cache = new Geocache { Name = "Valid Geocache Name", Coordinate = new Coordinate(-44, 44) };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(0, validationResults.Count);
        }
        public void ThenAGeocacheWithNullCoordinatesShouldInvalid()
        {
            // Arrange
            cache = new Geocache
            {
                Name = "Name"
            };

            // Act
            validationResults = ValidateModel(cache);

            // Assert
            Assert.AreEqual(2, validationResults.Count);
            Assert.AreEqual("The field Longitude is required.", validationResults.Find(x => x.MemberNames.Contains("Longitude")).ErrorMessage);
            Assert.AreEqual("The field Latitude is required.", validationResults.Find(x => x.MemberNames.Contains("Latitude")).ErrorMessage);

        }
 public void Create(Geocache cache)
 {
     context.Geocaches.Add(cache);
     Save();
 }
 public override void Arrange()
 {
     base.Arrange();
     cache = new Geocache { Name = "Geocache 500", Coordinate = new Coordinate(-89.0, 112.0) };
 }
 public override void Arrange()
 {
     base.Arrange();
     cache = new Geocache { Name = string.Empty, Coordinate = new Coordinate(1000.0, -999) }; 
 }