Inheritance: IStudioResourceRepository
        protected StudioResourceRepository CreateModels(bool isChecked, Mock<IContextualResourceModel> mockResourceModel, out IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm, out IExplorerItemModel rootItem)
        {
            Mock<IContextualResourceModel> resourceModel = mockResourceModel;

            var connection = new Mock<IEnvironmentConnection>();

            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object);
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(new Mock<IAuthorizationService>().Object);
            environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            rootItem = serverItemModel;
            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = ResourceType.Folder, ResourcePath = "WORKFLOWS", EnvironmentId = mockEnvironmentModel.Object.ID, ResourceId = Guid.NewGuid() };
            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, _Invoke);
            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            resourceVm = workflowsFolder.Children[0];
            resourceVm.IsChecked = isChecked;
            return studioResourceRepository;
        }
        public void StudioResourceRepository_AddItem_AttachedToParent_AddCalledOnServer()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success"));
            var mockVersionRepository = new Mock<IVersionRepository>();
            SetupEnvironmentRepo(Guid.Empty);

            var repository = new StudioResourceRepository(GetTestData(), Guid.Empty, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object
                };
            var parent = repository.ExplorerItemModels[0].Children[0];

            var environmentId = Guid.NewGuid();
            var folderId = Guid.NewGuid();

            var folder1 = new ExplorerItemModel
            {
                Parent = parent,
                DisplayName = "subFolder 1",
                EnvironmentId = environmentId,
                Permissions = Permissions.Contribute,
                ResourceId = folderId,
            };
            //------------Execute Test---------------------------
            repository.AddItem(folder1);
            //------------Assert Results-------------------------
            mockExplorerResourceRepository.Verify(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()), Times.Once());
        }
 static StudioResourceRepository()
 {
     Instance = new StudioResourceRepository();
 }
        public void StudioResourceRepository_Disconnect_PublishesRemoveEnvironmentMessage_ServerIsDisconnectedAndChildrenAreCollapsed()
        {
            //------------Setup for test--------------------------
            var aggregator = new Mock<EventAggregator>();
            IEnvironmentModel actualEnvironmentInvoked = null;
            aggregator.Setup(a => a.Publish(It.IsAny<RemoveEnvironmentMessage>())).Callback<object>(msg =>
            {
                var workSurfaceObject = (msg is RemoveEnvironmentMessage) ? (msg as RemoveEnvironmentMessage).EnvironmentModel : null;
                actualEnvironmentInvoked = workSurfaceObject;
            });

            EventPublishers.Aggregator = aggregator.Object;

            var environmentId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);

            var repository = new StudioResourceRepository(GetTestData(), environmentId, _invoke);
            //------------Execute Test---------------------------
            var countBeforeDisconnect = repository.ExplorerItemModels[0].Children.Count;
            var isConnectedBeforeDisconnect = repository.ExplorerItemModels[0].IsConnected;
            repository.Disconnect(environmentId);
            var countAfterDisconnect = repository.ExplorerItemModels[0].Children.Count;
            var isConnectedAfterDisconnect = repository.ExplorerItemModels[0].IsConnected;
            //------------Assert Results-------------------------
            Assert.AreEqual(2, countBeforeDisconnect);
            Assert.AreEqual(0, countAfterDisconnect);
            Assert.AreEqual(true, isConnectedBeforeDisconnect);
            Assert.AreEqual(false, isConnectedAfterDisconnect);
            Assert.IsNull(actualEnvironmentInvoked);
        }
        public void StudioResourceRepository_DeleteItem_ItemParentNull_Exception()
        {
            //------------Setup for test--------------------------
            var _propertyChangedCalled = false;
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                          .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success"))
                                          .Verifiable();

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            var folderID = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString(), folderID: folderID), environmentId, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object
            };

            var folderItem = repository.FindItemById(folderID);

            ExplorerItemModel item = folderItem.Parent as ExplorerItemModel;
            // ReSharper disable PossibleNullReferenceException
            item.PropertyChanged += (sender, args) =>
            // ReSharper restore PossibleNullReferenceException
            {
                if(args.PropertyName == "ChildrenCount")
                {
                    _propertyChangedCalled = true;
                }
            };
            //------------Execute Test---------------------------
            ExplorerItemModel explorerItemModel = new ExplorerItemModel();
            repository.DeleteItem(explorerItemModel);
            //------------Assert Results-------------------------
            Assert.IsFalse(_propertyChangedCalled);
        }
 public void StudioResourceRepository_DeleteFolder_ExplorerItemModelIsNull_ThrowsException()
 {
     //------------Setup for test--------------------------
     var repository = new StudioResourceRepository(null, Guid.Empty, _invoke);
     //------------Execute Test---------------------------
     repository.DeleteItem(null);
 }
 public void StudioResourceRepository_Constructor_ExplorerItemHasData_ExplorerItemCollectionHasData()
 {
     AppSettings.LocalHost = "http://localhost:3142/";
     var repository = new StudioResourceRepository(GetTestData(), Guid.Empty, _invoke);
     Assert.AreEqual(1, repository.ExplorerItemModels.Count);
 }
        public void StudioResourceRepository_DeleteFolder_ItemIsOnExplorerItemModels_CallsDeleteOnService()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                          .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success"))
                                          .Verifiable();

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object
                };
            //------------Execute Test---------------------------
            var explorerItemModel = repository.ExplorerItemModels[0].Children[0];
            repository.DeleteFolder(explorerItemModel);
            //------------Assert Results-------------------------
            mockExplorerResourceRepository.Verify(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()), Times.Once());
        }
        public void StudioResourceRepository_DeleteFolder_EnvironmentIdDoesnotExists_ThrowsException()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>())).Verifiable();

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object
                };
            //------------Execute Test---------------------------
            repository.DeleteItem(Guid.NewGuid(), workflowId);
        }
        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_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_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 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 StudioResourceRepository_Filter_NullString_ReturnsSourceItems()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     var explorerItem = GetTestData();
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(explorerItem, Guid.Empty, _invoke)
         {
             GetVersionProxy = id => mockVersionRepository.Object,
             GetExplorerProxy = id => mockExplorerResourceRepository.Object
         };
     //------------Execute Test---------------------------
     var explorerItemModels = repository.Filter(null);
     //------------Assert Results-------------------------
     Assert.IsNotNull(explorerItemModels);
     Assert.AreEqual(explorerItemModels[0].DisplayName, repository.ExplorerItemModels[0].DisplayName);
     Assert.AreEqual(explorerItemModels[0].Children.Count, repository.ExplorerItemModels[0].Children.Count);
 }
 public void StudioResourceRepository_ShowVersionHistory_CallsGetVersionFromProxy()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     var mockVersionRepository = new Mock<IVersionRepository>();
     mockVersionRepository.Setup(m => m.GetVersions(It.IsAny<Guid>())).Verifiable();
     SetupEnvironmentRepo(Guid.Empty);
     var repo = new StudioResourceRepository(null, Guid.Empty, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object,
         GetCurrentEnvironment = () => Guid.Empty
     };
     //------------Execute Test---------------------------
     repo.ShowVersionHistory(Guid.NewGuid(), Guid.NewGuid());
     //------------Assert Results-------------------------
     mockVersionRepository.Verify(m => m.GetVersions(It.IsAny<Guid>()), Times.Once());
 }
 public void StudioResourceRepository_Constructor_ExplorerItemIsNull_ExplorerItemCollectionHasZeroItems()
 {
     AppSettings.LocalHost = "http://localhost:3145";
     var repo = new StudioResourceRepository(null, Guid.Empty, _invoke);
     Assert.AreEqual(0, repo.ExplorerItemModels.Count);
 }
        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);
        }
        public void StudioResourceRepository_DeleteFolder_ItemIsNotOnExplorerItemModels_DoesNotCallsDeleteOnService()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>())).Verifiable();

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object
                };
            //------------Execute Test---------------------------
            repository.DeleteFolder(new ExplorerItemModel());
            //------------Assert Results-------------------------
            mockExplorerResourceRepository.Verify(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()), Times.Never());
        }
        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_DeleteFolder_DeleteServiceReturnsAnError_ThrowsAnException()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                          .Returns(new ExplorerRepositoryResult(ExecStatus.Fail, "Just Failed"));

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            var folderID = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString(), folderID: folderID), environmentId, _invoke)
            {
                GetVersionProxy = id => mockVersionRepository.Object,
                GetExplorerProxy = id => mockExplorerResourceRepository.Object
            };
            //------------Execute Test---------------------------
            var explorerItemModel = repository.ExplorerItemModels[0].Children[0];
            repository.DeleteFolder(explorerItemModel);
        }
 public void StudioResourceRepository_FilterDialog_NullAfterFilter_ReturnsOriginalCollection()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     var explorerItem = GetTestData();
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(explorerItem, Guid.Empty, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object
     };
     //------------Preconditions--------------------------
     Assert.AreEqual(4, repository.ExplorerItemModels[0].ChildrenCount);
     var explorerItemModels = repository.Filter(model => model.DisplayName.Contains("r1"));
     Assert.AreEqual(0, explorerItemModels[0].ChildrenCount);
     Assert.AreEqual(1, explorerItemModels[0].Children.Count);
     //------------Execute Test---------------------------
     repository.Filter(null);
     //------------Assert Results-------------------------
     Assert.AreEqual(4, repository.ExplorerItemModels[0].ChildrenCount);
 }
 public void StudioResourceRepository_DeleteFolder_DeleteServiceThrowsAndException_ReThrowsAnException()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                   .Throws(new Exception("Something really bad happened, reboot your PC or risk a Harddrive crash"));
     var environmentId = Guid.NewGuid();
     var workflowId = Guid.NewGuid();
     SetupEnvironmentRepo(environmentId);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object
     };
     //------------Execute Test---------------------------
     var explorerItemModel = repository.ExplorerItemModels[0].Children[0];
     repository.DeleteFolder(explorerItemModel);
 }
 public void StudioResourceRepository_FilterDialog_String_Multiple_ReturnsMatchingItems()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     var explorerItem = GetTestData();
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(explorerItem, Guid.Empty, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object
     };
     //------------Execute Test---------------------------
     var explorerItemModels = repository.DialogFilter(model => model.DisplayName.Contains("r1"));
     //------------Assert Results-------------------------
     Assert.IsNotNull(explorerItemModels);
     Assert.AreEqual(explorerItemModels[0].DisplayName, repository.ExplorerItemModels[0].DisplayName);
     Assert.AreNotEqual(explorerItemModels[0].Children.Count, repository.ExplorerItemModels[0].Children.Count);
     Assert.AreEqual(1, explorerItemModels[0].Children.Count);
     Assert.AreEqual("folder1", explorerItemModels[0].Children[0].DisplayName);
     Assert.AreEqual("subfolder1", explorerItemModels[0].Children[0].Children[0].DisplayName);
 }
        public void StudioResourceRepository_Load_CallsServiceLoad()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     
            // ReSharper disable MaximumChainedReferences
            mockExplorerResourceRepository.Setup(m => m.Load(It.IsAny<Guid>()))
                                          .Returns(new ServerExplorerItem { DisplayName = "some name" })
                                          .Verifiable();
           

            var mockVersionRepository = new Mock<IVersionRepository>();

            SetupEnvironmentRepo(Guid.Empty);

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

            var mockResourceRepository = new Mock<IResourceRepository>();
            Mock<IEnvironmentModel> mockEnvironment = EnviromentRepositoryTest.CreateMockEnvironment(mockResourceRepository.Object, "localhost");
            mockEnvironment.Setup(model => model.ID).Returns(Guid.Empty);
            GetEnvironmentRepository(mockEnvironment);

            //------------Execute Test---------------------------
            repository.Load(Guid.Empty, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object);
            //------------Assert Results-------------------------
            mockExplorerResourceRepository.Verify(m => m.Load(It.IsAny<Guid>()), Times.Never());
        }
 public void StudioResourceRepository_AddItem_CallsServiceAddItem()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     mockExplorerResourceRepository.Setup(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                   .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success"))
                                   .Verifiable();
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(null, Guid.Empty, _invoke)
         {
             GetVersionProxy = id => mockVersionRepository.Object,
             GetExplorerProxy = id => mockExplorerResourceRepository.Object
         };
     //------------Execute Test---------------------------
     repository.AddItem(new ExplorerItemModel { Parent = new ExplorerItemModel() });
     //------------Assert Results-------------------------
     mockExplorerResourceRepository.Verify(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()), Times.Once());
 }
        public void StudioResourceRepository_Disconnect_ServerHasChildren_ServerIsDisconnectedAndChildrenAreCollapsed()
        {
            //------------Setup for test--------------------------
            var environmentId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);

            var repository = new StudioResourceRepository(GetTestData(), environmentId, _invoke);
            //------------Execute Test---------------------------
            var countBeforeDisconnect = repository.ExplorerItemModels[0].Children.Count;
            var isConnectedBeforeDisconnect = repository.ExplorerItemModels[0].IsConnected;
            repository.Disconnect(environmentId);
            var countAfterDisconnect = repository.ExplorerItemModels[0].Children.Count;
            var isConnectedAfterDisconnect = repository.ExplorerItemModels[0].IsConnected;
            //------------Assert Results-------------------------
            Assert.AreEqual(2, countBeforeDisconnect);
            Assert.AreEqual(0, countAfterDisconnect);
            Assert.AreEqual(true, isConnectedBeforeDisconnect);
            Assert.AreEqual(false, isConnectedAfterDisconnect);
        }
 public void StudioResourceRepository_AddItem_ServiceReturnsAndError_ThrowsAnException()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     mockExplorerResourceRepository.Setup(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                   .Returns(new ExplorerRepositoryResult(ExecStatus.Fail, "Just Failed"));
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(null, Guid.Empty, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object
     };
     //------------Execute Test---------------------------
     repository.AddItem(new ExplorerItemModel { Parent = new ExplorerItemModel() });
 }
 public void StudioResourceRepository_RemoveEnvironment_ServerHasChildren_ServerIsRemovedFromTree()
 {
     //------------Setup for test--------------------------
     var environmentId = Guid.NewGuid();
     SetupEnvironmentRepo(environmentId);
     var repository = new StudioResourceRepository(GetTestData(), environmentId, _invoke);
     //------------Execute Test---------------------------
     var countBeforeDisconnect = repository.ExplorerItemModels.Count;
     repository.RemoveEnvironment(environmentId);
     var countAfterDisconnect = repository.ExplorerItemModels.Count;
     //------------Assert Results-------------------------
     Assert.AreEqual(1, countBeforeDisconnect);
     Assert.AreEqual(0, countAfterDisconnect);
 }
 public void StudioResourceRepository_AddItem_ServiceThrowsAnException_ReThrowsAnException()
 {
     //------------Setup for test--------------------------
     var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
     mockExplorerResourceRepository.Setup(m => m.AddItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                                   .Throws(new Exception("Something really bad happened, reboot your PC or risk a Harddrive crash"));
     SetupEnvironmentRepo(Guid.Empty);
     var mockVersionRepository = new Mock<IVersionRepository>();
     var repository = new StudioResourceRepository(null, Guid.Empty, _invoke)
     {
         GetVersionProxy = id => mockVersionRepository.Object,
         GetExplorerProxy = id => mockExplorerResourceRepository.Object
     };
     //------------Execute Test---------------------------
     repository.AddItem(new ExplorerItemModel { Parent = new ExplorerItemModel() });
 }
        protected static StudioResourceRepository CreateModels(bool isChecked, IEnvironmentModel environmentModel, out IExplorerItemModel resourceVm)
        {
            Mock<IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, Guid.NewGuid());
            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = Common.Interfaces.Data.ResourceType.Server, EnvironmentId = environmentModel.ID, ResourceId = Guid.NewGuid(), ResourcePath = "" };

            ExplorerItemModel workflowsFolder = new ExplorerItemModel { DisplayName = "WORKFLOWS", ResourceType = Common.Interfaces.Data.ResourceType.Folder, ResourcePath = "WORKFLOWS", ResourceId = Guid.NewGuid(), EnvironmentId = environmentModel.ID };

            serverItemModel.Children.Add(workflowsFolder);

            var studioResourceRepository = new StudioResourceRepository(serverItemModel, Invoke);

            resourceModel.Setup(model => model.Category).Returns("WORKFLOWS\\" + resourceModel.Object.DisplayName);
            resourceModel.Setup(a => a.ServerID).Returns(environmentModel.ID);
            var env = new Mock<IEnvironmentModel>();
            resourceModel.Setup(a => a.Environment).Returns(env.Object);
            env.Setup(a => a.ID).Returns(environmentModel.ID);
            TestEnvironmentRespository testEnvironmentRespository = new TestEnvironmentRespository(environmentModel);
            // ReSharper disable ObjectCreationAsStatement
            new EnvironmentRepository(testEnvironmentRespository);
            // ReSharper restore ObjectCreationAsStatement
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            resourceVm = workflowsFolder.Children[0];
            resourceVm.IsChecked = isChecked;
            return studioResourceRepository;
        }
        public void StudioResourceRepository_DeleteFolder_HasWorkflow_WorkflowIsRemoved()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            mockExplorerResourceRepository.Setup(m => m.DeleteItem(It.IsAny<IExplorerItem>(), It.IsAny<Guid>()))
                               .Returns(new ExplorerRepositoryResult(ExecStatus.Success, "Success"));

            var environmentId = Guid.NewGuid();
            var workflowId = Guid.NewGuid();
            SetupEnvironmentRepo(environmentId);
            var repository = new StudioResourceRepository(GetTestData(workflowId.ToString()), environmentId, _invoke);
            var beforeDelete = repository.ExplorerItemModels[0].Children.Count;
            repository.GetExplorerProxy = id => mockExplorerResourceRepository.Object;
            //------------Execute Test---------------------------
            repository.DeleteItem(environmentId, workflowId);
            var afterDelete = repository.ExplorerItemModels[0].Children.Count;
            //------------Assert Results-------------------------
            Assert.AreEqual(beforeDelete, 2);
            Assert.AreEqual(afterDelete, 1);
        }