public void RebroadcastOptionsPresenter_ValueChanged_Does_Nothing_If_No_Server_Is_Selected()
        {
            _Presenter.Initialise(_View.Object);

            var line1 = new RebroadcastSettings()
            {
                Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 10001, Enabled = true
            };
            var line2 = new RebroadcastSettings()
            {
                Name = "XYZ", Format = RebroadcastFormat.Port30003, Port = 10002, Enabled = true
            };

            _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 });
            SetupSelectedRebroadcastSettings(null);
            _View.Raise(v => v.SelectedServerChanged += null, EventArgs.Empty);

            _View.Object.ServerEnabled = false;
            _View.Object.ServerName    = "New";
            _View.Object.ServerFormat  = RebroadcastFormat.Passthrough;
            _View.Object.ServerPort    = 8080;

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

            _View.Verify(v => v.RefreshSelectedServer(), Times.Never());
        }
        public void RebroadcastOptionsPresenter_ValueChanged_Updates_Selected_Line_With_New_Enabled_Value()
        {
            foreach (var enabled in new bool[] { true, false })
            {
                TestCleanup();
                TestInitialise();

                _Presenter.Initialise(_View.Object);

                var line1 = new RebroadcastSettings()
                {
                    Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 10001, Enabled = true
                };
                var line2 = new RebroadcastSettings()
                {
                    Name = "XYZ", Format = RebroadcastFormat.Port30003, Port = 10002, Enabled = !enabled
                };
                _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 });
                SetupSelectedRebroadcastSettings(line2);
                _View.Raise(v => v.SelectedServerChanged += null, EventArgs.Empty);

                SetupExpectedValidationFields(new ValidationResult[] { });

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

                _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2));
                Assert.AreEqual(enabled, line2.Enabled);
                _View.Verify(v => v.RefreshSelectedServer(), Times.Once());
            }
        }
        public void RebroadcastOptionsPresenter_ValueChanged_Updates_Selected_Line_With_Port()
        {
            _Presenter.Initialise(_View.Object);

            var line1 = new RebroadcastSettings()
            {
                Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 10001, Enabled = true
            };
            var line2 = new RebroadcastSettings()
            {
                Name = "XYZ", Format = RebroadcastFormat.Port30003, Port = 10002, Enabled = true
            };

            _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 });
            SetupSelectedRebroadcastSettings(line2);
            _View.Raise(v => v.SelectedServerChanged += null, EventArgs.Empty);

            SetupExpectedValidationFields(new ValidationResult[] { });

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

            _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2));
            Assert.AreEqual(8080, line2.Port);
            _View.Verify(v => v.RefreshSelectedServer(), Times.Once());
        }
        public void RebroadcastOptionsPresenter_ValueChanged_Displays_Validation_Message_When_Port_Duplicates_Existing_Port()
        {
            _Presenter.Initialise(_View.Object);

            var line1 = new RebroadcastSettings()
            {
                Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 10001, Enabled = true
            };
            var line2 = new RebroadcastSettings()
            {
                Name = "XYZ", Format = RebroadcastFormat.Port30003, Port = 10002, Enabled = true
            };

            _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 });
            SetupSelectedRebroadcastSettings(line2);
            _View.Raise(v => v.SelectedServerChanged += null, EventArgs.Empty);

            SetupExpectedValidationFields(new ValidationResult[] { new ValidationResult(ValidationField.BaseStationPort, Strings.PortMustBeUnique) });

            _View.Object.ServerName          = "XYZ";
            _View.Object.ServerPort          = 10001;
            _View.Raise(v => v.ValueChanged += null, EventArgs.Empty);

            _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2));
            _View.Verify(v => v.RefreshSelectedServer(), Times.Never());
            Assert.AreEqual(10002, line2.Port);
        }
        public void RebroadcastOptionsPresenter_ValueChanged_Does_Not_Display_Validation_Message_When_Port_Duplicates_Own_Port()
        {
            _Presenter.Initialise(_View.Object);

            var line1 = new RebroadcastSettings()
            {
                Name = "ABC", Format = RebroadcastFormat.Port30003, Port = 10001, Enabled = true
            };
            var line2 = new RebroadcastSettings()
            {
                Name = "XYZ", Format = RebroadcastFormat.Port30003, Port = 10002, Enabled = true
            };

            _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 });
            SetupSelectedRebroadcastSettings(line2);
            _View.Raise(v => v.SelectedServerChanged += null, EventArgs.Empty);

            SetupExpectedValidationFields(new ValidationResult[] { });

            _View.Object.ServerName          = "XYZ";
            _View.Object.ServerPort          = 10002;
            _View.Raise(v => v.ValueChanged += null, EventArgs.Empty);

            _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2));
        }
Exemplo n.º 6
0
        public void TestInitialise()
        {
            _OriginalClassFactory = Factory.TakeSnapshot();

            // Note that the class factory will keep returning the SAME instance for all of the
            // interfaces for which CreateMockImplementation is called... this means we can't
            // comprehensively test the handling of multiple servers. Creating a wrapper using
            // Mock<> is kind of possible but gets tricky around events, and in any case it's
            // rather defeating the point of using a mocking framework.
            _Server            = TestUtilities.CreateMockImplementation <IRebroadcastServer>();
            _Listener          = TestUtilities.CreateMockImplementation <IListener>();
            _BroadcastProvider = TestUtilities.CreateMockImplementation <IBroadcastProvider>();

            _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>();
            _Configuration        = new Configuration();
            _ConfigurationStorage.Setup(r => r.Load()).Returns(_Configuration);
            _RebroadcastSettings = new RebroadcastSettings()
            {
                Name = "A", Enabled = true, Port = 1000, Format = RebroadcastFormat.Passthrough
            };
            _Configuration.RebroadcastSettings.Add(_RebroadcastSettings);

            _Manager          = Factory.Singleton.Resolve <IRebroadcastServerManager>();
            _Manager.Listener = _Listener.Object;
        }
        public void RebroadcastSettings_Clone_Returns_Deep_Copy_Of_Original()
        {
            var original = new RebroadcastSettings()
            {
                Enabled = true,
                Format  = RebroadcastFormat.Avr,
                Name    = "The name",
                Port    = 1234,
            };

            var copy = (RebroadcastSettings)original.Clone();

            Assert.AreNotSame(original, copy);

            foreach (var property in typeof(RebroadcastSettings).GetProperties())
            {
                switch (property.Name)
                {
                case "Enabled":     Assert.AreEqual(true, copy.Enabled); break;

                case "Format":      Assert.AreEqual(RebroadcastFormat.Avr, copy.Format); break;

                case "Name":        Assert.AreEqual("The name", copy.Name); break;

                case "Port":        Assert.AreEqual(1234, copy.Port); break;

                default:            throw new NotImplementedException();
                }
            }
        }
 public static void CheckProperties(RebroadcastSettings settings)
 {
     TestUtilities.TestProperty(settings, r => r.Enabled, false);
     TestUtilities.TestProperty(settings, r => r.Format, RebroadcastFormat.None, RebroadcastFormat.Passthrough);
     TestUtilities.TestProperty(settings, r => r.Name, null, "ABC");
     TestUtilities.TestProperty(settings, r => r.Port, 0, 19000);
 }
        /// <summary>
        /// Fills the servers list view.
        /// </summary>
        private void PopulateServers()
        {
            var currentSuppressState = _SuppressItemSelectedEventHandler;

            try {
                _SuppressItemSelectedEventHandler = true;
                var selected = SelectedRebroadcastSettings;

                listView.Items.Clear();
                foreach (var settings in RebroadcastSettings)
                {
                    var item = new ListViewItem()
                    {
                        Tag = settings
                    };
                    PopulateListViewItem(item);
                    listView.Items.Add(item);
                }

                if (RebroadcastSettings.Contains(selected))
                {
                    SelectedRebroadcastSettings = selected;
                }
            } finally {
                _SuppressItemSelectedEventHandler = currentSuppressState;
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Hooks child objects on a rebroadcast setting.
 /// </summary>
 /// <param name="record"></param>
 private void RebroadcastSetting_HookChild(RebroadcastSettings record)
 {
     if (!HaveHookedChildren(record))
     {
         record.Access.PropertyChanged += RebroadcastSetting_Access_PropertyChanged;
         RecordHookedChild(record, record.Access);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Unhooks child objects on a rebroadcast setting.
 /// </summary>
 /// <param name="record"></param>
 private void RebroadcastSetting_UnhookChild(RebroadcastSettings record)
 {
     foreach (var child in GetHookedChildren(record).OfType <Access>())
     {
         child.PropertyChanged -= RebroadcastSetting_Access_PropertyChanged;
         RecordUnhookedChild(record, child);
     }
 }
        private RebroadcastSettings SetupSelectedRebroadcastSettings()
        {
            var result = new RebroadcastSettings()
            {
                Enabled = true, Name = "Server", Port = 12001, Format = RebroadcastFormat.Port30003
            };

            return(SetupSelectedRebroadcastSettings(result));
        }
        public void RebroadcastOptionsPresenter_Initialise_Selects_First_RebroadcastSettings()
        {
            var rebroadcastSettings = new RebroadcastSettings();

            _View.Object.RebroadcastSettings.Add(rebroadcastSettings);

            _Presenter.Initialise(_View.Object);

            Assert.AreSame(_View.Object.SelectedRebroadcastSettings, rebroadcastSettings);
        }
Exemplo n.º 14
0
        public void ConfigurationListener_Does_Not_Raise_Events_After_RebroadcastSettings_Is_Detached()
        {
            var record = new RebroadcastSettings();

            _Configuration.RebroadcastSettings.Add(record);

            _Configuration.RebroadcastSettings.Remove(record);
            record.UniqueId += 1;

            Assert.IsFalse(RaisedEvent <RebroadcastSettings>(ConfigurationListenerGroup.RebroadcastSetting, r => r.UniqueId, record, isListChild: true));
            Assert.AreEqual(2, _PropertyChanged.CallCount);
        }
        /// <summary>
        /// Raised when the user asks for a new server to be created.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void View_NewServerClicked(object sender, EventArgs args)
        {
            var server = new RebroadcastSettings()
            {
                Enabled = true,
                Name    = SelectUniqueName("New Server"),
                Format  = RebroadcastFormat.Passthrough,
                Port    = SelectUniquePort(DefaultPort),
            };

            _View.RebroadcastSettings.Add(server);
            _View.RefreshServers();
            _View.SelectedRebroadcastSettings = server;

            CopySelectedServerToFields();
            _View.FocusOnEditFields();
        }
        public static void CheckProperties(RebroadcastSettings settings)
        {
            TestUtilities.TestProperty(settings, r => r.Enabled, false);
            TestUtilities.TestProperty(settings, r => r.Format, null, RebroadcastFormat.Passthrough);
            TestUtilities.TestProperty(settings, r => r.Name, null, "ABC");
            TestUtilities.TestProperty(settings, r => r.IsTransmitter, false);
            TestUtilities.TestProperty(settings, r => r.TransmitAddress, null, "www.word.up");
            TestUtilities.TestProperty(settings, r => r.UseKeepAlive, false);
            TestUtilities.TestProperty(settings, r => r.IdleTimeoutMilliseconds, 30000, 15000);
            TestUtilities.TestProperty(settings, r => r.Passphrase, null, "Ab");
            TestUtilities.TestProperty(settings, r => r.Port, 0, 19000);
            TestUtilities.TestProperty(settings, r => r.ReceiverId, 0, 1234);
            TestUtilities.TestProperty(settings, r => r.UniqueId, 0, 456);
            TestUtilities.TestProperty(settings, r => r.SendIntervalMilliseconds, 1000, 2000);
            TestUtilities.TestProperty(settings, r => r.StaleSeconds, 3, 15);

            Assert.IsNotNull(settings.Access);
        }
Exemplo n.º 17
0
        private void ConfigureAuthentication(RebroadcastSettings rebroadcastSettings, IRebroadcastServer server)
        {
            var existingAuthentication = server.Connector.Authentication as IPassphraseAuthentication;
            var passphrase             = rebroadcastSettings.Passphrase ?? "";

            if ((existingAuthentication == null && passphrase != "") ||
                (existingAuthentication != null && existingAuthentication.Passphrase != passphrase))
            {
                if (passphrase == "")
                {
                    server.Connector.Authentication = null;
                }
                else
                {
                    var authentication = Factory.Singleton.Resolve <IPassphraseAuthentication>();
                    authentication.Passphrase       = rebroadcastSettings.Passphrase;
                    server.Connector.Authentication = authentication;
                }
            }
        }
        public void TestInitialise()
        {
            _OriginalClassFactory = Factory.TakeSnapshot();

            _Server = TestUtilities.CreateMockImplementation <IRebroadcastServer>();

            _Connector = new MockConnector <INetworkConnector, INetworkConnection>();
            Factory.Singleton.RegisterInstance <INetworkConnector>(_Connector.Object);
            _Connector.Object.Authentication = null;

            _PassphraseAuthentication = TestUtilities.CreateMockImplementation <IPassphraseAuthentication>();

            _Feeds     = new List <Mock <IFeed> >();
            _Listeners = new List <Mock <IListener> >();
            var useVisibleFeeds = false;

            _FeedManager = FeedHelper.CreateMockFeedManager(_Feeds, _Listeners, useVisibleFeeds, 1, 2);

            _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>();
            _Configuration        = new Configuration();
            _ConfigurationStorage.Setup(r => r.Load()).Returns(_Configuration);
            _RebroadcastSettings = new RebroadcastSettings()
            {
                UniqueId     = 22,
                Name         = "A",
                Enabled      = true,
                Port         = 1000,
                Format       = RebroadcastFormat.Passthrough,
                ReceiverId   = 1,
                StaleSeconds = 3,
                Access       =
                {
                    DefaultAccess = DefaultAccess.Allow,
                },
                IsTransmitter            = false,
                SendIntervalMilliseconds = 1000,
            };
            _Configuration.RebroadcastSettings.Add(_RebroadcastSettings);

            _Manager = Factory.Singleton.Resolve <IRebroadcastServerManager>();
        }
        public void RebroadcastSettings_Equals_Returns_Correct_Value()
        {
            var item1 = new RebroadcastSettings();
            var item2 = new RebroadcastSettings();

            Assert.AreEqual(item1, item2);

            item2.Enabled = !item2.Enabled;
            Assert.AreNotEqual(item1, item2);

            item2        = new RebroadcastSettings();
            item2.Format = RebroadcastFormat.Port30003;
            Assert.AreNotEqual(item1, item2);

            item2      = new RebroadcastSettings();
            item2.Name = "Z";
            Assert.AreNotEqual(item1, item2);

            item2      = new RebroadcastSettings();
            item2.Port = 1001;
            Assert.AreNotEqual(item1, item2);
        }
 private RebroadcastSettings SetupSelectedRebroadcastSettings(RebroadcastSettings settings)
 {
     _View.Setup(v => v.SelectedRebroadcastSettings).Returns(settings);
     return(settings);
 }