public void Describe_Bytes_Formats_Bytes_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            using(var switcher = new CultureSwitcher(worksheet.String("Region"))) {
                Assert.AreEqual(worksheet.String("Description"), Describe.Bytes(worksheet.Long("Bytes")));
            }
        }
 public void BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object_For_Different_Cultures()
 {
     foreach(var cultureName in new string[] { "en-GB", "fr-FR", "de-DE", "ru-RU" }) {
         using(var cultureSwitcher = new CultureSwitcher(cultureName)) {
             try {
                 Do_BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object();
             } catch(Exception ex) {
                 Assert.Fail("Failed to correctly translate a BaseStation message when culture was {0} - {1}", cultureName, ex.ToString());
             }
         }
     }
 }
        public void LogDatabase_UpdateClient_Updates_Existing_Client_Records_In_Different_Cultures()
        {
            foreach(var culture in _Cultures) {
                using(var switcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    try {
                        LogDatabase_UpdateClient_Updates_Existing_Client_Records();
                    } catch(Exception ex) {
                        throw new InvalidOperationException(String.Format("Exception thrown when culture was {0}", culture), ex);
                    }
                }
            }
        }
        public void BaseStationDatabase_UpdateAircraft_Works_For_Different_Cultures()
        {
            foreach(var culture in _Cultures) {
                using(var switcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    try {
                        BaseStationDatabase_UpdateAircraft_Correctly_Updates_Record();
                    } catch(Exception ex) {
                        throw new InvalidOperationException(String.Format("Exception thrown when culture was {0}", culture), ex);
                    }
                }
            }
        }
        public void BaseStationDatabase_CreateDatabaseIfMissing_Writes_Default_Location_In_Different_Cultures()
        {
            foreach(var culture in _Cultures) {
                using(var switcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    try {
                        BaseStationDatabase_CreateDatabaseIfMissing_Writes_Google_Map_Default_Centre_As_Default_Location();
                    } catch(Exception ex) {
                        throw new InvalidOperationException(String.Format("Exception thrown when culture was {0}", culture), ex);
                    }
                }
            }
        }
        public void BaseStationDatabase_CreateDatabaseIfMissing_Writes_Correct_History_Record_In_Different_Cultures()
        {
            foreach(var culture in _Cultures) {
                using(var switcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    try {
                        BaseStationDatabase_CreateDatabaseIfMissing_Writes_Correct_History_Record_If_Missing();
                    } catch(Exception ex) {
                        throw new InvalidOperationException(String.Format("Exception thrown when culture was {0}", culture), ex);
                    }
                }
            }
        }
        public void WebSite_BaseStationAircraftList_Calculates_Distances_From_Browser_To_Aircraft_Correctly_When_Culture_Is_Not_UK()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            using(var switcher = new CultureSwitcher("de-DE")) {
                var aircraft = new Mock<IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
                _BaseStationAircraft.Add(aircraft.Object);

                aircraft.Object.Latitude = worksheet.NFloat("AircraftLatitude");
                aircraft.Object.Longitude = worksheet.NFloat("AircraftLongitude");

                string address = String.Format("{0}?lat={1}&lng={2}", _AircraftListAddress.Page, worksheet.String("BrowserLatitude"), worksheet.String("BrowserLongitude"));

                var list = SendJsonRequest<AircraftListJson>(address);
                Assert.AreEqual(1, list.Aircraft.Count);
                var aircraftJson = list.Aircraft[0];

                double? expected = worksheet.NDouble("Distance");
                if(expected == null) Assert.IsNull(aircraftJson.DistanceFromHere);
                else Assert.AreEqual((double)expected, (double)aircraftJson.DistanceFromHere);
            }
        }
        public void WebSite_BaseStationAircraftList_Filters_Are_Culture_Agnostic()
        {
            var cultureNames = new string[] { 
                "en-GB",
                "en-US",
                "de-DE",
                "fr-FR",
                "nn-NO",
                "el-GR",
                "ru-RU",
                "zh-CHT",
            };

            _AircraftListAddress.BrowserLatitude = _AircraftListAddress.BrowserLongitude = 0;

            var currentCulture = Thread.CurrentThread.CurrentCulture;
            foreach(var cultureName in cultureNames) {
                string filterName = null;

                using(var switcher = new CultureSwitcher(cultureName)) {
                    foreach(var filterProperty in typeof(AircraftListFilter).GetProperties()) {
                        _BaseStationAircraft.Clear();
                        AddBlankAircraft(2);
                        var aircraft0 = _BaseStationAircraft[0];
                        var aircraft1 = _BaseStationAircraft[1];

                        _AircraftListFilter = new AircraftListFilter();
                        _AircraftListAddress.Filter = _AircraftListFilter;

                        filterName = filterProperty.Name;
                        var tailText = filterName.EndsWith("Upper") ? "Upper" :
                                       filterName.EndsWith("Lower") ? "Lower" :
                                       filterName.EndsWith("Within") ? "Within" :
                                       "";
                        if(tailText == "") continue;

                        string aircraftPropertyName = filterName.Substring(0, filterName.Length - tailText.Length);
                        switch(aircraftPropertyName) {
                            case "Altitude":
                                aircraft0.Altitude = -9; aircraft1.Altitude = 9;
                                filterProperty.SetValue(_AircraftListFilter, -5, null);
                                break;
                            case "Distance":
                                aircraft0.Latitude = aircraft0.Longitude = 1; aircraft1.Latitude = aircraft1.Longitude = 2;
                                filterProperty.SetValue(_AircraftListFilter, 200.25, null);
                                break;
                            case "Position":
                                aircraft0.Latitude = aircraft0.Longitude = -9.5f; aircraft1.Latitude = aircraft1.Longitude = 9.5f;
                                _AircraftListFilter.PositionWithin = new Pair<Coordinate>(new Coordinate(5.5f, -15.5f), new Coordinate(-15.5f, 5.5f));
                                break;
                            case "Squawk":
                                aircraft0.Squawk = -9; aircraft1.Squawk = 9;
                                filterProperty.SetValue(_AircraftListFilter, -5, null);
                                break;
                            default:
                                throw new NotImplementedException();
                        }

                        var list = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address).Aircraft;

                        var expectedAircraftId = tailText == "Upper" || tailText == "Within" ? 0 : 1;

                        Assert.AreEqual(1, list.Count, switcher.CultureName);
                        Assert.AreEqual(expectedAircraftId, list[0].UniqueId, switcher.CultureName);
                    }
                }
            }
        }
        public void PluginSettings_Read_Write_Works_In_Different_Regions()
        {
            using(var switcher = new CultureSwitcher("de-DE")) {
                _PluginSettings.Write(_Plugin, "int", 1234567890);
                Assert.AreEqual("1234567890", _PluginSettings.Values["x.int"]);
                Assert.AreEqual(1234567890, _PluginSettings.ReadInt(_Plugin, "int"));

                _PluginSettings.Write(_Plugin, "long", 1234567890987654321L);
                Assert.AreEqual("1234567890987654321", _PluginSettings.Values["x.long"]);
                Assert.AreEqual(1234567890987654321L, _PluginSettings.ReadLong(_Plugin, "long"));

                _PluginSettings.Write(_Plugin, "double", 1.2345);
                Assert.AreEqual("1.2345", _PluginSettings.Values["x.double"]);
                Assert.AreEqual(1.2345, _PluginSettings.ReadDouble(_Plugin, "double"));

                var dateTime = new DateTime(2010, 07, 31, 23, 22, 21, DateTimeKind.Local);
                _PluginSettings.Write(_Plugin, "dateTime", dateTime);
                Assert.AreEqual("2010-07-31 22:22:21Z", _PluginSettings.Values["x.dateTime"]);  // This assumes that the test is running under a timezone where 31/07/2010 is subject to daylight saving time
                var readBackDate = _PluginSettings.ReadDateTime(_Plugin, "dateTime");
                Assert.AreEqual(DateTimeKind.Local, readBackDate.Value.Kind);
                Assert.AreEqual(dateTime, readBackDate);
            }
        }
        public void Describe_RebroadcastSettingsCollection_Correctly_Describes_Collection()
        {
            foreach(var culture in new string[] { "en-GB", "fr-FR" })  {
                using(var cultureSwitcher = new CultureSwitcher(culture)) {
                    Assert.AreEqual(Strings.RebroadcastServersNoneConfigured, Describe.RebroadcastSettingsCollection(null));

                    var settings = new List<RebroadcastSettings>();
                    Assert.AreEqual(Strings.RebroadcastServersNoneConfigured, Describe.RebroadcastSettingsCollection(settings));

                    settings.Add(new RebroadcastSettings() { Enabled = false });
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeSingle, 0), Describe.RebroadcastSettingsCollection(settings));

                    settings[0].Enabled = true;
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeSingle, 1), Describe.RebroadcastSettingsCollection(settings));

                    settings.Add(new RebroadcastSettings() { Enabled = false });
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeMany, 2, 1), Describe.RebroadcastSettingsCollection(settings));

                    settings[1].Enabled = true;
                    Assert.AreEqual(String.Format(Strings.RebroadcastServersDescribeMany, 2, 2), Describe.RebroadcastSettingsCollection(settings));
                }
            }
        }
        private void Check_Selected_Location_Copied_To_Fields_And_Resets_Validation(Action raiseEvent)
        {
            foreach(var culture in new string[] { "en-GB", "en-US", "de-DE", "fr-FR", "ru-RU" }) {
                TestCleanup();
                TestInitialise();

                using(var cultureSwitcher = new CultureSwitcher(culture)) {
                    _Presenter.Initialise(_View.Object);
                    var selectedLocation = SetupSelectedLocation(new ReceiverLocation() { Name = "A", Latitude = 1.123, Longitude = -2.678 });
                    SetupExpectedValidationFields(new ValidationResult[] { });

                    raiseEvent();

                    Assert.AreEqual("A", _View.Object.Location);
                    Assert.AreEqual(1.123, double.Parse(_View.Object.Latitude));
                    Assert.AreEqual(-2.678, double.Parse(_View.Object.Longitude));

                    _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Once());
                }
            }
        }
        public void JsonSerialiser_WriteObject_Does_Not_Leave_Current_Culture_Set_To_Invariant()
        {
            using(var cultureSwitcher = new CultureSwitcher("de-DE")) {
                _JsonSerialiser.Initialise(typeof(SmallClass));
                _JsonSerialiser.WriteObject(_Stream, new SmallClass());

                Assert.AreEqual("de-DE", Thread.CurrentThread.CurrentCulture.Name);
                Assert.AreEqual("de-DE", Thread.CurrentThread.CurrentUICulture.Name);
            }
        }
        public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly_For_Non_UK_Cultures()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            foreach(var culture in new string[] { "en-US", "de-DE", "fr-FR", "ru-RU" }) {
                using(var cultureSwitcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    var obj = new ValueTypes() {
                        BoolValue = worksheet.Bool("BoolValue"),
                        UnusedBool = worksheet.Bool("UnusedBool"),
                        NullableBool = worksheet.NBool("NullableBool"),
                        Int = worksheet.Int("Int"),
                        NullableInt = worksheet.NInt("NullableInt"),
                        Long = worksheet.Long("Long"),
                        NullableLong = worksheet.NLong("NullableLong"),
                        Float = worksheet.Float("Float"),
                        NullableFloat = worksheet.NFloat("NullableFloat"),
                        Double = worksheet.Double("Double"),
                        NullableDouble = worksheet.NDouble("NullableDouble"),
                        DateTime = worksheet.DateTime("DateTime"),
                        NullableDateTime = worksheet.NDateTime("NullableDateTime"),
                    };

                    _JsonSerialiser.Initialise(typeof(ValueTypes));
                    _JsonSerialiser.WriteObject(_Stream, obj);

                    var message = String.Format("when culture is {0}", culture);
                    Assert.AreEqual(worksheet.EString("Json"), GetJson(), message);
                }
            }
        }
        private void Check_Selected_Server_Copied_To_Fields_And_Resets_Validation(Action raiseEvent)
        {
            foreach(var culture in new string[] { "en-GB", "en-US", "de-DE", "fr-FR", "ru-RU" }) {
                TestCleanup();
                TestInitialise();

                using(var cultureSwitcher = new CultureSwitcher(culture)) {
                    _Presenter.Initialise(_View.Object);
                    var selectedLocation = SetupSelectedRebroadcastSettings(new RebroadcastSettings() { Enabled = true, Format = RebroadcastFormat.Port30003, Name = "AW", Port = 8000 });
                    SetupExpectedValidationFields(new ValidationResult[] { });

                    raiseEvent();

                    Assert.AreEqual(true, _View.Object.ServerEnabled);
                    Assert.AreEqual(RebroadcastFormat.Port30003, _View.Object.ServerFormat);
                    Assert.AreEqual("AW", _View.Object.ServerName);
                    Assert.AreEqual(8000, _View.Object.ServerPort);

                    _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Once());
                }
            }
        }