Ejemplo n.º 1
0
 private void AddActionRegion(IList <IToolRegion> regions)
 {
     ActionRegion = new ComActionRegion(Model, ModelItem, SourceRegion, NamespaceRegion)
     {
         SourceChangedAction = () =>
         {
             OutputsRegion.IsEnabled = false;
             if (Regions != null)
             {
                 foreach (var toolRegion in Regions)
                 {
                     toolRegion.Errors?.Clear();
                 }
             }
         }
     };
     ActionRegion.ErrorsHandler += (sender, list) =>
     {
         var errorInfos = list.Select(error => new ActionableErrorInfo(new ErrorInfo {
             ErrorType = ErrorType.Critical, Message = error
         }, () => { })).ToList();
         UpdateDesignValidationErrors(errorInfos);
         Errors = new List <IActionableErrorInfo>(errorInfos);
     };
     regions.Add(ActionRegion);
 }
Ejemplo n.º 2
0
        public void ComActionRegion_Constructor_Scenerio_Result()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity()
            {
                SourceId = id
            };
            var src = new Mock <IComPluginServiceModel>();

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>());
            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()), sourceRegion, comNamespaceRegion);

            //------------Assert Results-------------------------
            Assert.AreEqual(0, dotNetActionRegion.Errors.Count);
            Assert.IsTrue(dotNetActionRegion.IsEnabled);
        }
Ejemplo n.º 3
0
        public void ComActionRegion_ChangeActionSomethingChanged_RegionsNotRestored_Invalid()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity {
                SourceId = id
            };
            var src       = new Mock <IComPluginServiceModel>();
            var dotNetsrc = new ComPluginSourceDefinition()
            {
                Id = id
            };
            var action = new PluginAction {
                FullName = "bravo"
            };

            var s2 = new ComPluginSourceDefinition {
                Id = Guid.NewGuid()
            };
            var action1 = new PluginAction {
                FullName = "bravo1"
            };

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>()
            {
                dotNetsrc, s2
            });

            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);

            var clone1 = new Mock <IToolRegion>();
            var clone2 = new Mock <IToolRegion>();
            var dep1   = new Mock <IToolRegion>();

            dep1.Setup(a => a.CloneRegion()).Returns(clone1.Object);

            var dep2 = new Mock <IToolRegion>();

            dep2.Setup(a => a.CloneRegion()).Returns(clone2.Object);
            dotNetActionRegion.Dependants = new List <IToolRegion> {
                dep1.Object, dep2.Object
            };
            dotNetActionRegion.SelectedAction = action;
            dotNetActionRegion.SelectedAction = action1;

            //------------Assert Results-------------------------
            dep1.Verify(a => a.RestoreRegion(clone1.Object), Times.Never);
            dep2.Verify(a => a.RestoreRegion(clone2.Object), Times.Never);
        }
Ejemplo n.º 4
0
        public void ComActionRegion_ChangeActionSomethingChanged_RestoreRegion_ExpectedRestore()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity {
                SourceId = id
            };
            var src       = new Mock <IComPluginServiceModel>();
            var dotNetsrc = new ComPluginSourceDefinition {
                Id = id
            };
            var s2 = new ComPluginSourceDefinition {
                Id = Guid.NewGuid()
            };
            var action = new PluginAction {
                FullName = "bravo"
            };

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>()
            {
                dotNetsrc, s2
            });

            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);
            // ReSharper disable once UseObjectOrCollectionInitializer
            ComActionRegion dotNetActionRegionToRestore = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);

            dotNetActionRegionToRestore.IsEnabled      = false;
            dotNetActionRegionToRestore.SelectedAction = action;

            dotNetActionRegion.RestoreRegion(dotNetActionRegionToRestore);

            //------------Assert Results-------------------------
            Assert.AreEqual(dotNetActionRegion.SelectedAction, action);
            Assert.IsFalse(dotNetActionRegion.IsEnabled);
        }
Ejemplo n.º 5
0
        public void ComActionRegion_ConstructorWithSelectedAction_Scenerio_Result()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity {
                SourceId = id
            };
            var src       = new Mock <IComPluginServiceModel>();
            var dotNetsrc = new ComPluginSourceDefinition {
                Id = id, ResourceName = "johnny"
            };
            var action = new PluginAction {
                FullName = "bravo", Method = "bravo", ReturnType = typeof(string), Variables = new List <INameValue>()
            };

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>()
            {
                dotNetsrc
            });

            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            sourceRegion.SelectedSource = dotNetsrc;

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);

            dotNetActionRegion.SelectedAction = action;

            //------------Assert Results-------------------------
            Assert.AreEqual(action, dotNetActionRegion.SelectedAction);
            Assert.AreEqual(action.FullName, dotNetActionRegion.SelectedAction.FullName);
            Assert.AreEqual(action.Method, dotNetActionRegion.SelectedAction.Method);
            Assert.AreEqual(typeof(string), dotNetActionRegion.SelectedAction.ReturnType);
            Assert.AreEqual(0, dotNetActionRegion.SelectedAction.Variables.Count);
            Assert.IsTrue(dotNetActionRegion.CanRefresh());
        }
Ejemplo n.º 6
0
        public void ComActionRegion_ChangeActionSomethingChanged_ExpectedChange_Result()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity {
                SourceId = id
            };
            var src       = new Mock <IComPluginServiceModel>();
            var dotNetsrc = new ComPluginSourceDefinition {
                Id = id
            };
            var evt = false;
            var s2  = new ComPluginSourceDefinition()
            {
                Id = Guid.NewGuid()
            };
            var action = new PluginAction {
                FullName = "bravo"
            };

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>()
            {
                dotNetsrc, s2
            });

            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);

            dotNetActionRegion.SomethingChanged += (a, b) => { evt = true; };
            dotNetActionRegion.SelectedAction    = action;

            //------------Assert Results-------------------------
            Assert.IsTrue(evt);
        }
Ejemplo n.º 7
0
        public void ComActionRegion_ChangeActionSomethingChanged_CloneRegion_ExpectedClone()
        {
            //------------Setup for test--------------------------
            var id  = Guid.NewGuid();
            var act = new DsfComDllActivity {
                SourceId = id
            };
            var src       = new Mock <IComPluginServiceModel>();
            var dotNetsrc = new ComPluginSourceDefinition {
                Id = id
            };
            var s2 = new ComPluginSourceDefinition {
                Id = Guid.NewGuid()
            };

            src.Setup(a => a.RetrieveSources()).Returns(new ObservableCollection <IComPluginSource>()
            {
                dotNetsrc, s2
            });

            ComSourceRegion sourceRegion = new ComSourceRegion(src.Object, ModelItemUtils.CreateModelItem(new DsfComDllActivity()));

            var namespaceItem = new NamespaceItem {
                FullName = "johnny"
            };
            ComNamespaceRegion comNamespaceRegion = new ComNamespaceRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion);

            comNamespaceRegion.SelectedNamespace = namespaceItem;

            //------------Execute Test---------------------------
            ComActionRegion dotNetActionRegion = new ComActionRegion(src.Object, ModelItemUtils.CreateModelItem(act), sourceRegion, comNamespaceRegion);
            var             cloned             = dotNetActionRegion.CloneRegion();

            //------------Assert Results-------------------------
            Assert.AreEqual(cloned.IsEnabled, dotNetActionRegion.IsEnabled);
            Assert.AreEqual(((ComActionRegion)cloned).SelectedAction, dotNetActionRegion.SelectedAction);
        }
Ejemplo n.º 8
0
        public override IList <IToolRegion> BuildRegions()
        {
            IList <IToolRegion> regions = new List <IToolRegion>();

            if (SourceRegion == null)
            {
                SourceRegion = new ComSourceRegion(Model, ModelItem)
                {
                    SourceChangedAction = () =>
                    {
                        if (Regions != null)
                        {
                            foreach (var toolRegion in Regions)
                            {
                                toolRegion.Errors?.Clear();
                            }
                        }
                    }
                };
                regions.Add(SourceRegion);
                NamespaceRegion = new ComNamespaceRegion(Model, ModelItem, SourceRegion)
                {
                    SourceChangedNamespace = () =>
                    {
                        OutputsRegion.IsEnabled = false;
                        if (Regions != null)
                        {
                            foreach (var toolRegion in Regions)
                            {
                                toolRegion.Errors?.Clear();
                            }
                        }
                    }
                };
                NamespaceRegion.SomethingChanged += (sender, args) =>
                {
                    if (args.Errors != null)
                    {
                        Errors =
                            args.Errors.Select(e => new ActionableErrorInfo {
                            ErrorType = ErrorType.Critical, Message = e
                        } as IActionableErrorInfo)
                            .ToList();
                    }
                };
                regions.Add(NamespaceRegion);
                ActionRegion = new ComActionRegion(Model, ModelItem, SourceRegion, NamespaceRegion)
                {
                    SourceChangedAction = () =>
                    {
                        OutputsRegion.IsEnabled = false;
                        if (Regions != null)
                        {
                            foreach (var toolRegion in Regions)
                            {
                                toolRegion.Errors?.Clear();
                            }
                        }
                    }
                };
                ActionRegion.ErrorsHandler += (sender, list) =>
                {
                    var errorInfos = list.Select(error => new ActionableErrorInfo(new ErrorInfo {
                        ErrorType = ErrorType.Critical, Message = error
                    }, () => { })).ToList();
                    UpdateDesignValidationErrors(errorInfos);
                    Errors = new List <IActionableErrorInfo>(errorInfos);
                };
                regions.Add(ActionRegion);
                InputArea = new DotNetInputRegion(ModelItem, ActionRegion);
                regions.Add(InputArea);
                OutputsRegion = new OutputsRegion(ModelItem, true);
                regions.Add(OutputsRegion);
                if (OutputsRegion.Outputs.Count > 0)
                {
                    OutputsRegion.IsEnabled = true;
                }
                ErrorRegion = new ErrorRegion();
                regions.Add(ErrorRegion);
                SourceRegion.Dependants.Add(NamespaceRegion);
                NamespaceRegion.Dependants.Add(ActionRegion);
                ActionRegion.Dependants.Add(InputArea);
                ActionRegion.Dependants.Add(OutputsRegion);
            }
            regions.Add(ManageServiceInputViewModel);
            Regions = regions;
            return(regions);
        }