Inheritance: Dev2.Studio.Core.ViewModels.Base.ValidationController, IDataErrorInfo, IContextualResourceModel
        public void WorkerServicePropertyInterigator_SetActivityProperties_NoSourceNameFromResourceRepo_NoSourceIdOnXML()
        {
            //------------Setup for test--------------------------
            IEventAggregator evtAg = new EventAggregator();
            Mock<IEnvironmentModel> env = new Mock<IEnvironmentModel>();
            Mock<IStudioResourceRepository> exp = new Mock<IStudioResourceRepository>();
            var resRepo = new Mock<IResourceRepository>();
            var srcRes = new Mock<IResourceModel>();
            srcRes.Setup(a => a.DisplayName).Returns("bob");
            resRepo.Setup(a => a.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false, false)).Returns(srcRes.Object);

            env.Setup(e => e.Name).Returns("My Env");
            var resource = new ResourceModel(env.Object, evtAg) { WorkflowXaml = new StringBuilder("<Action SourceName=\"TheSource\" Type=\"TheType\" SourceMethod=\"SourceMethod\"></Action>") };
            resource.ServerResourceType = "TheType";
            var activity = new DsfActivity("FriendlyName", String.Empty, "ServiceName", string.Empty, string.Empty, string.Empty);

            //------------Execute Test---------------------------
            WorkerServicePropertyInterigator.SetActivityProperties(resource, ref activity, resRepo.Object);

            //------------Assert Results-------------------------
            Assert.IsFalse(activity.IsWorkflow);
            Assert.AreEqual("TheType", ((Literal<string>)(activity.Type.Expression)).Value);
            Assert.AreEqual("TheSource", activity.FriendlySourceName.Expression.ToString());
            Assert.AreEqual("SourceMethod", activity.ActionName.Expression.ToString());
        }
 public static IContextualResourceModel CreateResourceModel(IEnvironmentModel environment, ResourceType resourceType, string iconPath, string displayName)
 {
     IContextualResourceModel resource = new ResourceModel(environment);
     resource.ResourceType = resourceType;
     resource.IconPath = iconPath;
     resource.DisplayName = displayName;
     resource.UserPermissions = Permissions.Contribute;
     return resource;
 }
        public void GivenIHaveTheFollowingVariableList(string variableList)
        {
            const string Root = "<DataList>##</DataList>";
            var datalist = Root.Replace("##", variableList);
            ScenarioContext.Current.Add("dataList", datalist);

            var testEnvironmentModel = ResourceModelTest.CreateMockEnvironment();

            var resourceModel = new ResourceModel(testEnvironmentModel.Object)
            {
                ResourceName = "test",
                ResourceType = ResourceType.Service,
                DataList = datalist
            };

            IDataListViewModel setupDatalist = new DataListViewModel();
            DataListSingleton.SetDataList(setupDatalist);
            DataListSingleton.ActiveDataList.InitializeDataListViewModel(resourceModel);
        }
        public void WorkflowPropertyInterigator_SetActivityProperties_WhenNullXmlPayload_ExpectSomePropertiesSet()
        {
            //------------Setup for test--------------------------
            IEventAggregator evtAg = new EventAggregator();
            Mock<IEnvironmentModel> env = new Mock<IEnvironmentModel>();
            Mock<IStudioResourceRepository> exp = new Mock<IStudioResourceRepository>();
            env.Setup(e => e.Name).Returns("My Env");
            var resource = new ResourceModel(env.Object, evtAg);

            var activity = new DsfActivity("FriendlyName", String.Empty, "ServiceName", string.Empty, string.Empty, string.Empty);
            //------------Execute Test---------------------------

            WorkflowPropertyInterigator.SetActivityProperties(resource, ref activity);

            //------------Assert Results-------------------------
            Assert.IsTrue(activity.IsWorkflow);
            Assert.AreEqual("Workflow", activity.Type.Expression.ToString());
            Assert.AreEqual("My Env", activity.FriendlySourceName.Expression.ToString());
        }
        public void WorkerServicePropertyInterigator_SetActivityProperties_WhenNotNullXML_ExpectPropertiesSet()
        {
            //------------Setup for test--------------------------
            IEventAggregator evtAg = new EventAggregator();
            Mock<IEnvironmentModel> env = new Mock<IEnvironmentModel>();
            Mock<IStudioResourceRepository> exp = new Mock<IStudioResourceRepository>();
            env.Setup(e => e.Name).Returns("My Env");
            var resource = new ResourceModel(env.Object, evtAg) { WorkflowXaml = new StringBuilder("<Action SourceName=\"TheSource\" Type=\"TheType\" SourceMethod=\"SourceMethod\"></Action>") };
            resource.ServerResourceType = "TheType";
            var activity = new DsfActivity("FriendlyName", String.Empty, "ServiceName", string.Empty, string.Empty, string.Empty);

            //------------Execute Test---------------------------
            WorkerServicePropertyInterigator.SetActivityProperties(resource, ref activity, null);

            //------------Assert Results-------------------------
            Assert.IsFalse(activity.IsWorkflow);
            Assert.AreEqual("TheType", ((Literal<string>)(activity.Type.Expression)).Value);
            Assert.AreEqual("TheSource", activity.FriendlySourceName.Expression.ToString());
            Assert.AreEqual("SourceMethod", activity.ActionName.Expression.ToString());
        }
        public void WorkerServicePropertyInterigator_SetActivityProperties_WhenNullXML_ExpectSomePropertiesSet()
        {
            //------------Setup for test--------------------------
            IEventAggregator evtAg = new EventAggregator();
            Mock<IEnvironmentModel> env = new Mock<IEnvironmentModel>();
            Mock<IStudioResourceRepository> exp = new Mock<IStudioResourceRepository>();
            env.Setup(e => e.Name).Returns("My Env");
            var resource = new ResourceModel(env.Object, evtAg);

            var activity = new DsfActivity("FriendlyName", String.Empty, "ServiceName", string.Empty, string.Empty, string.Empty);

            //------------Execute Test---------------------------
            WorkerServicePropertyInterigator.SetActivityProperties(resource, ref activity, null);

            //------------Assert Results-------------------------
            Assert.IsFalse(activity.IsWorkflow);
            Assert.IsNull(((Literal<string>)(activity.Type.Expression)).Value);
            Assert.IsNull(activity.FriendlySourceName);
            Assert.IsNull(activity.ActionName);
        }
        protected void ReloadResource(IEnvironmentModel environmentModel, Guid resourceId, ResourceType resourceType)
        {
            if(environmentModel == null || environmentModel.ResourceRepository == null)
            {
                return;
            }

            var getWorksurfaceItemRepo = WorkspaceItemRepository.Instance;

            CheckForServerMessages(environmentModel, resourceId, getWorksurfaceItemRepo);
            var effectedResources = environmentModel.ResourceRepository.ReloadResource(resourceId, resourceType, ResourceModelEqualityComparer.Current, true);
            if(effectedResources != null)
            {
                foreach(var resource in effectedResources)
                {
                    var resourceWithContext = new ResourceModel(environmentModel);
                    resourceWithContext.Update(resource);
                    Dev2Logger.Log.Info("Publish message of type - " + typeof(UpdateResourceMessage));
                    EventPublisher.Publish(new UpdateResourceMessage(resourceWithContext));
                }
            }
        }
Ejemplo n.º 8
0
        public void ResourceModel_ClearErrors_ClearsErrors()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);

            var errorInfos = model.Errors;

            //------------Assert Preconditions-------------------------
            Assert.AreEqual(2, errorInfos.Count);
            //------------Execute Test---------------------------
            model.ClearErrors();
            //-------------Assert Results------------------------
            errorInfos = model.Errors;
            Assert.AreEqual(0, errorInfos.Count);
        }
Ejemplo n.º 9
0
 public void ResourceModel_Update_WhenWorkflowXamlChanged_ExpectUpdatedResourceModelWithNewXaml()
 {
     //------------Setup for test--------------------------
     // Setup();
     var environmentModel = CreateMockEnvironment(new EventPublisher());
     var resourceModel = new ResourceModel(environmentModel.Object);
     const string category = "TestCat";
     const string comment = "TestComment";
     const string displayName = "DisplayName";
     const string resourceName = "TestResourceName";
     var id = Guid.NewGuid();
     const string tags = "TestTags";
     resourceModel.Category = category;
     resourceModel.Comment = comment;
     resourceModel.DisplayName = displayName;
     resourceModel.ID = id;
     resourceModel.ResourceName = resourceName;
     resourceModel.Tags = tags;
     resourceModel.WorkflowXaml = new StringBuilder("new xaml");
     //------------Execute Test---------------------------
     var updateResourceModel = new ResourceModel(environmentModel.Object) { WorkflowXaml = new StringBuilder("old xaml") };
     updateResourceModel.Update(resourceModel);
     //------------Assert Results-------------------------
     Assert.AreEqual("new xaml", updateResourceModel.WorkflowXaml.ToString());
 }
Ejemplo n.º 10
0
        public void ResourceModel_ToServiceDefinition_InvalidResourceType_ThrowsException()
        {
            //------------Setup for test--------------------------
            Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var repo = new Mock<IResourceRepository>();
            environmentModel.Setup(e => e.ResourceRepository).Returns(repo.Object);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID,
                WorkflowXaml = null,
                ResourceType = ResourceType.Server
            };

            //------------Execute Test---------------------------
            var serviceDefinition = model.ToServiceDefinition();

            //------------Assert Results-------------------------
            Assert.AreEqual(string.Empty, serviceDefinition);
        }
Ejemplo n.º 11
0
        public void ResourceModel_RemoveError_ErrorIsNotFound_DoesNothing()
        {
            var instanceID = Guid.NewGuid();

            IErrorInfo err1 = new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.Critical,
                FixType = FixType.ReloadMapping
            };

            IErrorInfo err2 = new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.Warning,
                FixType = FixType.ReloadMapping
            };
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1);
            model.AddError(err2);

            //------------Execute Test---------------------------
            model.RemoveError(new ErrorInfo
            {
                InstanceID = instanceID,
                ErrorType = ErrorType.None,
                FixType = FixType.Delete
            });

            //------------Assert Results-------------------------
            var errors = model.GetErrors(instanceID);

            Assert.AreEqual(2, errors.Count);
            Assert.AreSame(err1, errors[0]);
            Assert.AreSame(err2, errors[1]);
        }
Ejemplo n.º 12
0
        public void ResourceModel_IDataErrorInfo_ThisAccessor_ResourceName()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);
            //------------Execute Test---------------------------
            var errMessage = model["ResourceName"];
            //-------------Assert Results------------------------
            Assert.IsNotNull(errMessage);
            Assert.AreEqual("Please enter a name for this resource", errMessage);
        }
Ejemplo n.º 13
0
        public void ResourceModel_IDataErrorInfo_ThisAccessor_HelpLink()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object) { HelpLink = "somePath" };
            //------------Execute Test---------------------------
            var errMsg = model["HelpLink"];
            //-------------Assert Results------------------------
            Assert.IsNotNull(errMsg);
            Assert.AreEqual("The help link is not in a valid format", errMsg);
        }
Ejemplo n.º 14
0
        void Verify_ToServiceDefinition_GivenXamlPresent(ResourceType resourceType, string category, string workflowXaml, bool hasWorkflowXaml, Action<XElement> verify)
        {
            //------------Setup for test--------------------------
            Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var repo = new Mock<IResourceRepository>();
            repo.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(MakeMessage(workflowXaml));

            environmentModel.Setup(e => e.ResourceRepository).Returns(repo.Object);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID,
                WorkflowXaml = hasWorkflowXaml ? new StringBuilder(workflowXaml) : null,
                ResourceType = resourceType,
                Category = category
            };

            //------------Execute Test---------------------------
            var serviceDefinition = model.ToServiceDefinition();

            //------------Assert Results-------------------------
            var serviceElement = XElement.Parse(serviceDefinition.ToString());
            Assert.IsNotNull(serviceElement);

            verify(serviceElement);
        }
Ejemplo n.º 15
0
        void Verify_ToServiceDefinition_GivenXamlNull(ResourceType resourceType)
        {
            //------------Setup for test--------------------------
            Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var repo = new Mock<IResourceRepository>();
            repo.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(MakeMessage("test")).Verifiable();

            environmentModel.Setup(e => e.ResourceRepository).Returns(repo.Object);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID,
                WorkflowXaml = null,
                ResourceType = resourceType
            };

            //------------Execute Test---------------------------
            model.ToServiceDefinition();

            //------------Assert Results-------------------------
            repo.Verify(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>()));
        }
Ejemplo n.º 16
0
        public void ResourceModel_Environment_DesignValidationService_WiredUp()
        {
            var eventPublisher = new EventPublisher();

            var environmentID = Guid.NewGuid();
            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.Connection.ServerEvents).Returns(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environment.Object, new Mock<IEventAggregator>().Object);

            var errors = model.GetErrors(instanceID);
            Assert.AreEqual(0, errors.Count);

            var err = new ErrorInfo
            {
                InstanceID = instanceID,
            };

            var memo = new DesignValidationMemo
            {
                InstanceID = environmentID,
                Errors = new List<IErrorInfo>
                {
                    err
                }
            };

            //------------Execute Test---------------------------
            eventPublisher.Publish(memo);

            //------------Assert Results-------------------------
            errors = model.GetErrors(instanceID);
            Assert.AreEqual(1, errors.Count);
            Assert.AreSame(err, errors[0]);
        }
Ejemplo n.º 17
0
        public void ResourceModel_GetErrors_ErrorsForInstance()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);

            //------------Execute Test---------------------------
            var errors = model.GetErrors(instanceID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual(instanceID, errors[0].InstanceID);
        }
Ejemplo n.º 18
0
        public void ResourceModel_ClearErrors_FiresPropertyChangeForErrors()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);
            model.AddError(err1.Object);
            model.AddError(err2.Object);
            var _propertyChangedFired = false;
            model.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Errors")
                {
                    _propertyChangedFired = true;
                }
            };
            //------------Execute Test---------------------------
            model.ClearErrors();
            //-------------Assert Results------------------------
            Assert.IsTrue(_propertyChangedFired);
        }
Ejemplo n.º 19
0
        public void ResourceModel_IDataErrorInfo_ThisAccessor_IconPath()
        {
            //------------Setup for test--------------------------
            var instanceID = Guid.NewGuid();

            var err1 = new Mock<IErrorInfo>();
            err1.Setup(e => e.InstanceID).Returns(instanceID);
            var err2 = new Mock<IErrorInfo>();
            err2.Setup(e => e.InstanceID).Returns(Guid.NewGuid());
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object) { IconPath = "somePath" };
            //------------Execute Test---------------------------
            var errMsg = model["IconPath"];
            //-------------Assert Results------------------------
            Assert.IsNotNull(errMsg);
            Assert.AreEqual("Icon Path Does Not Exist or is not valid", errMsg);
        }
Ejemplo n.º 20
0
        public void ResourceModel_Constructor_IsWorkflowSaved()
        {
            //------------Setup for test--------------------------
            Setup();
            var environmentModel = CreateMockEnvironment(new Mock<IEventPublisher>().Object);

            //------------Execute Test---------------------------
            var resourceModel = new ResourceModel(environmentModel.Object);
            //------------Assert Results-------------------------
            Assert.IsTrue(resourceModel.IsWorkflowSaved);
        }
Ejemplo n.º 21
0
 public void ResourceModel_OnWorkflowSaved_IsWorkflowchangedWherePropertyUpdated_FireOnWorkflowSaved()
 {
     //------------Setup for test--------------------------
     Setup();
     Mock<IEnvironmentModel> testEnvironmentModel = CreateMockEnvironment(EventPublishers.Studio);
     var resourceModel = new ResourceModel(testEnvironmentModel.Object);
     var eventFired = false;
     IContextualResourceModel eventResourceModel = null;
     resourceModel.OnResourceSaved += model =>
     {
         eventResourceModel = model;
         eventFired = true;
     };
     //------------Execute Test---------------------------
     resourceModel.IsWorkflowSaved = true;
     //------------Assert Results-------------------------
     Assert.IsTrue(eventFired);
     Assert.IsNotNull(eventResourceModel);
     Assert.AreSame(resourceModel, eventResourceModel);
 }
Ejemplo n.º 22
0
 public void ResourceModel_DataListPropertyWhereChangedToSameString_NotifyPropertyChangedNotFiredTwice()
 {
     //------------Setup for test--------------------------
     // Setup();
     Mock<IEnvironmentModel> testEnvironmentModel = CreateMockEnvironment();
     var resourceModel = new ResourceModel(testEnvironmentModel.Object);
     var timesFired = 0;
     var dataListFired = 0;
     resourceModel.PropertyChanged += (sender, args) =>
     {
         timesFired++;
     };
     resourceModel.OnDataListChanged += () =>
         {
             dataListFired++;
         };
     //------------Execute Test---------------------------
     resourceModel.DataList = "TestDataList";
     resourceModel.DataList = "TestDataList";
     //------------Assert Results-------------------------
     Assert.AreEqual(1, timesFired);
     Assert.AreEqual(1, dataListFired);
 }
Ejemplo n.º 23
0
        public void ResourceModel_Rollback_FixedErrorsRestored()
        {
            //Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            var hitCount = 0;
            model.OnDesignValidationReceived += (sender, memo) =>
            {
                switch (hitCount++)
                {
                    case 0:
                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;

                    case 1:
                        Assert.AreEqual(1, model.Errors.Count);
                        Assert.AreEqual(1, model.FixedErrors.Count);

                        model.Rollback();

                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;
                }
            };

            // Publish 2 errors
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });
            eventPublisher.Publish(pubMemo);

            // Fix 1 error and publish
            pubMemo.Errors.RemoveAt(1);
            eventPublisher.Publish(pubMemo);
        }
Ejemplo n.º 24
0
        public void ResourceModel_DataList_Setter_UpdatedDataListSectionInServiceDefinition()
        {
            Setup();
            const string newDataList = @"<DataList>
              <Country />
              <State />
              <City>
            <Name />
            <GeoLocation />
              </City>
            </DataList>";

            var environmentModel = CreateMockEnvironment(new Mock<IEventPublisher>().Object);

            var resourceModel = new ResourceModel(environmentModel.Object)
            {
                ResourceName = "test",
                ResourceType = ResourceType.Service,
                WorkflowXaml = new StringBuilder(@"
            <Service Name=""abc"">
            <Inputs/>
            <Outputs/>
            <DataList>
            <Country/>
            <State />
            <City>
            <Name/>
            <GeoLocation />
            </City>
            </DataList>
            </Service>
            ")
            };

            var eventWasFired = false;
            resourceModel.OnDataListChanged += () =>
                {
                    eventWasFired = true;
                };
            resourceModel.DataList = newDataList;

            string result = resourceModel.DataList;

            var xe = resourceModel.WorkflowXaml.ToXElement();
            var dlElms = xe.Elements("DataList");

            var firstOrDefault = dlElms.FirstOrDefault();
            if (firstOrDefault != null)
            {
                var wfResult = firstOrDefault.ToString(SaveOptions.None);
                StringAssert.Contains(result, wfResult);
                Assert.IsTrue(eventWasFired);
            }
            else
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 25
0
 public void ResourceModel_UpdateResourceModelExpectPropertiesUpdated()
 {
     //------------Setup for test--------------------------
     Setup();
     var environmentModel = CreateMockEnvironment(new EventPublisher());
     var resourceModel = new ResourceModel(environmentModel.Object);
     const Permissions UserPermissions = Permissions.Contribute;
     const string category = "TestCat";
     const string comment = "TestComment";
     const string displayName = "DisplayName";
     const string resourceName = "TestResourceName";
     const string inputs = "this is the inputs";
     const string outputs = "this is the outputs";
     var id = Guid.NewGuid();
     const string tags = "TestTags";
     resourceModel.Category = category;
     resourceModel.Comment = comment;
     resourceModel.DisplayName = displayName;
     resourceModel.ID = id;
     resourceModel.ResourceName = resourceName;
     resourceModel.Tags = tags;
     resourceModel.UserPermissions = UserPermissions;
     resourceModel.Inputs = inputs;
     resourceModel.Outputs = outputs;
     //------------Execute Test---------------------------
     var updateResourceModel = new ResourceModel(environmentModel.Object);
     updateResourceModel.Update(resourceModel);
     //------------Assert Results-------------------------
     Assert.AreEqual(category, updateResourceModel.Category);
     Assert.AreEqual(comment, updateResourceModel.Comment);
     Assert.AreEqual(displayName, updateResourceModel.DisplayName);
     Assert.AreEqual(id, updateResourceModel.ID);
     Assert.AreEqual(tags, updateResourceModel.Tags);
     Assert.AreEqual(UserPermissions, updateResourceModel.UserPermissions);
     Assert.AreEqual(inputs, updateResourceModel.Inputs);
     Assert.AreEqual(outputs, updateResourceModel.Outputs);
 }
Ejemplo n.º 26
0
        public void ResourceModel_DesignValidationServicePublishingMemo_NoInstanceID_DoesNotUpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error." });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error." });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) => Assert.AreEqual(0, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

            eventPublisher.Publish(pubMemo);
        }
Ejemplo n.º 27
0
        static ResourceModel CreateResourceModel(string resourceDefintion = "resource xaml")
        {
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var repo = new Mock<IResourceRepository>();
            repo.Setup(r => r.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(MakeMessage(resourceDefintion));

            environmentModel.Setup(e => e.ResourceRepository).Returns(repo.Object);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };
            return model;
        }
Ejemplo n.º 28
0
        public void ResourceModel_DesignValidationServicePublishingMemo_UpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) =>
            {
                Assert.AreEqual(memo.Errors.Count, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

                foreach (var error in memo.Errors)
                {
                    var modelError = model.Errors.FirstOrDefault(me => me.ErrorType == error.ErrorType && me.Message == error.Message);
                    Assert.AreSame(error, modelError, "OnDesignValidationReceived did not set the error.");
                }
            };

            eventPublisher.Publish(pubMemo);
        }
Ejemplo n.º 29
0
        static void Verify_Authorization_IsAuthorized(AuthorizationContext authorizationContext)
        {
            //------------Setup for test--------------------------
            var requiredPermissions = authorizationContext.ToPermissions();
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object);

            foreach (Permissions permission in Enum.GetValues(typeof(Permissions)))
            {
                model.UserPermissions = permission;
                var expected = (permission & requiredPermissions) != 0;

                //------------Execute Test---------------------------
                var authorized = model.IsAuthorized(authorizationContext);

                //------------Assert Results-------------------------
                Assert.AreEqual(expected, authorized);
            }
        }
Ejemplo n.º 30
0
        public void ResourceModel_DisplayName_IsNullOrEmptyAndResourceTypeIsWorkflowService_Workflow()
        {
            //------------Setup for test--------------------------
            var model = new ResourceModel(new Mock<IEnvironmentModel>().Object, new Mock<IEventAggregator>().Object)
            {
                ResourceType = ResourceType.WorkflowService
            };

            //------------Execute Test---------------------------
            var displayName = model.DisplayName;

            //------------Assert Results-------------------------
            Assert.AreEqual("Workflow", displayName);
        }