// ReSharper disable InconsistentNaming public void DebugStateTreeViewItemViewModel_Constructor_IsExpanded_False() { //Setup var serverID = Guid.NewGuid(); const string ServerName = "Myserver"; var env = new Mock <IEnvironmentModel>(); env.Setup(e => e.ID).Returns(serverID); env.Setup(e => e.Name).Returns(ServerName); var env2 = new Mock <IEnvironmentModel>(); env2.Setup(e => e.ID).Returns(Guid.NewGuid()); var envRep = new Mock <IEnvironmentRepository>(); envRep.Setup(e => e.All()).Returns(() => new[] { env.Object, env2.Object }); var content = new DebugState { ServerID = serverID }; //Execute var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; //Assert Assert.IsFalse(vm.IsExpanded, "The debug state tree viewmodel should be collapsed if not explicitly expanded in constructor"); }
public void DebugStateTreeViewItemViewModel_Constructor_ContentWithItems_BindsInputsAndOutputs() { //------------Setup for test-------------------------- var envRep = CreateEnvironmentRepository(); var expected = new DebugState { DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = ActivityType.Step }; expected.Inputs.Add(new DebugItem(new[] { new DebugItemResult(), new DebugItemResult { GroupName = "group1", GroupIndex = 1 } })); expected.Outputs.Add(new DebugItem(new[] { new DebugItemResult(), new DebugItemResult { GroupName = "group1", GroupIndex = 1 } })); //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = expected }; //------------Assert Results------------------------- Assert.AreEqual(1, vm.Inputs.Count); Assert.AreEqual(1, vm.Outputs.Count); }
public void DebugStateTreeViewItemViewModel_Constructor_CanDetectRemoteServerName() { var serverID = Guid.NewGuid(); const string ServerName = "Myserver"; var env = new Mock <IEnvironmentModel>(); env.Setup(e => e.ID).Returns(serverID); env.Setup(e => e.Name).Returns(ServerName); var env2ID = Guid.NewGuid(); var env2 = new Mock <IEnvironmentModel>(); env2.Setup(e => e.ID).Returns(env2ID); env2.Setup(e => e.Name).Returns("Unknown Remote Server"); var envRep = new Mock <IEnvironmentRepository>(); envRep.Setup(e => e.All()).Returns(() => new[] { env.Object, env2.Object }); var content = new DebugState { ServerID = serverID, Server = env2ID.ToString() }; var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; Assert.AreEqual("Unknown Remote Server", vm.Content.Server); }
public void DebugStateTreeViewItemViewModel_Constructor_NullEnvironmentRepository_ExceptionThrown() { //------------Setup for test-------------------------- //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(null); //------------Assert Results------------------------- Assert.AreEqual(0, vm.Inputs.Count); Assert.AreEqual(0, vm.Outputs.Count); }
public void DebugStateTreeViewItemViewModel_Constructor_NullContent_NoExceptionThrown() { //------------Setup for test-------------------------- var envRep = new Mock <IEnvironmentRepository>(); envRep.Setup(r => r.All()).Returns(new List <IEnvironmentModel>()); //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object); //------------Assert Results------------------------- Assert.AreEqual(0, vm.Inputs.Count); Assert.AreEqual(0, vm.Outputs.Count); }
static void Verify_IsSelected_PublishesDebugSelectionChangedEventArgs(ActivityType activityType, ActivitySelectionType expectedSelectionType, int expectedCount, bool setIsSelected = false) { var expected = new DebugState { DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = activityType }; var events = new List <DebugSelectionChangedEventArgs>(); var selectionChangedEvents = EventPublishers.Studio.GetEvent <DebugSelectionChangedEventArgs>(); selectionChangedEvents.Subscribe(events.Add); var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = expected }; if (setIsSelected) { // clear constructor events events.Clear(); // events are only triggered when property changes to true vm.IsSelected = false; vm.SelectionType = expectedSelectionType; vm.IsSelected = true; } else { vm.IsSelected = false; vm.SelectionType = expectedSelectionType; } EventPublishers.Studio.RemoveEvent <DebugSelectionChangedEventArgs>(); Assert.AreEqual(expectedCount, events.Count); if (events.Count > 0) { var foundEvent = events.Find(args => args.SelectionType == expectedSelectionType); Assert.IsNotNull(foundEvent); Assert.AreSame(expected, foundEvent.DebugState); } }
public void DebugStateTreeViewItemViewModel_IsSelected_SetsSelectionTypeToSingle() { //------------Setup for test-------------------------- var content = new DebugState { DisplayName = "Error Test", ID = Guid.NewGuid(), ActivityType = ActivityType.Workflow }; var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content, SelectionType = ActivitySelectionType.Add, IsSelected = true }; //------------Execute Test--------------------------- //------------Assert Results------------------------- Assert.AreEqual(ActivitySelectionType.Single, vm.SelectionType); }
static void Verify_AppendError(bool contentHasError) { //------------Setup for test-------------------------- const string AppendError = "Appended text"; const string ContentError = "Content text"; var content = new DebugState { DisplayName = "Error Test", ID = Guid.NewGuid(), ActivityType = ActivityType.Workflow }; var expectedProps = new[] { "Content.ErrorMessage", "Content.HasError", "Content", "HasError" }; var actualProps = new List <string>(); var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; vm.PropertyChanged += (sender, args) => actualProps.Add(args.PropertyName); //------------Execute Test--------------------------- vm.Content.HasError = contentHasError; vm.Content.ErrorMessage = ContentError; vm.AppendError(AppendError); //------------Assert Results------------------------- if (contentHasError) { Assert.AreEqual(ContentError + AppendError, content.ErrorMessage); } else { Assert.AreEqual(AppendError, content.ErrorMessage); } Assert.IsTrue(content.HasError); Assert.IsTrue(vm.HasError != null && vm.HasError.Value); CollectionAssert.AreEqual(expectedProps, actualProps); }
// ReSharper disable InconsistentNaming public void DebugStateTreeViewItemViewModel_Constructor_IsExpanded_False() { //Setup var serverID = Guid.NewGuid(); const string ServerName = "Myserver"; var env = new Mock<IEnvironmentModel>(); env.Setup(e => e.ID).Returns(serverID); env.Setup(e => e.Name).Returns(ServerName); var env2 = new Mock<IEnvironmentModel>(); env2.Setup(e => e.ID).Returns(Guid.NewGuid()); var envRep = new Mock<IEnvironmentRepository>(); envRep.Setup(e => e.All()).Returns(() => new[] { env.Object, env2.Object }); var content = new DebugState { ServerID = serverID }; //Execute var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; //Assert Assert.IsFalse(vm.IsExpanded, "The debug state tree viewmodel should be collapsed if not explicitly expanded in constructor"); }
public void DebugStateTreeViewItemViewModel_Constructor_CanDetectRemoteServerName() { var serverID = Guid.NewGuid(); const string ServerName = "Myserver"; var env = new Mock<IEnvironmentModel>(); env.Setup(e => e.ID).Returns(serverID); env.Setup(e => e.Name).Returns(ServerName); var env2ID = Guid.NewGuid(); var env2 = new Mock<IEnvironmentModel>(); env2.Setup(e => e.ID).Returns(env2ID); env2.Setup(e => e.Name).Returns("Unknown Remote Server"); var envRep = new Mock<IEnvironmentRepository>(); envRep.Setup(e => e.All()).Returns(() => new[] { env.Object, env2.Object }); var content = new DebugState { ServerID = serverID, Server = env2ID.ToString() }; var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; Assert.AreEqual("Unknown Remote Server", vm.Content.Server); }
static void Verify_IsSelected_PublishesDebugSelectionChangedEventArgs(ActivityType activityType, ActivitySelectionType expectedSelectionType, int expectedCount, bool setIsSelected = false) { var expected = new DebugState { DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = activityType }; var events = new List<DebugSelectionChangedEventArgs>(); var selectionChangedEvents = EventPublishers.Studio.GetEvent<DebugSelectionChangedEventArgs>(); selectionChangedEvents.Subscribe(events.Add); var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = expected }; if(setIsSelected) { // clear constructor events events.Clear(); // events are only triggered when property changes to true vm.IsSelected = false; vm.SelectionType = expectedSelectionType; vm.IsSelected = true; } else { vm.IsSelected = false; vm.SelectionType = expectedSelectionType; } EventPublishers.Studio.RemoveEvent<DebugSelectionChangedEventArgs>(); Assert.AreEqual(expectedCount, events.Count); if(events.Count > 0) { var foundEvent = events.Find(args => args.SelectionType == expectedSelectionType); Assert.IsNotNull(foundEvent); Assert.AreSame(expected, foundEvent.DebugState); } }
static void Verify_AppendError(bool contentHasError) { //------------Setup for test-------------------------- const string AppendError = "Appended text"; const string ContentError = "Content text"; var content = new DebugState { DisplayName = "Error Test", ID = Guid.NewGuid(), ActivityType = ActivityType.Workflow }; var expectedProps = new[] { "Content.ErrorMessage", "Content.HasError", "Content", "HasError" }; var actualProps = new List<string>(); var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content }; vm.PropertyChanged += (sender, args) => actualProps.Add(args.PropertyName); //------------Execute Test--------------------------- vm.Content.HasError = contentHasError; vm.Content.ErrorMessage = ContentError; vm.AppendError(AppendError); //------------Assert Results------------------------- if(contentHasError) { Assert.AreEqual(ContentError + AppendError, content.ErrorMessage); } else { Assert.AreEqual(AppendError, content.ErrorMessage); } Assert.IsTrue(content.HasError); Assert.IsTrue(vm.HasError != null && vm.HasError.Value); CollectionAssert.AreEqual(expectedProps, actualProps); }
public void DebugStateTreeViewItemViewModel_IsSelected_SetsSelectionTypeToSingle() { //------------Setup for test-------------------------- var content = new DebugState { DisplayName = "Error Test", ID = Guid.NewGuid(), ActivityType = ActivityType.Workflow }; var envRep = CreateEnvironmentRepository(); var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content, SelectionType = ActivitySelectionType.Add, IsSelected = true }; //------------Execute Test--------------------------- //------------Assert Results------------------------- Assert.AreEqual(ActivitySelectionType.Single, vm.SelectionType); }
public void DebugStateTreeViewItemViewModel_Constructor_NullEnvironmentRepository_ExceptionThrown() { //------------Setup for test-------------------------- //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(null); //------------Assert Results------------------------- Assert.AreEqual(0, vm.Inputs.Count); Assert.AreEqual(0, vm.Outputs.Count); }
public void DebugStateTreeViewItemViewModel_Constructor_NullContent_NoExceptionThrown() { //------------Setup for test-------------------------- var envRep = new Mock<IEnvironmentRepository>(); envRep.Setup(r => r.All()).Returns(new List<IEnvironmentModel>()); //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object); //------------Assert Results------------------------- Assert.AreEqual(0, vm.Inputs.Count); Assert.AreEqual(0, vm.Outputs.Count); }
public void DebugStateTreeViewItemViewModel_Constructor_ContentWithItems_BindsInputsAndOutputs() { //------------Setup for test-------------------------- var envRep = CreateEnvironmentRepository(); var expected = new DebugState { DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = ActivityType.Step }; expected.Inputs.Add(new DebugItem(new[] { new DebugItemResult(), new DebugItemResult { GroupName = "group1", GroupIndex = 1 } })); expected.Outputs.Add(new DebugItem(new[] { new DebugItemResult(), new DebugItemResult { GroupName = "group1", GroupIndex = 1 } })); //------------Execute Test--------------------------- var vm = new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = expected }; //------------Assert Results------------------------- Assert.AreEqual(1, vm.Inputs.Count); Assert.AreEqual(1, vm.Outputs.Count); }