Inheritance: IDebugState, INotifyPropertyChanged
        public void Filter_Where_ContentIsDebugState_And_FilterTextMatchesNothing_Expected_False()
        {
            DebugState debugState = new DebugState();

            bool actual = _debugOutputFilterStrategy.Filter(debugState, "cake");

            Assert.AreEqual(false, actual);
        }
        // ReSharper disable InconsistentNaming - Unit Test
        public void Constructor_Expected_InitializesInputsAndOutputsAsEmptyLists()
        // ReSharper restore InconsistentNaming
        {
            var debugState = new DebugState();

            Assert.IsNotNull(debugState.Inputs);
            Assert.IsNotNull(debugState.Outputs);

            Assert.AreEqual(0, debugState.Inputs.Count);
            Assert.AreEqual(0, debugState.Outputs.Count);
        }
        public void ReadXml(XmlReader reader)
        {
            DebugStates = new List<DebugState>();
            reader.MoveToContent();
            reader.ReadStartElement();

            while(reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugState")
            {
                var item = new DebugState();
                item.ReadXml(reader);
                DebugStates.Add(item);
            }


            reader.ReadEndElement();
        }
        public static IDebugState Create(string message, IContextualResourceModel resourceModel)
        {
            var state = new DebugState
                {
                    Message = message,
                };

            if(resourceModel != null)
            {
                state.ServerID = resourceModel.ServerID;
                state.OriginatingResourceID = resourceModel.ID;
            }
            state.StateType = String.IsNullOrWhiteSpace(message) ? StateType.Clear : StateType.Message;

            return state;
        }
        // ReSharper disable InconsistentNaming - Unit Test
        public void Write_With_ByteWriterBase_Expected_InvokesByteWriterBase()
        // ReSharper restore InconsistentNaming
        {
            var debugState = new DebugState();

            var writer = new Mock<IByteWriterBase>();
            writer.Setup(w => w.Write(It.IsAny<int>())).Verifiable();
            writer.Setup(w => w.Write(It.IsAny<string>())).Verifiable();
            writer.Setup(w => w.Write(It.IsAny<bool>())).Verifiable();
            writer.Setup(w => w.Write(It.IsAny<Guid>())).Verifiable();
            writer.Setup(w => w.Write(It.IsAny<DateTime>())).Verifiable();

            debugState.Write(writer.Object);

            writer.Verify(w => w.Write(It.IsAny<int>()));
            writer.Verify(w => w.Write(It.IsAny<string>()));
            writer.Verify(w => w.Write(It.IsAny<bool>()));
            writer.Verify(w => w.Write(It.IsAny<Guid>()));
            writer.Verify(w => w.Write(It.IsAny<DateTime>()));
        }
        public void DebugStateTreeViewItemViewModel_Constructor_EnvironmentRepository_SetsDebugStateServer()
        {
            var environmentID = Guid.NewGuid();
            const string ServerName = "Myserver";

            var env = new Mock<IEnvironmentModel>();
            env.Setup(e => e.ID).Returns(environmentID);
            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 { EnvironmentID = environmentID };
            // ReSharper disable ObjectCreationAsStatement
            new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content };
            // ReSharper restore ObjectCreationAsStatement
            Assert.AreEqual(ServerName, content.Server);
        }
        // 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 Filter_Where_ContentIsDebugState_And_FilterTextMatchesDisplayName_Expected_True()
        {
            DebugState debugState = new DebugState { DisplayName = "Cake" };

            bool actual = _debugOutputFilterStrategy.Filter(debugState, "ak");

            Assert.AreEqual(true, actual);
        }
        public void Filter_Where_ContentIsDebugState_And_FilterTextMatchesActivityType_Expected_True()
        {
            DebugState debugState = new DebugState { ActivityType = ActivityType.Workflow };

            bool actual = _debugOutputFilterStrategy.Filter(debugState, "work");

            Assert.AreEqual(true, actual);
        }
        static void DebugOutputViewModel_Append_SearchText(string searchText, string contentText, bool isAdded)
        {
            //------------Setup for test--------------------------
            var envRepo = GetEnvironmentRepository();
            var filterStrat = new Mock<IDebugOutputFilterStrategy>();
            filterStrat.Setup(e => e.Filter(It.IsAny<Object>(), It.IsAny<String>())).Returns(searchText == contentText);
            var viewModel = new DebugOutputViewModel(new Mock<IEventPublisher>().Object, envRepo, filterStrat.Object) { SearchText = searchText };

            var content = new DebugState { DisplayName = contentText, ID = Guid.NewGuid(), StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };

            //------------Execute Test---------------------------
            viewModel.Append(content);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, viewModel.ContentItemCount);
            Assert.AreEqual(isAdded ? 1 : 0, viewModel.RootItems.Count);
        }
        public void Filter_Where_ContentIsDebugState_And_FilterTextMatchesOuputOnValue_Expected_True()
        {
            var debugState = new DebugState();
            DebugItem itemToAdd = new DebugItem();
            itemToAdd.Add(new DebugItemResult { Type = DebugItemResultType.Variable, Value = "cake" });
            debugState.Outputs.Add(itemToAdd);

            const bool Expected = true;
            var actual = _debugOutputFilterStrategy.Filter(debugState, "ak");

            Assert.AreEqual(Expected, actual);
        }
        public void Filter_Where_ContentIsDebugState_And_ActivityTypeIsWorkflow_And_FilterTextMatchesEndTime_Expected_True()
        {
            DebugState debugState = new DebugState { ActivityType = ActivityType.Workflow, StateType = StateType.After, EndTime = new DateTime(2012, 01, 02, 2, 2, 3) };

            bool actual = _debugOutputFilterStrategy.Filter(debugState, "2012");

            Assert.AreEqual(true, actual);
        }
        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);
        }
        static void DebugOutputViewModel_Append_ContentStateType(StateType stateType, Type expectedType, bool isExpanded)
        {
            //------------Setup for test--------------------------
            var envRepo = GetEnvironmentRepository();
            var viewModel = new DebugOutputViewModel(new Mock<IEventPublisher>().Object, envRepo, new Mock<IDebugOutputFilterStrategy>().Object);

            var content = new DebugState { DisplayName = "Content", ID = Guid.NewGuid(), StateType = stateType, ActivityType = ActivityType.Step, Message = "The message", SessionID = viewModel.SessionID };

            //------------Execute Test---------------------------
            viewModel.Append(content);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, viewModel.ContentItemCount);
            Assert.AreEqual(1, viewModel.RootItems.Count);
            Assert.AreEqual(viewModel.RootItems[0].IsExpanded, isExpanded);
            Assert.IsInstanceOfType(viewModel.RootItems[0], expectedType);

            if(expectedType == typeof(DebugStringTreeViewItemViewModel))
            {
                Assert.AreEqual(0, viewModel.RootItems[0].Depth);
                var viewContent = ((DebugStringTreeViewItemViewModel)viewModel.RootItems[0]).Content;
                Assert.AreEqual(content.Message, viewContent);
            }
            else
            {
                Assert.IsTrue(viewModel.RootItems[0].Depth >= 0);
                var viewContent = ((DebugStateTreeViewItemViewModel)viewModel.RootItems[0]).Content;
                Assert.AreSame(content, viewContent);
            }
        }
 private static void CreateDebugState(string result, string workflowName, string taskName)
 {
     string user = Thread.CurrentPrincipal.Identity.Name.Replace("\\", "-");
     var state = new DebugState
         {
             HasError = true,
             ID = Guid.NewGuid(),
             Message = string.Format("{0}", result),
             StartTime = DateTime.Now,
             EndTime = DateTime.Now,
             ErrorMessage = string.Format("{0}", result),
             DisplayName = workflowName
         };
     var debug = new DebugItem();
     debug.Add(new DebugItemResult
     {
         Type = DebugItemResultType.Label,
         Value = "Warewolf Execution Error:",
         Label = "Scheduler Execution Error",
         Variable = result
     });
     var js = new Dev2JsonSerializer();
     Thread.Sleep(5000);
     string correlation = GetCorrelationId(WarewolfTaskSchedulerPath + taskName);
     if (!Directory.Exists(OutputPath))
         Directory.CreateDirectory(OutputPath);
     File.WriteAllText(
         string.Format("{0}DebugItems_{1}_{2}_{3}_{4}.txt", OutputPath, workflowName.Replace("\\","_"),
                       DateTime.Now.ToString("yyyy-MM-dd"), correlation, user),
         js.SerializeToBuilder(new List<DebugState> { state }).ToString());
 }
        public void DispatchDebugState(IDSFDataObject dataObject, StateType stateType, bool hasErrors, string existingErrors, out ErrorResultTO errors, DateTime? workflowStartTime = null, bool interrogateInputs = false, bool interrogateOutputs = false)
        {
            errors = new ErrorResultTO();
            if(dataObject != null)
            {
                Guid parentInstanceId;
                Guid.TryParse(dataObject.ParentInstanceID, out parentInstanceId);
                IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
                bool hasError = dataObject.Environment.HasErrors();
                var errorMessage = String.Empty;
                if(hasError)
                {
                    errorMessage = dataObject.Environment.FetchErrors();
                }
                if(String.IsNullOrEmpty(existingErrors))
                {
                    existingErrors = errorMessage;
                }
                else
                {
                    existingErrors += Environment.NewLine + errorMessage;
                }
                var debugState = new DebugState
                {
                    ID = dataObject.OriginalInstanceID,
                    ParentID = parentInstanceId,
                    WorkspaceID = dataObject.WorkspaceID,
                    StateType = stateType,
                    StartTime = workflowStartTime ?? DateTime.Now,
                    EndTime = DateTime.Now,
                    ActivityType = ActivityType.Workflow,
                    DisplayName = dataObject.ServiceName,
                    IsSimulation = dataObject.IsOnDemandSimulation,
                    ServerID = dataObject.ServerID,
                    OriginatingResourceID = dataObject.ResourceID,
                    OriginalInstanceID = dataObject.OriginalInstanceID,
                    Server = string.Empty,
                    Version = string.Empty,
                    SessionID = dataObject.DebugSessionID,
                    EnvironmentID = dataObject.EnvironmentID,
                    ClientID = dataObject.ClientID,
                    Name = stateType.ToString(),
                    HasError = hasErrors || hasError,
                    ErrorMessage = existingErrors
                };

                if(interrogateInputs)
                {
                    ErrorResultTO invokeErrors;
                    var defs = compiler.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Input);
                    var inputs = GetDebugValues(defs, dataObject, out invokeErrors);
                    errors.MergeErrors(invokeErrors);
                    debugState.Inputs.AddRange(inputs);
                }
                if(interrogateOutputs)
                {
                    ErrorResultTO invokeErrors;
                    
                    var defs = compiler.GenerateDefsFromDataListForDebug(FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID), enDev2ColumnArgumentDirection.Output);
                    var inputs = GetDebugValues(defs, dataObject, out invokeErrors);
                    errors.MergeErrors(invokeErrors);
                    debugState.Outputs.AddRange(inputs);
                }
                if(stateType == StateType.End)
                {
                    debugState.NumberOfSteps = dataObject.NumberOfSteps;
                }

                if(stateType == StateType.Start)
                {
                    debugState.ExecutionOrigin = dataObject.ExecutionOrigin;
                    debugState.ExecutionOriginDescription = dataObject.ExecutionOriginDescription;
                }

                if(dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer))
                {
                    var debugDispatcher = GetDebugDispatcher();
                    if(debugState.StateType == StateType.End)
                    {
                        while(!debugDispatcher.IsQueueEmpty)
                        {
                            Thread.Sleep(100);
                        }
                        debugDispatcher.Write(debugState, dataObject.RemoteInvoke, dataObject.RemoteInvokerID, dataObject.ParentInstanceID, dataObject.RemoteDebugItems);
                    }
                    else
                    {
                        debugDispatcher.Write(debugState);
                    }
                }
            }
        }
        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_Constructor_AssignsNameToContentServer(StateType stateType, bool contentServerIsSource = false)
        {
            //------------Setup for test--------------------------
            var environmentID = Guid.NewGuid();
            const string serverName = "TestEnvironment";

            var env = new Mock<IEnvironmentModel>();
            env.Setup(e => e.ID).Returns(environmentID);
            env.Setup(e => e.Name).Returns(serverName);

            var envRep = CreateEnvironmentRepository(env.Object);

            var content = new DebugState { Server = (!contentServerIsSource ? Guid.Empty : Guid.NewGuid()).ToString(), EnvironmentID = environmentID, StateType = stateType, DisplayName = "IsSelectedTest", ID = Guid.NewGuid(), ActivityType = ActivityType.Workflow };
            content.OriginalInstanceID = content.ID;

            //------------Execute Test---------------------------
            // ReSharper disable ObjectCreationAsStatement
            new DebugStateTreeViewItemViewModelMock(envRep.Object) { Content = content };
            // ReSharper restore ObjectCreationAsStatement

            //------------Assert Results-------------------------
            Assert.AreEqual(serverName, content.Server);
        }
        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);
        }
Beispiel #22
0
        // BUG 9706 - 2013.06.22 - TWR : refactored
        void DispatchDebugErrors(ErrorResultTO errors, IDSFDataObject dataObject, StateType stateType)
        {
            if(errors.HasErrors() && dataObject.IsDebugMode())
            {
                Guid parentInstanceId;
                Guid.TryParse(dataObject.ParentInstanceID, out parentInstanceId);

                var debugState = new DebugState
                {
                    ID = dataObject.DataListID,
                    ParentID = parentInstanceId,
                    WorkspaceID = dataObject.WorkspaceID,
                    StateType = stateType,
                    StartTime = DateTime.Now,
                    EndTime = DateTime.Now,
                    ActivityType = ActivityType.Workflow,
                    DisplayName = dataObject.ServiceName,
                    IsSimulation = dataObject.IsOnDemandSimulation,
                    ServerID = dataObject.ServerID,
                    OriginatingResourceID = dataObject.ResourceID,
                    OriginalInstanceID = dataObject.OriginalInstanceID,
                    SessionID = dataObject.DebugSessionID,
                    EnvironmentID = dataObject.EnvironmentID,
                    ClientID = dataObject.ClientID,
                    Server = string.Empty,
                    Version = string.Empty,
                    Name = GetType().Name,
                    HasError = errors.HasErrors(),
                    ErrorMessage = errors.MakeDisplayReady()
                };

                DebugDispatcher.Instance.Write(debugState, dataObject.RemoteInvoke, dataObject.RemoteInvokerID);
            }
        }
 static DebugState DebugStateIn()
 {
     var debugStateIn = new DebugState
     {
         WorkspaceID = Guid.NewGuid(),
         ID = Guid.NewGuid(),
         ParentID = Guid.NewGuid(),
         StateType = StateType.Before,
         DisplayName = "DisplayName",
         Name = "Name",
         ActivityType = ActivityType.Step,
         Version = "Version",
         IsSimulation = false,
         HasError = false,
         ErrorMessage = "ErrorMessage",
         Server = "Server",
         ServerID = Guid.NewGuid(),
         StartTime = DateTime.Now,
         EndTime = DateTime.Now.AddMinutes(3),
         SessionID = Guid.NewGuid()
     };
     return debugStateIn;
 }
        // ReSharper disable InconsistentNaming - Unit Test
        public void Serialized_Expected_CanBeDeserialized()
        // ReSharper restore InconsistentNaming
        {
            var rw = new MockByteReaderWriter();

            var debugStateIn = DebugStateIn();

            DebugItem itemToAdd = new DebugItem();
            itemToAdd.Add(new DebugItemResult { GroupIndex = 0, GroupName = "Group1", Type = DebugItemResultType.Label, Value = "MyLabel" });
            itemToAdd.Add(new DebugItemResult { GroupIndex = 0, GroupName = "Group1", Type = DebugItemResultType.Variable, Value = "[[MyVar]]" });
            itemToAdd.Add(new DebugItemResult { GroupIndex = 0, GroupName = "Group1", Type = DebugItemResultType.Value, Value = "MyValue" });
            debugStateIn.Inputs.Add(itemToAdd);

            debugStateIn.Write(rw);
            var debugStateOut = new DebugState(rw);

            Assert.AreEqual(debugStateIn.WorkspaceID, debugStateOut.WorkspaceID);
            Assert.AreEqual(debugStateIn.ID, debugStateOut.ID);
            Assert.AreEqual(debugStateIn.ParentID, debugStateOut.ParentID);
            Assert.AreEqual(debugStateIn.StateType, debugStateOut.StateType);
            Assert.AreEqual(debugStateIn.DisplayName, debugStateOut.DisplayName);
            Assert.AreEqual(debugStateIn.Name, debugStateOut.Name);
            Assert.AreEqual(debugStateIn.ActivityType, debugStateOut.ActivityType);
            Assert.AreEqual(debugStateIn.Version, debugStateOut.Version);
            Assert.AreEqual(debugStateIn.IsSimulation, debugStateOut.IsSimulation);
            Assert.AreEqual(debugStateIn.HasError, debugStateOut.HasError);
            Assert.AreEqual(debugStateIn.ErrorMessage, debugStateOut.ErrorMessage);
            Assert.AreEqual(debugStateIn.Server, debugStateOut.Server);
            Assert.AreEqual(debugStateIn.Server, debugStateOut.Server);
            Assert.AreEqual(debugStateIn.ServerID, debugStateOut.ServerID);
            Assert.AreEqual(debugStateIn.StartTime, debugStateOut.StartTime);
            Assert.AreEqual(debugStateIn.EndTime, debugStateOut.EndTime);
            Assert.AreEqual(debugStateIn.SessionID, debugStateOut.SessionID);

            Assert.IsTrue(debugStateOut.Inputs[0].FetchResultsList().SequenceEqual(debugStateIn.Inputs[0].FetchResultsList(), new DebugItemResultEqualityComparer()));
        }
        void DebugOutputViewModel_Append_ContentIsDebugStateErrors(bool parentContentHasErrors, bool childContentHasErrors)
        {
            //------------Setup for test--------------------------
            var envRepo = GetEnvironmentRepository();
            var viewModel = new DebugOutputViewModel(new Mock<IEventPublisher>().Object, envRepo, new Mock<IDebugOutputFilterStrategy>().Object);

            var parentContent = new DebugState { HasError = parentContentHasErrors, DisplayName = "Content", ID = Guid.NewGuid(), ParentID = Guid.Empty, StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };
            var childContent = new DebugState { HasError = childContentHasErrors, DisplayName = "Content", ID = Guid.NewGuid(), ParentID = parentContent.ID, StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };

            //------------Execute Test---------------------------
            viewModel.Append(parentContent);
            viewModel.Append(childContent);

            //------------Assert Results-------------------------
            Assert.AreEqual(2, viewModel.ContentItemCount);
            Assert.AreEqual(1, viewModel.RootItems.Count);

            var childItem = viewModel.RootItems[0].Children[0];

            Assert.AreEqual(childContentHasErrors, childItem.HasError);
            Assert.AreEqual(parentContentHasErrors, childItem.Parent.HasError);
        }
 public void DebugOutputViewModel_Append_ItemHasSameID_ShouldAddAsNewItemIntoTree()
 {
     //------------Setup for test--------------------------
     var id = Guid.NewGuid();
     var envRepo = GetEnvironmentRepository();
     var viewModel = new DebugOutputViewModel(new Mock<IEventPublisher>().Object, envRepo, new Mock<IDebugOutputFilterStrategy>().Object);
     var content = new DebugState { DisplayName = "Content", ID = id, ParentID = id, StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };
     viewModel.Append(content);
     var content2 = new DebugState { DisplayName = "Content2", ID = id, ParentID = id, StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };
     //------------Execute Test---------------------------
     viewModel.Append(content2);
     //------------Assert Results-------------------------
     Assert.AreEqual(2, viewModel.RootItems.Count);
     var child = viewModel.RootItems[0] as DebugStateTreeViewItemViewModel;
     Assert.IsNotNull(child);
     // ReSharper disable ConditionIsAlwaysTrueOrFalse
     if(child != null)
     // ReSharper restore ConditionIsAlwaysTrueOrFalse
     {
         Assert.AreEqual("Content", child.Content.DisplayName);
     }
     var child2 = viewModel.RootItems[1] as DebugStateTreeViewItemViewModel;
     Assert.IsNotNull(child2);
     // ReSharper disable ConditionIsAlwaysTrueOrFalse
     if(child2 != null)
     // ReSharper restore ConditionIsAlwaysTrueOrFalse
     {
         Assert.AreEqual("Content2", child2.Content.DisplayName);
     }
 }
        public void Filter_Where_ContentIsDebugState_And_ActivityTypeIsStep_And_FilterTextMatchesDurration_Expected_True()
        {
            DebugState debugState = new DebugState { ActivityType = ActivityType.Step, StartTime = new DateTime(2012, 01, 02, 1, 2, 3), EndTime = new DateTime(2012, 01, 02, 2, 2, 3) };

            bool actual = _debugOutputFilterStrategy.Filter(debugState, "01:");

            Assert.AreEqual(true, actual);
        }
        void DebugOutputViewModel_Append_ContentIsDebugState(Guid contentID, Guid contentParentID, string displayName)
        {
            //------------Setup for test--------------------------
            var envRepo = GetEnvironmentRepository();
            var viewModel = new DebugOutputViewModel(new Mock<IEventPublisher>().Object, envRepo, new Mock<IDebugOutputFilterStrategy>().Object);

            var content = new DebugState { DisplayName = displayName, ID = contentID, ParentID = contentParentID, StateType = StateType.All, ActivityType = ActivityType.Step, SessionID = viewModel.SessionID };

            //------------Execute Test---------------------------
            viewModel.Append(content);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, viewModel.ContentItemCount);
            Assert.AreEqual(1, viewModel.RootItems.Count);

            var child = viewModel.RootItems[0];
            Assert.AreEqual(0, child.Depth);
            Assert.IsNull(child.Parent);
            Assert.IsFalse(child.IsExpanded);
        }
        private static void WriteDebugItems(string workflowName, string taskName, string result)
        {
            string user = Thread.CurrentPrincipal.Identity.Name.Replace("\\", "-");

            var state = new DebugState
            {
                HasError = false,
                ID = Guid.NewGuid(),
                StartTime = DateTime.Now,
                EndTime = DateTime.Now,
                ActivityType = ActivityType.Workflow,
                ExecutingUser = user,
                Server = "localhost",
                ServerID = Guid.Empty,
                DisplayName = workflowName
            };
            if(!string.IsNullOrEmpty(result))
            {
                var data = DataListUtil.AdjustForEncodingIssues(result);
                bool isFragment;
                var isXml = DataListUtil.IsXml(data, out isFragment);
                if(isXml)
                {
                    var xmlData = XElement.Parse(data);
                    var allChildren = xmlData.Elements();
                    var groupedData = allChildren.GroupBy(element => element.Name);

                    var recSets = groupedData as IGrouping<XName, XElement>[] ?? groupedData.ToArray();
                    foreach(var grouping in recSets)
                    {
                        var debugItem = new DebugItem();
                        foreach(var name in grouping)
                        {
                            if(name.HasElements)
                            {
                                var debugItemResult = ProcessRecordSet(name, name.Elements());
                                debugItem.ResultsList.AddRange(debugItemResult);
                            }
                            else
                            {
                                var debugItemResult = new DebugItemResult
                                {
                                    Variable = DataListUtil.AddBracketsToValueIfNotExist(name.Name.LocalName),
                                    Value = name.Value,
                                    Operator = "=",
                                    Type = DebugItemResultType.Variable
                                };
                                debugItem.ResultsList.Add(debugItemResult);
                            }
                        }
                        state.Outputs.Add(debugItem);
                    }
                }
            }
            var js = new Dev2JsonSerializer();
            Thread.Sleep(5000);
            string correlation = GetCorrelationId(WarewolfTaskSchedulerPath + taskName);
            if(!Directory.Exists(OutputPath))
                Directory.CreateDirectory(OutputPath);
            File.WriteAllText(
                string.Format("{0}DebugItems_{1}_{2}_{3}_{4}.txt", OutputPath, workflowName.Replace("\\", "_"),
                    DateTime.Now.ToString("yyyy-MM-dd"), correlation, user),
                js.SerializeToBuilder(new List<DebugState> { state }).ToString());

        }
        public void Filter_Where_ContentIsDebugState_And_ActivityTypeIsWorkflow_And_FilterTextMatchesServer_Expected_True()
        {
            DebugState debugState = new DebugState { ActivityType = ActivityType.Workflow, DisplayName = "Cake" };
            bool actual = _debugOutputFilterStrategy.Filter(debugState, "ak");

            Assert.AreEqual(true, actual);
        }