public void ValidationResult_Constructor_Initialises_To_Known_State()
        {
            var validationResult = new ValidationResult();

            TestUtilities.TestProperty(validationResult, "Field", ValidationField.None, ValidationField.EndDate);
            TestUtilities.TestProperty(validationResult, "Message", null, "This is a test");
            TestUtilities.TestProperty(validationResult, "IsWarning", false);

            var validationResult2 = new ValidationResult(ValidationField.EndDate, "Hello");
            Assert.AreEqual(ValidationField.EndDate, validationResult2.Field);
            Assert.AreEqual("Hello", validationResult2.Message);
            Assert.AreEqual(false, validationResult2.IsWarning);

            var validationResult3 = new ValidationResult(ValidationField.BaseStationAddress, "Message here", true);
            Assert.AreEqual(ValidationField.BaseStationAddress, validationResult3.Field);
            Assert.AreEqual("Message here", validationResult3.Message);
            Assert.IsTrue(validationResult.IsWarning);
        }
        private ISheet AddValidationMessage(ISheet selectSheet, StringBuilder messages, ValidationResult result)
        {
            if(messages.Length != 0) messages.Append("\r\n");
            messages.AppendFormat("{0}{1}", result.IsWarning ? Localise.GetLocalisedText("::Warning:::") : "", result.Message);

            if(selectSheet == null) {
                switch(result.Field) {
                    case ValidationField.BaseStationAddress:
                    case ValidationField.BaseStationPort:
                    case ValidationField.ComPort:
                    case ValidationField.BaudRate:
                    case ValidationField.DataBits:
                    case ValidationField.BaseStationDatabase:
                    case ValidationField.FlagsFolder:
                    case ValidationField.PicturesFolder:
                    case ValidationField.SilhouettesFolder:
                        selectSheet = _DataSourcesSheet;
                        break;
                    case ValidationField.Location:
                    case ValidationField.ReceiverRange:
                    case ValidationField.AcceptableAirborneLocalPositionSpeed:
                    case ValidationField.AcceptableSurfaceLocalPositionSpeed:
                    case ValidationField.AcceptableTransitionLocalPositionSpeed:
                    case ValidationField.AirborneGlobalPositionLimit:
                    case ValidationField.FastSurfaceGlobalPositionLimit:
                    case ValidationField.SlowSurfaceGlobalPositionLimit:
                    case ValidationField.AcceptIcaoInNonPICount:
                    case ValidationField.AcceptIcaoInNonPISeconds:
                    case ValidationField.AcceptIcaoInPI0Count:
                    case ValidationField.AcceptIcaoInPI0Seconds:
                        selectSheet = _RawFeedSheet;
                        break;
                    case ValidationField.WebUserName:
                    case ValidationField.UPnpPortNumber:
                    case ValidationField.InternetUserIdleTimeout:
                        selectSheet = _WebServerSheet;
                        break;
                    case ValidationField.InitialGoogleMapRefreshSeconds:
                    case ValidationField.MinimumGoogleMapRefreshSeconds:
                    case ValidationField.Latitude:
                    case ValidationField.Longitude:
                    case ValidationField.GoogleMapZoomLevel:
                        selectSheet = _WebSiteSheet;
                        break;
                    case ValidationField.CheckForNewVersions:
                    case ValidationField.DisplayTimeout:
                    case ValidationField.ShortTrailLength:
                    case ValidationField.TextToSpeechSpeed:
                    case ValidationField.TrackingTimeout:
                        selectSheet = _GeneralOptions;
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }

            return selectSheet;
        }
        private void ValidateFileSystemEntityExists(ValidationField field, string entityName, List<ValidationResult> results, bool isFile)
        {
            ValidationResult result = null;

            if(!String.IsNullOrEmpty(entityName)) {
                var cachedResult = _CachedFileSystemResults.Where(r => r.ValidationField == field).FirstOrDefault();
                if(cachedResult != null && entityName == cachedResult.FileSystemEntityName) result = cachedResult.ValidationResult;
                else {
                    if(cachedResult != null) _CachedFileSystemResults.Remove(cachedResult);
                    cachedResult = new CachedFileSystemResult() { ValidationField = field, FileSystemEntityName = entityName };

                    bool entityExists = isFile ? Provider.FileExists(entityName) : Provider.FolderExists(entityName);
                    if(!entityExists) cachedResult.ValidationResult = result = new ValidationResult(field, String.Format(Strings.SomethingDoesNotExist, entityName), true);

                    _CachedFileSystemResults.Add(cachedResult);
                }

                if(result != null) results.Add(result);
            }
        }
        private void CheckValidation_Displays_Validation_Message_When_Any_Field_Is_Empty(Action trigger)
        {
            for(var emptyFieldNumber = 0;emptyFieldNumber < 3;++emptyFieldNumber) {
                TestCleanup();
                TestInitialise();

                ValidationResult expectedValidationResult;
                switch(emptyFieldNumber) {
                    case 0:     expectedValidationResult = new ValidationResult(ValidationField.Location, Strings.PleaseEnterNameForLocation); break;
                    case 1:     expectedValidationResult = new ValidationResult(ValidationField.Latitude, Strings.LatitudeOutOfBounds); break;
                    case 2:     expectedValidationResult = new ValidationResult(ValidationField.Longitude, Strings.LongitudeOutOfBounds); break;
                    default:    throw new NotImplementedException();
                }

                _Presenter.Initialise(_View.Object);
                var selectedLocation = SetupSelectedLocation(new ReceiverLocation() { Name = "A", Latitude = 7, Longitude = 8 });
                SetupExpectedValidationFields(new ValidationResult[] { expectedValidationResult });

                _View.Object.Location = emptyFieldNumber == 0 ? "" : "ABC";
                _View.Object.Latitude = emptyFieldNumber == 1 ? "" : (1.0).ToString();
                _View.Object.Longitude = emptyFieldNumber == 2 ? "" : (2.0).ToString();

                trigger();

                _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Once());
                _View.Verify(v => v.RefreshSelectedLocation(), Times.Never());
                Assert.AreEqual("A", selectedLocation.Name);
                Assert.AreEqual(7.0, selectedLocation.Latitude);
                Assert.AreEqual(8.0, selectedLocation.Longitude);
            }
        }
        public void RebroadcastOptionsPresenter_ValueChanged_Displays_Validation_Message_When_Any_Field_Is_Empty()
        {
            for(var emptyFieldNumber = 0;emptyFieldNumber < 2;++emptyFieldNumber) {
                TestCleanup();
                TestInitialise();

                ValidationResult expectedValidationResult;
                switch(emptyFieldNumber) {
                    case 0:     expectedValidationResult = new ValidationResult(ValidationField.Name, Strings.NameRequired); break;
                    case 1:     expectedValidationResult = new ValidationResult(ValidationField.Format, Strings.RebroadcastFormatRequired); break;
                    default:    throw new NotImplementedException();
                }

                _Presenter.Initialise(_View.Object);
                var selectedServer = SetupSelectedRebroadcastSettings(new RebroadcastSettings() { Enabled = true, Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 100 });
                SetupExpectedValidationFields(new ValidationResult[] { expectedValidationResult });

                _View.Object.ServerName = emptyFieldNumber == 0 ? "" : "XYZ";
                _View.Object.ServerFormat = emptyFieldNumber == 1 ? RebroadcastFormat.None : RebroadcastFormat.Passthrough;

                _View.Raise(v => v.ValueChanged += null, EventArgs.Empty);

                _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Once());
                _View.Verify(v => v.RefreshSelectedServer(), Times.Never());
                Assert.AreEqual(true, selectedServer.Enabled);
                Assert.AreEqual("ABC", selectedServer.Name);
                Assert.AreEqual(RebroadcastFormat.Port30003, selectedServer.Format);
                Assert.AreEqual(100, selectedServer.Port);
            }
        }