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); }
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); }
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 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); }
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; }
/// <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 void OptionsPresenter_SaveClicked_Copies_RebroadcastSettings_From_Options_UI_To_Configuration_Before_Save() { _Configuration.RebroadcastSettings.Add(new RebroadcastSettings() { Enabled = true, Name = "Will be deleted", Format = RebroadcastFormat.Passthrough, Port = 100 }); _Presenter.Initialise(_View.Object); var line1 = new RebroadcastSettings() { Enabled = true, Name = "X1", Format = RebroadcastFormat.Passthrough, Port = 9000 }; var line2 = new RebroadcastSettings() { Enabled = false, Name = "Y1", Format = RebroadcastFormat.Port30003, Port = 9001 }; _View.Object.RebroadcastSettings.Clear(); _View.Object.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 }); _ConfigurationStorage.Setup(c => c.Save(_Configuration)).Callback(() => { Assert.AreEqual(2, _Configuration.RebroadcastSettings.Count); Assert.IsTrue(_Configuration.RebroadcastSettings.Contains(line1)); Assert.IsTrue(_Configuration.RebroadcastSettings.Contains(line2)); }); _View.Raise(v => v.SaveClicked += null, EventArgs.Empty); _ConfigurationStorage.Verify(c => c.Save(_Configuration), Times.Once()); }
public void OptionsPresenter_Initialise_Copies_RebroadcastSettings_From_Configuration_To_General_Options_UI() { var line1 = new RebroadcastSettings() { Enabled = true, Name = "A", Port = 12, Format = RebroadcastFormat.Passthrough }; var line2 = new RebroadcastSettings() { Enabled = true, Name = "B", Port = 17, Format = RebroadcastFormat.Port30003 }; _Configuration.RebroadcastSettings.AddRange(new RebroadcastSettings[] { line1, line2 }); _Presenter.Initialise(_View.Object); Assert.AreEqual(2, _View.Object.RebroadcastSettings.Count); Assert.IsTrue(_View.Object.RebroadcastSettings.Contains(line1)); Assert.IsTrue(_View.Object.RebroadcastSettings.Contains(line2)); }
private RebroadcastSettings SetupSelectedRebroadcastSettings() { var result = new RebroadcastSettings() { Enabled = true, Name = "Server", Port = 12001, Format = RebroadcastFormat.Port30003 }; return SetupSelectedRebroadcastSettings(result); }
private RebroadcastSettings SetupSelectedRebroadcastSettings(RebroadcastSettings settings) { _View.Setup(v => v.SelectedRebroadcastSettings).Returns(settings); return settings; }
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_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_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_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)); }
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); }