Used to return a list of messages
Inheritance: ICompileMessageList
 static Mock<IEnvironmentConnection> SetupConnectionWithCompileMessageList(List<ICompileMessageTO> compileMessageTos, List<string> deps)
 {
     CompileMessageList compileMessageList = new CompileMessageList { MessageList = compileMessageTos, Dependants = deps };
     var jsonSer = new Dev2JsonSerializer();
     string serializeObject = jsonSer.Serialize(compileMessageList);
     var envConnection = new Mock<IEnvironmentConnection>();
     envConnection.Setup(e => e.IsConnected).Returns(true);
     envConnection.Setup(c => c.ServerEvents).Returns(new EventPublisher());
     envConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(new StringBuilder(serializeObject));
     return envConnection;
 }
        public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace)
        {
            string serviceId = null;
            string workspaceId = null;

            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var result = new ExecuteMessage { HasError = false };

            StringBuilder tmp;
            values.TryGetValue("ServiceID", out tmp);
            if(tmp != null)
            {
                serviceId = tmp.ToString();
            }
            values.TryGetValue("WorkspaceID", out tmp);
            if(tmp != null)
            {
                workspaceId = tmp.ToString();
            }
            values.TryGetValue("FilterList", out tmp);
            if(tmp != null)
            {
            }

            if(string.IsNullOrEmpty(serviceId) || string.IsNullOrEmpty(workspaceId))
            {
                throw new InvalidDataContractException("Null or empty ServiceID or WorkspaceID");
            }

            Guid wGuid;
            Guid sGuid;

            Guid.TryParse(workspaceId, out wGuid);
            Guid.TryParse(serviceId, out sGuid);


            var thisService = ResourceCatalog.Instance.GetResource(wGuid, sGuid);
            var msgs = new CompileMessageList();
            var dependants = new List<Guid>();
            if(thisService != null)
            {
                var workspaceGuids = WorkspaceRepository.Instance.GetWorkspaceGuids();
                workspaceGuids.ForEach(guid =>
                {
                    var union = dependants.Union(ResourceCatalog.Instance.GetDependants(guid, thisService.ResourceID));
                    dependants = union.ToList();
                });
                
                var enumerable = dependants.Select(a =>
                {
                    var resource = ResourceCatalog.Instance.GetResource(GlobalConstants.ServerWorkspaceID,a) ?? ResourceCatalog.Instance.GetResource(wGuid,a);
                    return resource==null?"": resource.ResourcePath;
                });
                var deps = enumerable.Distinct().ToList();
                if(deps.Count > 0)
                {
                    // ReSharper disable ExpressionIsAlwaysNull
                    msgs = new CompileMessageList();
                    var compileMessageTo = new CompileMessageTO
                    {
                        ErrorType = ErrorType.Critical, 
                        MessageType = CompileMessageType.MappingChange
                    };
                    msgs.Dependants =new List<string>();
                    deps.ForEach(s => msgs.Dependants.Add(s));
                    msgs.MessageList = new List<ICompileMessageTO> { compileMessageTo };
                    // ReSharper restore ExpressionIsAlwaysNull
                    return serializer.SerializeToBuilder(msgs);
                }
            }
            else
            {
                result.Message.Append("Could not locate service with ID [ " + sGuid + " ]");
            }

            return serializer.SerializeToBuilder(msgs);
        }
        public void WorkSurfaceContextViewModel_SaveCallsCheckForServerMessages_MessagesAvailable_SuffHappens()
        {
            //------------Setup for test--------------------------
            var workSurfaceKey = new WorkSurfaceKey();
            var mockWorkSurfaceViewModel = new Mock<IWorkflowDesignerViewModel>();
            var mockedConn = new Mock<IEnvironmentConnection>();
            mockedConn.Setup(conn => conn.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockedConn.Object);
            mockEnvironmentModel.SetupGet(p => p.IsConnected).Returns(true);
            var mockRepository = new Mock<IResourceRepository>();
            mockRepository.Setup(c => c.FetchResourceDefinition(It.IsAny<IEnvironmentModel>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<bool>())).Returns(new ExecuteMessage());
            mockRepository.Setup(m => m.Save(It.IsAny<IResourceModel>())).Verifiable();
            mockRepository.Setup(c => c.SaveToServer(It.IsAny<IResourceModel>())).Returns(new ExecuteMessage());
            mockEnvironmentModel.SetupGet(p => p.ResourceRepository).Returns(mockRepository.Object);
            var environmentModel = mockEnvironmentModel.Object;
            mockWorkSurfaceViewModel.Setup(model => model.EnvironmentModel).Returns(environmentModel);
            mockWorkSurfaceViewModel.Setup(m => m.BindToModel()).Verifiable();
            var workSurfaceViewModel = mockWorkSurfaceViewModel.As<IWorkSurfaceViewModel>();

            // object to work on
            var workSurfaceContextViewModel = new WorkSurfaceContextViewModel(workSurfaceKey, workSurfaceViewModel.Object);

            var lst = new CompileMessageList { MessageList = new List<ICompileMessageTO> { new CompileMessageTO() } };
            var st = new Mock<IStudioCompileMessageRepoFactory>();
            var mr = new Mock<IStudioCompileMessageRepo>();
            workSurfaceContextViewModel.StudioCompileMessageRepoFactory = st.Object;
            st.Setup(x => x.Create()).Returns(mr.Object);
            mr.Setup(a => a.GetCompileMessagesFromServer(It.IsAny<IContextualResourceModel>())).Returns(lst);
            var resourceChangedFactory = new Mock<IResourceChangeHandlerFactory>();
            var rsHandler = new Mock<IResourceChangeHandler>();
            resourceChangedFactory.Setup(a => a.Create(It.IsAny<IEventAggregator>())).Returns(rsHandler.Object);
            workSurfaceContextViewModel.ResourceChangeHandlerFactory = resourceChangedFactory.Object;

            var mockResourceModel = new Mock<IContextualResourceModel>();
            mockResourceModel.SetupGet(p => p.Environment).Returns(environmentModel);
            mockResourceModel.Setup(m => m.UserPermissions).Returns(Permissions.Contribute);

            //------------Execute Test---------------------------

            workSurfaceContextViewModel.Handle(new SaveResourceMessage(mockResourceModel.Object, false, false));
        }
Ejemplo n.º 4
0
        public CompileMessageList FetchMessages(Guid workspaceId, Guid serviceId, IList<string> dependants, CompileMessageType[] filter = null)
        {
            IList<ICompileMessageTO> result = new List<ICompileMessageTO>();

            lock(Lock)
            {
                IList<ICompileMessageTO> messages;
                if(_messageRepo.TryGetValue(workspaceId, out messages))
                {

                    var candidateMessage = messages.Where(c => c.ServiceID == serviceId);
                    var compileMessageTos = candidateMessage as IList<ICompileMessageTO> ??
                                            candidateMessage.ToList();

                    foreach(var msg in compileMessageTos)
                    {
                        if(filter != null)
                        {
                            // TODO : Apply filter logic ;)
                        }
                        else
                        {
                            result.Add(msg);
                        }
                    }
                }
            }
            var compileMessageList = new CompileMessageList { MessageList = result, ServiceID = serviceId, Dependants = dependants };
            RemoveMessages(workspaceId, serviceId);
            return compileMessageList;
        }