Inheritance: IExplorerItem
        public void ServerExplorerItem_GetHashCode_ExpectHashCodeSameAsID()
        {
            //------------Setup for test--------------------------
            var guid = Guid.NewGuid();
            const string name = "a";
            const ResourceType explorerItemType = ResourceType.PluginService;
            var children = new List<IExplorerItem>();
            const Permissions permissions = Permissions.DeployFrom;


            //------------Execute Test---------------------------
            var serverExplorerItem = new ServerExplorerItem(name, guid, explorerItemType, children, permissions, "");
            //------------Assert Results-------------------------

            Assert.AreEqual(guid.GetHashCode(), serverExplorerItem.GetHashCode());

        }
        public void FetchExplorerItems_Execute_ExpectName()
        {
            //------------Setup for test--------------------------
            var fetchExplorerItems = new FetchExplorerItems();

            ServerExplorerItem item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "");
            var repo = new Mock<IExplorerServerResourceRepository>();
            var ws = new Mock<IWorkspace>();
            repo.Setup(a => a.Load(It.IsAny<Guid>())).Returns(item).Verifiable();
            var serializer = new Dev2JsonSerializer();
            ws.Setup(a => a.ID).Returns(Guid.Empty);
            fetchExplorerItems.ServerExplorerRepo = repo.Object;
            //------------Execute Test---------------------------
            var ax = fetchExplorerItems.Execute(new Dictionary<string, StringBuilder>(), ws.Object);
            //------------Assert Results-------------------------
            repo.Verify(a => a.Load(It.IsAny<Guid>()));
            Assert.AreEqual(serializer.Deserialize<IExplorerItem>(ax.ToString()).ResourceId, item.ResourceId);
        }
 public void GetVersions_Execute_ExpectName()
 {
     //------------Setup for test--------------------------
     var getVersions = new GetVersions();
     var resourceId = Guid.NewGuid();
     ServerExplorerItem item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "");
     var repo = new Mock<IServerVersionRepository>();
     var ws = new Mock<IWorkspace>();
     repo.Setup(a => a.GetVersions(resourceId)).Returns(new List<IExplorerItem> {item});
     var serializer = new Dev2JsonSerializer();
     ws.Setup(a => a.ID).Returns(Guid.Empty);
     getVersions.ServerVersionRepo = repo.Object;
     //------------Execute Test---------------------------
     var ax = getVersions.Execute(new Dictionary<string, StringBuilder> {{"resourceId",new StringBuilder( resourceId.ToString())}}, ws.Object);
     //------------Assert Results-------------------------
     repo.Verify(a => a.GetVersions(It.IsAny<Guid>()));
     Assert.AreEqual(serializer.Deserialize<IList<IExplorerItem>>(ax.ToString())[0].ResourceId, item.ResourceId);
 }
        public void ServerExplorerItem_Constructor_Construct_ExpectAllFieldsAreSetup()
        {
            //------------Setup for test--------------------------
            var guid = Guid.NewGuid();
            const string name = "a";
            const ResourceType explorerItemType = ResourceType.Folder;
            var children = new List<IExplorerItem>();
            const Permissions permissions = Permissions.DeployFrom;


            //------------Execute Test---------------------------
            var serverExplorerItem = new ServerExplorerItem(name, guid, explorerItemType, children, permissions, "/");
            //------------Assert Results-------------------------

            Assert.AreEqual(children, serverExplorerItem.Children);
            Assert.AreEqual(name, serverExplorerItem.DisplayName);
            Assert.AreEqual(serverExplorerItem.ResourceType, explorerItemType);
            Assert.AreEqual(permissions, serverExplorerItem.Permissions);
            Assert.AreEqual(guid, serverExplorerItem.ResourceId);
        }
Exemple #5
0
        public void CreateFolder_Execute_ExpectCreateCalled()
        {
            //------------Setup for test--------------------------
            var createFolderService = new AddFolderService();

            ServerExplorerItem item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "");
            var repo = new Mock<IExplorerServerResourceRepository>();
            var ws = new Mock<IWorkspace>();
            repo.Setup(a => a.AddItem(item, It.IsAny<Guid>())).Returns(new ExplorerRepositoryResult(ExecStatus.Fail, "noddy"));
            var serializer = new Dev2JsonSerializer();
            var inputs = new Dictionary<string, StringBuilder>();
            inputs.Add("itemToAdd", serializer.SerializeToBuilder(item));

            ws.Setup(a => a.ID).Returns(Guid.Empty);
            createFolderService.ServerExplorerRepo = repo.Object;
            //------------Execute Test---------------------------
            createFolderService.Execute(inputs, ws.Object);
            //------------Assert Results-------------------------
            repo.Verify(a => a.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()));
        }
        public void ServerExplorerItem_Equals_ExpectEqualityOnGuidOnly()
        {
            //------------Setup for test--------------------------
            var guid = Guid.NewGuid();
            const string name = "a";
            const ResourceType explorerItemType = ResourceType.PluginService;
            var children = new List<IExplorerItem>();
            const Permissions permissions = Permissions.DeployFrom;


            //------------Execute Test---------------------------
            var serverExplorerItem = new ServerExplorerItem(name, guid, explorerItemType, children, permissions, "");
            var serverExplorerItem2 = new ServerExplorerItem(name, guid, explorerItemType, children, Permissions.Administrator, "");
            var serverExplorerItem3 = new ServerExplorerItem(name, Guid.NewGuid(), explorerItemType, children, permissions, "");
            //------------Assert Results-------------------------

            Assert.AreEqual(serverExplorerItem, serverExplorerItem2);
            Assert.AreNotEqual(serverExplorerItem, null);
            Assert.AreEqual(serverExplorerItem, serverExplorerItem);
            Assert.AreNotEqual(serverExplorerItem, guid);
            Assert.AreNotEqual(serverExplorerItem, serverExplorerItem3);

        }
 public void StudioResourceRepository_GetEnvironmentModel_HasMatchingID_ReturnsTrue()
 {
     //------------Setup for test--------------------------
     var environmentModel = new Mock<IEnvironmentModel>();
     var environmentId = Guid.NewGuid();
     environmentModel.Setup(model => model.ID).Returns(environmentId);
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.WebServerUri).Returns(new Uri("http://bob:3142/"));
     var serverID = Guid.NewGuid();
     mockConnection.Setup(connection => connection.ServerID).Returns(serverID);
     environmentModel.Setup(a => a.Connection).Returns(mockConnection.Object);
     ServerExplorerItem serverExplorerItem = new ServerExplorerItem { WebserverUri = "http://bob:3142/", ServerId = serverID };
     //------------Execute Test---------------------------
     var found = StudioResourceRepository.GetEnvironmentModel(environmentModel.Object, serverExplorerItem, environmentId);
     //------------Assert Results-------------------------
     Assert.IsTrue(found);
 }
        private IList<IExplorerItem> BuildStructureFromFilePath(IDirectory directory, string path, string rootPath)
        {

            var firstGen =
                directory.GetDirectories(path)
                         .Where(a => !a.EndsWith("VersionControl"));

            IList<IExplorerItem> children = new List<IExplorerItem>();
            foreach(var resource in firstGen)
            {
                var resourcePath = resource.Replace(rootPath, "").Substring(1);

                var node = new ServerExplorerItem(new DirectoryInfo(resource).Name, Guid.NewGuid(), ResourceType.Folder, null, _authService.GetResourcePermissions(Guid.Empty), resourcePath);
                children.Add(node);
                node.Children = BuildStructureFromFilePath(directory, resource, rootPath);
            }
            return children;
        }
        public void StudioResourceRepository_UpdateRootAndFoldersPermissions_SetPermissionsToView_ExplorerItemsAreUpdatedToView()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.Server,
                DisplayName = "Azure server",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };
            SetupEnvironmentRepo(Guid.Empty);
            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };

            repo.GetCurrentEnvironment = () => Guid.Empty;
            //------------Execute Test---------------------------
            repo.UpdateRootAndFoldersPermissions(Permissions.View, Guid.Empty);
            //------------Assert Results-------------------------
            var permissions  = repo.ExplorerItemModels.First().Descendants().Select(s => s.Permissions);
            Assert.IsTrue(permissions.All(p => p == Permissions.View));
        }
        private IExplorerItem GetTestData(string workFlowId = "DF279411-F678-4FCC-BE88-A1B613EE51E3",
                                          string dbServiceId = "DF279411-F678-4FCC-BE88-A1B613EE51E3", Guid? folderID = null)
        {
            var workflow1 = new ServerExplorerItem
                {
                    ResourceType = ResourceType.WorkflowService,
                    DisplayName = "workflow1",
                    ResourceId = string.IsNullOrEmpty(workFlowId) ? Guid.NewGuid() : Guid.Parse(workFlowId),
                    Permissions = Permissions.Administrator
                };

            var dbService1 = new ServerExplorerItem { ResourceType = ResourceType.DbService, DisplayName = "dbService1", ResourceId = string.IsNullOrEmpty(dbServiceId) ? Guid.NewGuid() : Guid.Parse(dbServiceId), Permissions = Permissions.Contribute };
            var webService1 = new ServerExplorerItem { ResourceType = ResourceType.WebService, DisplayName = "webService1", ResourceId = Guid.NewGuid(), Permissions = Permissions.View };
            var pluginService1 = new ServerExplorerItem { ResourceType = ResourceType.PluginService, DisplayName = "pluginService1", ResourceId = Guid.NewGuid(), Permissions = Permissions.View };
            var dbSource1 = new ServerExplorerItem { ResourceType = ResourceType.DbSource, DisplayName = "dbSource1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var webSource1 = new ServerExplorerItem { ResourceType = ResourceType.WebSource, DisplayName = "webSource1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var pluginSource1 = new ServerExplorerItem { ResourceType = ResourceType.PluginSource, DisplayName = "pluginSource1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var emailSource1 = new ServerExplorerItem { ResourceType = ResourceType.EmailSource, DisplayName = "emailSource1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var serverSource1 = new ServerExplorerItem { ResourceType = ResourceType.ServerSource, DisplayName = "serverSource1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var folder1 = new ServerExplorerItem { ResourceType = ResourceType.Folder, DisplayName = "folder1", ResourceId = folderID ?? Guid.NewGuid(), Permissions = Permissions.Administrator };
            var folder2 = new ServerExplorerItem { ResourceType = ResourceType.Folder, DisplayName = "folder2", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var subfolder1 = new ServerExplorerItem { ResourceType = ResourceType.Folder, DisplayName = "subfolder1", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };
            var localhost = new ServerExplorerItem { ResourceType = ResourceType.Server, DisplayName = "localhost", ResourceId = Guid.NewGuid(), Permissions = Permissions.Administrator };

            dbService1.Parent = webService1.Parent = pluginService1.Parent = subfolder1.Parent = folder1;
            dbSource1.Parent = webSource1.Parent = pluginSource1.Parent = emailSource1.Parent = serverSource1.Parent = folder2;

            folder2.Children = new List<IExplorerItem>
                {
                    dbSource1,
                    webSource1,
                    pluginSource1,
                    emailSource1,
                    serverSource1
                };


            folder1.Children = new List<IExplorerItem>
                {
                    dbService1, 
                    webService1,
                    pluginService1, 
                    subfolder1
                };

            localhost.Children = new List<IExplorerItem> { folder1, workflow1 };
            workflow1.Parent = localhost;
            folder1.Parent = localhost;

            return localhost;
        }
        public void ServerExplorerRepository_RenameFolder_FilesystemError_ExpectFailureMessage()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock<IResourceCatalog>();
            ResourceCatalogResult resourceCatalogResult = new ResourceCatalogResult { Status = ExecStatus.Success, Message = "" };
            catalogue.Setup(catalog => catalog.RenameCategory(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<string>())).Returns(resourceCatalogResult);
            var factory = new Mock<IExplorerItemFactory>();
            var dir = new Mock<IDirectory>();
            var guid = Guid.NewGuid();

            var explorerItem = new ServerExplorerItem(
                "dave", guid,
                ResourceType.DbSource,
                new List<IExplorerItem>()
                , Permissions.Administrator, "bob"
                );
            factory.Setup(a => a.CreateRootExplorerItem(It.IsAny<string>(), It.IsAny<Guid>())).Returns(explorerItem);

            dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(true);
            dir.Setup(a => a.Delete(It.IsAny<string>(), It.IsAny<bool>())).Throws(new FieldAccessException("bob has an error")).Verifiable();

            var sync = new Mock<IExplorerRepositorySync>();
            var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper());


            //------------Execute Test---------------------------
            var result = serverExplorerRepository.RenameFolder("monkey", "moocowimpi", Guid.NewGuid());
            //------------Assert Results-------------------------
            Assert.AreEqual(result.Message, "bob has an error");
            Assert.AreEqual(result.Status, ExecStatus.AccessViolation);

        }
        public void StudioResourceRepository_GetServerVersion_CallsProxy_ReturnsDefault_IfError()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty,
                GetEnvironmentRepository = () => new Mock<IEnvironmentRepository>().Object
            };
            var env = Guid.NewGuid();
            mockExplorerResourceRepository.Setup(a => a.GetServerVersion()).Throws(new Exception());
            //------------Execute Test---------------------------
            Assert.AreEqual("Less than 0.4.19.1", repo.GetServerVersion(env));
            mockExplorerResourceRepository.Verify(a=>a.GetServerVersion());
        }
        public void StudioResourceRepository_GetVersion_VersionIsNull_ThrowsException()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };
            //------------Execute Test---------------------------
            repo.GetVersion(null, Guid.Empty);
        }
Exemple #14
0
 protected bool Equals(ServerExplorerItem other)
 {
     return(ResourceId.Equals(other.ResourceId));
 }
 protected bool Equals(ServerExplorerItem other)
 {
     return ResourceId.Equals(other.ResourceId);
 }
        public void GetDirectoriesRelativeToServer_UnitTest_ExecuteWithDirectory_ExpectDirectoryStructure()
        {
            //----------------Setup---------------------------------------------
            var esb = new GetDirectoriesRelativeToServer();
            Mock<IExplorerServerResourceRepository> mockRepo = new Mock<IExplorerServerResourceRepository>();
            ServerExplorerItem serverExplorerItem = new ServerExplorerItem();
            serverExplorerItem.ResourceType = ResourceType.Server;
            ServerExplorerItem levelOneFolder = new ServerExplorerItem();
            levelOneFolder.ResourceType = ResourceType.Folder;
            levelOneFolder.DisplayName = "Test1";
            levelOneFolder.ResourcePath = "Test1";
            serverExplorerItem.Children.Add(levelOneFolder);
            IExplorerItem levelOneFolderTwo = new ServerExplorerItem();
            levelOneFolderTwo.ResourceType = ResourceType.Folder;
            levelOneFolderTwo.DisplayName = "Test2";
            levelOneFolderTwo.ResourcePath = "Test2";
            ServerExplorerItem levelTwoFolderInFolderTwo = new ServerExplorerItem();
            levelTwoFolderInFolderTwo.ResourceType = ResourceType.Folder;
            levelTwoFolderInFolderTwo.DisplayName = "InnerTest2";
            levelTwoFolderInFolderTwo.ResourcePath = levelOneFolderTwo.ResourcePath + "\\InnerTest2";
            levelOneFolderTwo.Children.Add(levelTwoFolderInFolderTwo);
            serverExplorerItem.Children.Add(levelOneFolderTwo);
            mockRepo.Setup(repository => repository.Load(ResourceType.Folder, It.IsAny<string>())).Returns(serverExplorerItem);
            esb.ServerExplorerRepo = mockRepo.Object;
            //----------------Execute------------------------------------------------
            var actual = esb.Execute(new Dictionary<string, StringBuilder> { { "Directory", new StringBuilder("Resources") } }, null);
            //----------------Assert Results-----------------------------------------
            Assert.AreNotEqual(string.Empty, actual);
            const string expected = @"<JSON>{
  ""$type"": ""Dev2.Runtime.ESB.Management.Services.JsonTreeNode, Dev2.Runtime.Services"",
  ""title"": ""Root"",
  ""isFolder"": true,
  ""key"": ""root"",
  ""isLazy"": false,
  ""children"": [
    {
      ""$type"": ""Dev2.Runtime.ESB.Management.Services.JsonTreeNode, Dev2.Runtime.Services"",
      ""title"": ""Test1"",
      ""isFolder"": true,
      ""key"": ""Test1"",
      ""isLazy"": false,
      ""children"": []
    },
    {
      ""$type"": ""Dev2.Runtime.ESB.Management.Services.JsonTreeNode, Dev2.Runtime.Services"",
      ""title"": ""Test2"",
      ""isFolder"": true,
      ""key"": ""Test2"",
      ""isLazy"": false,
      ""children"": [
        {
          ""$type"": ""Dev2.Runtime.ESB.Management.Services.JsonTreeNode, Dev2.Runtime.Services"",
          ""title"": ""InnerTest2"",
          ""isFolder"": true,
          ""key"": ""Test2\\\\InnerTest2"",
          ""isLazy"": false,
          ""children"": []
        }
      ]
    }
  ]
}</JSON>
";
            var actuals = actual.ToString().Trim();
            Assert.AreEqual(expected.Trim(), actuals);
        }
Exemple #17
0
 protected bool Equals(ServerExplorerItem other) => ResourceId.Equals(other.ResourceId);
        public void ServerExplorerRepository_CreateItem_FileSystemException_ExpectErrorMessageFromException()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock<IResourceCatalog>();
            var factory = new Mock<IExplorerItemFactory>();
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false);
            dir.Setup(a => a.CreateIfNotExists(It.IsAny<string>())).Throws(new FileNotFoundException("bobe"));
            var sync = new Mock<IExplorerRepositorySync>();
            var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper());
            var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom,
                                              "/bob/dave");

            //------------Execute Test---------------------------
            var result = serverExplorerRepository.AddItem(item, Guid.NewGuid());
            //------------Assert Results-------------------------
            Assert.AreEqual(result.Message, "bobe");
            Assert.AreEqual(result.Status, ExecStatus.Fail);
            dir.Verify(a => a.Exists(It.IsAny<string>()));
            dir.Verify(a => a.CreateIfNotExists(It.IsAny<string>()));

        }
 public void AddResouceItem(IContextualResourceModel resourceModel)
 {
     var explorerItemModel = new ServerExplorerItem { ResourcePath = resourceModel.Category, DisplayName = resourceModel.DisplayName, ResourceId = resourceModel.ID, Permissions = resourceModel.UserPermissions,ServerId = resourceModel.Environment.ID};
     ResourceType resourceType;
     Enum.TryParse(resourceModel.ServerResourceType, out resourceType);
     explorerItemModel.ResourceType = resourceType;
     ItemAddedMessageHandler(explorerItemModel);
 }
 public IExplorerItem BuildRoot()
 {
     ServerExplorerItem serverExplorerItem = new ServerExplorerItem(RootName, Guid.Empty, ResourceType.Server, new List<IExplorerItem>(), _authService.GetResourcePermissions(Guid.Empty), "") { ServerId = HostSecurityProvider.Instance.ServerID, WebserverUri = EnvironmentVariables.WebServerUri };
     return serverExplorerItem;
 }
        public void StudioResourceRepository_ShowVersionHistory_NoItemsReturned_InfoItemAttachedToParent()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            mockVersionRepository.Setup(m => m.GetVersions(It.IsAny<Guid>())).Returns(new List<IExplorerItem>());

            var superWFId = Guid.NewGuid();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = superWFId,
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };

            SetupEnvironmentRepo(Guid.Empty);

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };
            //------------Execute Test---------------------------
            repo.ShowVersionHistory(Guid.Empty, superWFId);
            //------------Assert Results-------------------------
            var actual = repo.FindItemById(superWFId);
            Assert.AreEqual(1, actual.Children.Count);
            Assert.AreEqual("There is no version history to display", actual.Children[0].DisplayName);
        }
        public void MoveItem_Execute_ExpectRename()
        {
            //------------Setup for test--------------------------
            var MoveItemService = new MoveItemService();

            ServerExplorerItem item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom, "");
            var repo = new Mock<IExplorerServerResourceRepository>();
            var ws = new Mock<IWorkspace>();
            repo.Setup(a => a.MoveItem(It.IsAny<IExplorerItem>(), It.IsAny<string>(), It.IsAny<Guid>())).Returns(new ExplorerRepositoryResult(ExecStatus.Success, "")).Verifiable();

            var serializer = new Dev2JsonSerializer();
            var inputs = new Dictionary<string, StringBuilder>
                {
                    {
                        "itemToMove", serializer.SerializeToBuilder(item)
                    },
                    {
                        "newPath", new StringBuilder("bob")
                    }
                };
            ws.Setup(a => a.ID).Returns(Guid.Empty);
            MoveItemService.ServerExplorerRepo = repo.Object;
            //------------Execute Test---------------------------
            MoveItemService.Execute(inputs, ws.Object);
            //------------Assert Results-------------------------
            repo.Verify(a => a.MoveItem(It.IsAny<IExplorerItem>(), It.IsAny<string>(), It.IsAny<Guid>()));
        }
        public void StudioResourceRepository_HideHistory_ClearsChildren()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
           
            var superWFId = Guid.NewGuid();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = superWFId,
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER",
                Children = new List<IExplorerItem>
                    {
                        new ServerExplorerItem{ ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View },
                        new ServerExplorerItem{ ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View }
                    }
            };

            SetupEnvironmentRepo(Guid.Empty);

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };
            //------------Execute Test---------------------------
            repo.HideVersionHistory(Guid.Empty, superWFId);
            //------------Assert Results-------------------------
            var actual = repo.FindItemById(superWFId);
            Assert.AreEqual(0, actual.Children.Count);
        }
        public void ServerExplorerRepository_CreateItem_ValidFolder_ExpectCreatedFolder()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock<IResourceCatalog>();
            var factory = new Mock<IExplorerItemFactory>();
            var sync = new Mock<IExplorerRepositorySync>();
            sync.Setup(m => m.AddItemMessage(It.IsAny<IExplorerItem>())).Verifiable();
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false);
            dir.Setup(a => a.CreateIfNotExists(It.IsAny<string>()));
            var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper());
            var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.Folder, null, Permissions.DeployFrom,
                                              "/bob/dave");

            //------------Execute Test---------------------------
            var result = serverExplorerRepository.AddItem(item, Guid.NewGuid());
            //------------Assert Results-------------------------
            Assert.AreEqual(result.Message, "");
            Assert.AreEqual(result.Status, ExecStatus.Success);
            dir.Verify(a => a.Exists(It.IsAny<string>()));
            dir.Verify(a => a.CreateIfNotExists(It.IsAny<string>()));
            sync.Verify(m => m.AddItemMessage(It.IsAny<IExplorerItem>()), Times.Once());
        }
        public void StudioResourceRepository_DeleteVersion_TwoItemsReturned_ItemsAttachedToParent()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var v1 = new Mock<IVersionInfo>();
            v1.Setup(v => v.VersionNumber).Returns("1");
            var v2 = new Mock<IVersionInfo>();
            v2.Setup(v => v.VersionNumber).Returns("2");
            mockVersionRepository.Setup(m => m.DeleteVersion(It.IsAny<Guid>(), It.IsAny<string>()))
                .Returns(new List<IExplorerItem>
                {
                    new ServerExplorerItem { ResourceType = ResourceType.WebService, DisplayName = "v2 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View, VersionInfo = v1.Object },
                    new ServerExplorerItem { ResourceType = ResourceType.WebService, DisplayName = "v1 2012-10-10 Save", ResourceId = Guid.NewGuid(), Permissions = Permissions.View , VersionInfo = v2.Object }
                })
                .Verifiable();

            var superWFId = Guid.NewGuid();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = superWFId,
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };

            SetupEnvironmentRepo(Guid.Empty);

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };

            var versionInfo = new VersionInfo
            {
                DateTimeStamp = DateTime.Now,
                Reason = "Rollback",
                ResourceId = superWFId,
                User = "",
                VersionId = Guid.NewGuid(),
                VersionNumber = "3"
            };

            //------------Execute Test---------------------------
            repo.DeleteVersion(versionInfo, Guid.Empty);
            //------------Assert Results-------------------------
            var actual = repo.FindItemById(superWFId);
            Assert.AreEqual(2, actual.Children.Count);
            mockVersionRepository.Verify(m => m.DeleteVersion(It.IsAny<Guid>(), It.IsAny<string>()), Times.Once());
        }
        public void StudioResourceRepository_MoveItem_ParentExistsOnTree_AddedSuccessfully()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.Folder,
                DisplayName = "SUB FOLDER",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\SUB FOLDER"
            };
            var mockResourceRepo = SetupEnvironmentRepo(Guid.Empty);
            mockResourceRepo.Setup(repository => repository.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false)).Returns(new Mock<IResourceModel>().Object);
            mockResourceRepo.Setup(repository => repository.ReloadResource(It.IsAny<Guid>(), It.IsAny<Studio.Core.AppResources.Enums.ResourceType>(), It.IsAny<IEqualityComparer<IResourceModel>>(), It.IsAny<bool>()));
            // ReSharper disable ObjectCreationAsStatement
            mockExplorerResourceRepository.Setup(a => a.MoveItem(It.IsAny<IExplorerItem>(), It.IsAny<string>(), Guid.Empty)).Returns(new ExplorerRepositoryResult(ExecStatus.Success, ""));
            new StudioResourceRepository(parent, Guid.Empty, _invoke)
            // ReSharper restore ObjectCreationAsStatement
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };
            
            var studioResourceRepository = StudioResourceRepository.Instance;

            //------------Execute Test---------------------------
            var itemToMove = new ExplorerItemModel(studioResourceRepository, new Mock<IAsyncWorker>().Object,
                new Mock<IConnectControlSingleton>().Object)
                {
                    ResourcePath = "dave",
                    DisplayName = "dave\bob",
                    Children = new ObservableCollection<IExplorerItemModel> { new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, studioResourceRepository) },
                    Parent = new ExplorerItemModel { Children = new ObservableCollection<IExplorerItemModel>() }
                };
            Assert.AreEqual(itemToMove.Children.Count, 1);
            studioResourceRepository.MoveItem(itemToMove, "bob");

            mockExplorerResourceRepository.Verify(a => a.MoveItem(It.IsAny<IExplorerItem>(), "bob", Guid.Empty));
            Assert.AreEqual(itemToMove.Children.Count,0);
        }
        public void StudioResourceRepository_GetVersion_CallsVersionOnTheProxy()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            mockVersionRepository.Setup(m => m.GetVersion(It.IsAny<IVersionInfo>())).Verifiable();
            var superWFId = Guid.NewGuid();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.WorkflowService,
                DisplayName = "SuperWF",
                ResourceId = superWFId,
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };

            SetupEnvironmentRepo(Guid.Empty);

            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };

            var versionInfo = new VersionInfo
            {
                DateTimeStamp = DateTime.Now,
                Reason = "Rollback",
                ResourceId = superWFId,
                User = "",
                VersionId = Guid.NewGuid(),
                VersionNumber = "3"
            };

            //------------Execute Test---------------------------
            repo.GetVersion(versionInfo, superWFId);
            //------------Assert Results-------------------------
            mockVersionRepository.Verify(m => m.GetVersion(It.IsAny<IVersionInfo>()), Times.Once());
        }
        public void StudioResourceRepository_ItemAddedMessageHandler_ItemNotServerNode_AddedSuccessfully()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.Folder,
                DisplayName = "SUB FOLDER",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\SUB FOLDER"
            };
            var mockResourceRepo = SetupEnvironmentRepo(Guid.Empty);
            mockResourceRepo.Setup(repository => repository.FindSingle(It.IsAny<Expression<Func<IResourceModel, bool>>>(), false)).Returns(new Mock<IResourceModel>().Object);
            mockResourceRepo.Setup(repository => repository.ReloadResource(It.IsAny<Guid>(), It.IsAny<Studio.Core.AppResources.Enums.ResourceType>(), It.IsAny<IEqualityComparer<IResourceModel>>(), It.IsAny<bool>()));
            // ReSharper disable ObjectCreationAsStatement
            new StudioResourceRepository(parent, Guid.Empty, _invoke)
            // ReSharper restore ObjectCreationAsStatement
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                GetCurrentEnvironment = () => Guid.Empty
            };

            var studioResourceRepository = StudioResourceRepository.Instance;
            var before = studioResourceRepository.ExplorerItemModels[0].Children.Count();
            //------------Execute Test---------------------------
            studioResourceRepository.ItemAddedMessageHandler(new ServerExplorerItem
            {
                DisplayName = "TEST FOLDER",
                ResourcePath = "MANFOLDER\\SUB FOLDER\\TEST FOLDER",
                ResourceId = Guid.NewGuid()
            });
            var after = studioResourceRepository.ExplorerItemModels[0].Children.Count();
            //------------Assert Results-------------------------
            mockResourceRepo.Verify(repository => repository.ReloadResource(It.IsAny<Guid>(), It.IsAny<Studio.Core.AppResources.Enums.ResourceType>(), It.IsAny<IEqualityComparer<IResourceModel>>(), It.IsAny<bool>()), Times.Never());
            Assert.AreEqual(0, before);
            Assert.AreEqual(1, after);
        }
        public void ServerExplorerRepository_CreateItem_InvalidItemType_ExpectErrorResult()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock<IResourceCatalog>();
            var factory = new Mock<IExplorerItemFactory>();
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(false);
            var sync = new Mock<IExplorerRepositorySync>();
            sync.Setup(m => m.AddItemMessage(It.IsAny<IExplorerItem>())).Verifiable();
            var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper());
            var item = new ServerExplorerItem("a", Guid.NewGuid(), ResourceType.ReservedService, null, Permissions.DeployFrom,
                                              "/bob/dave");

            //------------Execute Test---------------------------
            var result = serverExplorerRepository.AddItem(item, Guid.NewGuid());
            //------------Assert Results-------------------------
            Assert.AreEqual(result.Message, "Only user resources can be added from this repository");
            Assert.AreEqual(result.Status, ExecStatus.Fail);
            sync.Verify(m => m.AddItemMessage(It.IsAny<IExplorerItem>()), Times.Never());
        }
        public void StudioResourceRepository_ItemAddedMessageHandler_ParentDoesNotExistsOnTree_NotAdded()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
            {
                ResourceType = ResourceType.Folder,
                DisplayName = "SUB FOLDER",
                ResourceId = Guid.NewGuid(),
                Permissions = Permissions.Contribute,
                ResourcePath = "MANFOLDER\\APRIL WORK\\SUB FOLDER"
            };
            SetupEnvironmentRepo(Guid.Empty);
            var repo = new StudioResourceRepository(parent, Guid.Empty, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                    GetCurrentEnvironment = () => Guid.Empty
                };

            repo.GetCurrentEnvironment = () => Guid.Empty;

            var studioResourceRepository = StudioResourceRepository.Instance;
            var before = studioResourceRepository.ExplorerItemModels[0].Children.Count();
            //------------Execute Test---------------------------
            studioResourceRepository.ItemAddedMessageHandler(new ServerExplorerItem
            {
                DisplayName = "TEST FOLDER",
                ResourcePath = "MANFOLDER\\APRIL\\TEST FOLDER"
            });

            var after = studioResourceRepository.ExplorerItemModels[0].Children.Count();
            //------------Assert Results-------------------------
            Assert.AreEqual(0, before);
            Assert.AreEqual(0, after);
        }
        public void StudioResourceRepository_ItemAddedMessageHandler_ItemNotFoundInResourceRepo_Workflow_AddedSuccessfully()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            var mockVersionRepository = new Mock<IVersionRepository>();
            var parent = new ServerExplorerItem
                {
                    ResourceType = ResourceType.Folder,
                    DisplayName = "SUB FOLDER",
                    ResourceId = Guid.NewGuid(),
                    Permissions = Permissions.Contribute,
                    ResourcePath = "MANFOLDER\\SUB FOLDER"
                };
            var mockResourceRepo = SetupEnvironmentRepo(Guid.Empty);
            mockResourceRepo.Setup(repository => repository.ReloadResource(It.IsAny<Guid>(), It.Is<Studio.Core.AppResources.Enums.ResourceType>(type => type == Studio.Core.AppResources.Enums.ResourceType.WorkflowService), It.IsAny<IEqualityComparer<IResourceModel>>(), It.IsAny<bool>()));
            // ReSharper disable ObjectCreationAsStatement
            new StudioResourceRepository(parent, Guid.Empty, _invoke)
                // ReSharper restore ObjectCreationAsStatement
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object,
                    GetCurrentEnvironment = () => Guid.Empty
                };

            var studioResourceRepository = StudioResourceRepository.Instance;
            //------------Execute Test---------------------------
            studioResourceRepository.ItemAddedMessageHandler(new ServerExplorerItem
                {
                    DisplayName = "TEST FOLDER",
                    ResourcePath = "MANFOLDER\\SUB FOLDER\\TEST FOLDER",
                    ResourceType = ResourceType.WorkflowService
                });

            //------------Assert Results-------------------------
            mockResourceRepo.Verify(repository => repository.ReloadResource(It.IsAny<Guid>(), It.Is<Studio.Core.AppResources.Enums.ResourceType>(type => type == Studio.Core.AppResources.Enums.ResourceType.WorkflowService), It.IsAny<IEqualityComparer<IResourceModel>>(), It.IsAny<bool>()), Times.Once());
        }
 public ServerExplorerItem CreateResourceItem(IResource resource)
 {
     Guid resourceId = resource.ResourceID;
     var childNode = new ServerExplorerItem(resource.ResourceName, resourceId, resource.ResourceType == ResourceType.Server ? ResourceType.ServerSource : resource.ResourceType, null,
                                            _authService.GetResourcePermissions(resourceId), resource.ResourcePath);
     return childNode;
 }