Наследование: ObservableObject, IExplorerItemModel
        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 EnvironmentTreeViewModel_PermissionsChanged_DeployToTrue_ChildrenIsNotCleared()
        {
            var connection = CreateConnection();
            connection.Setup(c => c.IsAuthorized).Returns(true);
            var authorizationService = new Mock<IAuthorizationService>();
            authorizationService.Setup(e => e.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(true);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            mockEnvironmentModel.SetupGet(x => x.Connection.AppServerUri).Returns(new Uri("http://127.0.0.1/"));
            mockEnvironmentModel.Setup(model => model.Equals(It.IsAny<IEnvironmentModel>())).Returns(true);
            mockEnvironmentModel.Setup(e => e.IsAuthorized).Returns(true);
            mockEnvironmentModel.Setup(model => model.AuthorizationService).Returns(authorizationService.Object);
            mockEnvironmentModel.Setup(model => model.Connection).Returns(connection.Object);

            var environmentVm = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, StudioResourceRepository.Instance);

            var child = new Mock<IExplorerItemModel>().Object;
            environmentVm.Children.Add(child);
            environmentVm.Children.Add(child);
            environmentVm.Children.Add(child);

            authorizationService.Setup(e => e.IsAuthorized(AuthorizationContext.DeployTo, null)).Returns(true);
            connection.Raise(c => c.PermissionsChanged += null, EventArgs.Empty);

            Assert.AreEqual(3, environmentVm.Children.Count);
        }
 public void ExplorerItemModel_Constructor_HasChildrenCollectionInstantiated()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var explorerItemModel = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object);
     //------------Assert Results-------------------------
     Assert.IsNotNull(explorerItemModel);
     Assert.IsNotNull(explorerItemModel.Children);
     Assert.AreEqual(0, explorerItemModel.ChildrenCount);
 }
 //This is for testing only need better way of putting this together
 internal StudioResourceRepository(ExplorerItemModel explorerItem, Action<System.Action, DispatcherPriority> invoke)
 {
     ExplorerItemModelClone = a => a.Clone();
     ExplorerItemModels = new ObservableCollection<IExplorerItemModel>();
     _invoke = invoke;
     if(explorerItem != null)
     {
         LoadItemsToTree(explorerItem.EnvironmentId, explorerItem);
         Instance = this;
     }
 }
        public void DeployStatsCalculator_Calculate_HasFolders_Expect_NoFoldersCounted()
        {
            //------------Setup for test--------------------------

            var conn = new Mock<IConnectControlSingleton>().Object;
            var studio = new Mock<IStudioResourceRepository>().Object;
            ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(conn,studio){ResourceType = ResourceType.Folder,IsChecked = true};
            IEnvironmentModel environmentModel = Dev2MockFactory.SetupEnvironmentModel().Object;
            bool actual = DeployStatsCalculator.DeploySummaryPredicateNew(navigationItemViewModel, environmentModel);
            Assert.IsFalse(actual);
        }
        // ReSharper disable once InconsistentNaming
        public void ExplorerView_Move_FolderExpectRename()
        {
            //------------Setup for test--------------------------
            var stud = new Mock<IStudioResourceRepository>();
            var model1 = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.Folder, ResourcePath = "bob" };
            var model2 = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.Folder, ResourcePath = "dave", Parent = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourcePath = "moo" } };
            stud.Setup(a => a.MoveItem(model1, "bob"));
            ExplorerView.MoveItem(model1, model2, stud.Object);

            //------------Execute Test---------------------------
            stud.Verify(a => a.MoveItem(model1, "dave"));
            //------------Assert Results-------------------------
        }
 public void ExplorerItemModel_Constructor_Has4ChildrenCount()
 {
     //------------Setup for test--------------------------
     //------------Execute Test---------------------------
     var connectControlSingleton = new Mock<IConnectControlSingleton>().Object;
     var explorerItemModel = new ExplorerItemModel(connectControlSingleton, new Mock<IStudioResourceRepository>().Object);
     explorerItemModel.Children.Add(new ExplorerItemModel(connectControlSingleton, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.WorkflowService });
     explorerItemModel.Children.Add(new ExplorerItemModel(connectControlSingleton, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.WorkflowService });
     explorerItemModel.Children.Add(new ExplorerItemModel(connectControlSingleton, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.WorkflowService });
     explorerItemModel.Children.Add(new ExplorerItemModel(connectControlSingleton, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.WorkflowService });
     //------------Assert Results-------------------------
     Assert.IsNotNull(explorerItemModel);
     Assert.IsNotNull(explorerItemModel.Children);
     Assert.AreEqual(4, explorerItemModel.ChildrenCount);
 }
Пример #8
0
 public void DragDropHelpers_PreventDrop_DataContextViewModelSameEnvironmentID_ReturnsFalse()
 {
     //------------Setup for test--------------------------
     var environmentMock = new Mock<IEnvironmentModel>();
     Guid guid = Guid.NewGuid();
     environmentMock.Setup(model => model.ID).Returns(guid);
     var data = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { Permissions = Permissions.Execute, ResourceType = ResourceType.DbService, EnvironmentId = environmentMock.Object.ID };
     var dataContext = new Mock<IWorkflowDesignerViewModel>();
     dataContext.Setup(model => model.EnvironmentModel).Returns(environmentMock.Object);
     var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext.Object));
     //------------Execute Test---------------------------
     bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data));
     //------------Assert Results-------------------------
     Assert.IsFalse(canDoDrop);
 }
        // ReSharper disable once InconsistentNaming
        public void ExplorerView_Move_FolderExpectPopup()
        {
            //------------Setup for test--------------------------
            var stud = new Mock<IStudioResourceRepository>();
            var popup = new Mock<IPopupController>();
            CustomContainer.Register(popup.Object);
            var model1 = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.Folder, ResourcePath = "bob",EnvironmentId = Guid.NewGuid()};
            var model2 = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourceType = ResourceType.Folder, ResourcePath = "dave", Parent = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { ResourcePath = "moo" } };
            stud.Setup(a => a.MoveItem(model1, "bob"));
            ExplorerView.MoveItem(model1, model2, stud.Object);

            //------------Execute Test---------------------------
            popup.Verify(a=>a.Show());
            popup.VerifySet(a => a.Description = "You are not allowed to move items between Servers using the explorer. Please use the deploy instead");
            //------------Assert Results-------------------------
        }
Пример #10
0
        public static void MoveItem(ExplorerItemModel source, ExplorerItemModel destination, IStudioResourceRepository rep)
        {
            if (source != null)
            {
                if(source.EnvironmentId != destination.EnvironmentId)
                {
                    var popup = CustomContainer.Get<IPopupController>();
                    popup.Description = "You are not allowed to move items between Servers using the explorer. Please use the deploy instead";
                    popup.Buttons = MessageBoxButton.OK;
                    popup.Header = "Invalid Action";
                    popup.ImageType = MessageBoxImage.Error;
                    popup.Show();

                }
                else
                switch (destination.ResourceType)
                {
                    case ResourceType.Folder:
                    case ResourceType.Server:
                        rep.MoveItem(source, destination.ResourcePath);
                        break;
                    default:
                        rep.MoveItem(source, destination.Parent.ResourcePath);
                        break;
                }
            }
        }
        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);
        }
Пример #12
0
        public void DragDropHelpers_PreventDrop_UserIsAuthorized_False()
        {
            //------------Setup for test--------------------------
            var data = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { Permissions = Permissions.Execute, ResourceType = ResourceType.WorkflowService };

            var dataContext = new Mock<IWorkflowDesignerViewModel>();
            var differentEnvironment = new Mock<IEnvironmentModel>();
            differentEnvironment.Setup(model => model.ID).Returns(Guid.Empty);
            dataContext.Setup(model => model.EnvironmentModel).Returns(differentEnvironment.Object);
            var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext.Object));

            //------------Execute Test---------------------------
            var canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data));

            //------------Assert Results-------------------------
            Assert.IsFalse(canDoDrop);
        }
        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 NavigationItemViewModelMouseDownBehavior_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsOne_PublishesEvent()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = true };

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

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_TreecodeIsNotResourceTreeViewModel_PublishEventsCorrectly()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
        static void Verify_OnMouseDown_SelectOnRightClick(bool selectOnRightClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { SelectOnRightClick = selectOnRightClick };

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            Assert.AreEqual(selectOnRightClick, explorerItemModel.IsExplorerSelected);
        }
Пример #17
0
        public void WhenIDeleteTheResource(string resourceToDelete)
        {
            var localhost = Guid.Empty;

            ExecuteService(() =>
            {
                var repository = ScenarioContext.Current.Get<StudioResourceRepository>("repository");
                repository.Load(localhost, new TestAsyncWorker());
                var resourcePath = ScenarioContext.Current.Get<string>("path");
                var displayName = resourcePath.Split("\\".ToArray()).Last();
                var parent = repository.FindItem(i => i.DisplayName == displayName);
                Assert.IsNotNull(parent,string.Format("Did not find {0}", displayName));
                var child = parent.Children.FirstOrDefault(c => c.DisplayName == resourceToDelete);

                if(child == null)
                {
                    child = new ExplorerItemModel
                        {
                            Parent = parent,
                            DisplayName = resourceToDelete,
                            ResourcePath = resourcePath + "\\" + resourceToDelete,
                            Permissions = SecPermissions.Contribute
                        };
                    parent.Children.Add(child);
                }

                string errorMessage = "";
                var hasError = false;

                try
                {
                    repository.DeleteFolder(child);
                }
                catch(Exception exception)
                {
                    errorMessage = exception.Message;
                    hasError = true;
                }

                ScenarioContext.Current.Add("errorMessage", errorMessage);
                ScenarioContext.Current.Add("hasError", hasError);
            });
        }
Пример #18
0
        public void WhenIRenameTheResourceTo(string oldResourceName, string newResourceName)
        {
            var workingDirectory = ScenarioContext.Current.Get<string>("workingDirectory");
            var resourceName = workingDirectory + @"\" + oldResourceName;
            var extension = Path.GetExtension(resourceName);
            if(string.IsNullOrEmpty(extension))
            {
                Directory.CreateDirectory(resourceName);
            }
            else
            {
                File.Create(resourceName);
            }

            var localhost = Guid.Empty;

            ExecuteService(() =>
            {
                var repository = ScenarioContext.Current.Get<StudioResourceRepository>("repository");
                repository.Load(localhost, new TestAsyncWorker());
                var resourcePath = ScenarioContext.Current.Get<string>("path");
                var displayName = resourcePath.Split("\\".ToArray()).Last();
                var parent = repository.FindItem(i => i.DisplayName == displayName);
                if(parent.Children != null)
                {
                    var child = parent.Children.FirstOrDefault(c => c.DisplayName == oldResourceName);
                    var hasError = false;

                    if(child == null)
                    {
                        child = new ExplorerItemModel
                        {
                            Parent = parent,
                            DisplayName = oldResourceName,
                            ResourcePath = resourcePath + "\\" + displayName,
                            Permissions = SecPermissions.Contribute
                        };
                        parent.Children.Add(child);
                    }

                    string errorMessage = "";

                    try
                    {
                        repository.RenameItem(child, resourcePath + "\\" + newResourceName);
                    }
                    catch(Exception exception)
                    {
                        errorMessage = exception.Message;
                        hasError = true;
                    }

                    ScenarioContext.Current.Add("errorMessage", errorMessage);
                    ScenarioContext.Current.Add("hasError", hasError);
                }
            });
        }
        static void Verify_OnMouseDown_SetActiveEnvironmentOnClick(int publishCount, bool setActiveEnvironmentOnClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            eventPublisher.Setup(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { SetActiveEnvironmentOnClick = setActiveEnvironmentOnClick };

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>()), Times.Exactly(publishCount));
        }
Пример #20
0
        public void WorkflowDesignerViewModelTestStartNodeNotDoubleConnect()
        {
            #region Setup view model constructor parameters

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

            var crm = new Mock<IContextualResourceModel>();
            crm.Setup(r => r.Environment).Returns(env.Object);
            crm.Setup(r => r.ResourceName).Returns("Test");
            crm.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition));
            //, new Mock<IWizardEngine>().Object
            var explorerItem = new ExplorerItemModel();
            IContextualResourceModel contextualResourceModel = crm.Object;
            explorerItem.DisplayName = contextualResourceModel.ResourceName;
            explorerItem.EnvironmentId = contextualResourceModel.Environment.ID;

            var wh = new Mock<IWorkflowHelper>();

            #endregion

            #region setup Mock ModelItem

            var properties = new Dictionary<string, Mock<ModelProperty>>();
            var propertyCollection = new Mock<ModelPropertyCollection>();
            var environmentRepository = SetupEnvironmentRepo(Guid.Empty); // Set the active environment
            var testAct = DsfActivityFactory.CreateDsfActivity(contextualResourceModel, new DsfActivity(), true, environmentRepository, true);

            var prop = new Mock<ModelProperty>();
            prop.Setup(p => p.SetValue(It.IsAny<DsfActivity>())).Verifiable();
            prop.Setup(p => p.ComputedValue).Returns(testAct);
            properties.Add("Action", prop);

            propertyCollection.Protected().Setup<ModelProperty>("Find", "Action", true).Returns(prop.Object);

            var source = new Mock<ModelItem>();
            source.Setup(s => s.Properties).Returns(propertyCollection.Object);
            source.Setup(s => s.ItemType).Returns(typeof(FlowStep));

            #endregion

            #region setup mock to change properties

            //mock item adding - this is obsolote functionality but not refactored due to overhead
            var args = new Mock<ModelChangedEventArgs>();
            #pragma warning disable 618
            args.Setup(a => a.ItemsAdded).Returns(new List<ModelItem> { source.Object });
            #pragma warning restore 618

            #endregion

            //Execute
            var wfd = new WorkflowDesignerViewModelMock(contextualResourceModel, wh.Object);
            wfd.SetDataObject(explorerItem);
            wfd.TestModelServiceModelChanged(args.Object);

            wfd.Dispose();

            //Verify
            prop.Verify(p => p.SetValue(It.IsAny<DsfActivity>()), Times.Never());
        }
        static void Verify_OnMouseDown_OpenOnDoubleClick_DoesNothing(int clickCount, bool openOnDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            eventPublisher.Setup(p => p.Publish(It.IsAny<object>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = openOnDoubleClick };

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

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object) { Permissions = Permissions.Administrator };
            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, clickCount);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny<object>()), Times.Never());
        }
        public void StudioResourceRepository_AddItem_ItemNotAttachedToParent_ThrowsException()
        {
            //------------Setup for test--------------------------
            var mockExplorerResourceRepository = new Mock<IClientExplorerResourceRepository>();
            SetupEnvironmentRepo(Guid.Empty);
            var mockVersionRepository = new Mock<IVersionRepository>();
            var repository = new StudioResourceRepository(null, Guid.Empty, _invoke)
                {
                    GetVersionProxy = id => mockVersionRepository.Object,
                    GetExplorerProxy = id => mockExplorerResourceRepository.Object
                };

            var environmentId = Guid.NewGuid();
            var folderId = Guid.NewGuid();
            var explorerItemModel = new ExplorerItemModel
            {
                DisplayName = "FOLDER 1",
                EnvironmentId = environmentId,
                Permissions = Permissions.Contribute,
                ResourceId = folderId,
            };
            //------------Execute Test---------------------------
            repository.AddItem(explorerItemModel);
        }
        static void Verify_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsTwo(bool dontAllowDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = true, DontAllowDoubleClick = dontAllowDoubleClick };

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

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var editCommand = new Mock<ICommand>();
            editCommand.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(true);
            editCommand.Setup(c => c.Execute(It.IsAny<object>())).Verifiable();

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 2);

            //------------Assert Results-------------------------
            Assert.AreEqual(dontAllowDoubleClick, result);
            editCommand.Verify(c => c.Execute(It.IsAny<object>()), Times.Exactly(dontAllowDoubleClick ? 0 : 1));
        }
        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);
        }
Пример #25
0
        public void DragDropHelpers_PreventDrop_LocalResourceOnRemoteDesignSurface_ReturnsFalse()
        {
            //------------Setup for test--------------------------
            var data = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { Permissions = Permissions.Execute, ResourceType = ResourceType.WorkflowService,EnvironmentId = Guid.NewGuid()};
            var dataContext = new Mock<IWorkflowDesignerViewModel>();

            var differentEnvironment = new Mock<IEnvironmentModel>();
            differentEnvironment.Setup(model => model.ID).Returns(Guid.Empty);
            dataContext.Setup(model => model.EnvironmentModel).Returns(differentEnvironment.Object);
            differentEnvironment.Setup(a => a.IsLocalHost).Returns(false);
            var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext.Object));
            CustomContainer.Register(new Mock<IPopupController>().Object);
            //------------Execute Test---------------------------
            bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data));
            //------------Assert Results-------------------------
            Assert.IsTrue(canDoDrop);
        }
        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());
        }
Пример #27
0
        public void DragDropHelpers_PreventDrop_UserIsNotAuthorized_True()
        {
            //------------Setup for test--------------------------
            var data = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { Permissions = Permissions.View, ResourceType = ResourceType.WorkflowService };

            var dataContext = new object();
            var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext));

            //------------Execute Test---------------------------
            var canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data));

            //------------Assert Results-------------------------
            Assert.IsTrue(canDoDrop);
        }
        public void StudioResourceRepository_AddResourceItem_ItemAdded()
        {
            //------------Setup for test--------------------------
            Mock<IContextualResourceModel> resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(model => model.DisplayName).Returns("some resource name");
            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);
            var environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            var 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);
            new EnvironmentRepository(testEnvironmentRespository);
            resourceModel.Setup(a => a.Environment).Returns(mockEnvironmentModel.Object);
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            //------------Execute Test---------------------------
            studioResourceRepository.AddResouceItem(resourceModel.Object);
            //------------Assert Results-------------------------
            Assert.AreEqual(1, rootItem.Children.Count);
            Assert.AreEqual(1, rootItem.Children[0].Children.Count);
        }
Пример #29
0
        public void DragDropHelpers_PreventDrop_FormatOfWorkflowItemTypeNameFormat_ReturnsFalse()
        {
            //------------Setup for test--------------------------
            object dataContext = new object();
            var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext));

            var data = new ExplorerItemModel(new Mock<IConnectControlSingleton>().Object, new Mock<IStudioResourceRepository>().Object) { Permissions = Permissions.Execute, ResourceType = ResourceType.DbService };
            //------------Execute Test---------------------------
            bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "WorkflowItemTypeNameFormat" }, data));
            //------------Assert Results-------------------------
            Assert.IsFalse(canDoDrop);
        }
        public void StudioResourceRepository_AddServerNode_Existing_ItemExpandedAndSelected()
        {
            //------------Setup for test--------------------------
            Mock<IContextualResourceModel> resourceModel = new Mock<IContextualResourceModel>();
            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);
            var environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List<IResourceModel>()).Object;

            var serverItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server, EnvironmentId = environmentModel.ID, ResourcePath = "", ResourceId = Guid.NewGuid() };
            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);
            new EnvironmentRepository(testEnvironmentRespository);
            IEnvironmentModel internalEnvironmentModel = environmentModel;
            studioResourceRepository.GetCurrentEnvironment = () => internalEnvironmentModel.ID;
            ExplorerItemModel serverExplorerItem = new ExplorerItemModel(studioResourceRepository, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, new Mock<IConnectControlSingleton>().Object) { EnvironmentId = Guid.NewGuid(), ResourceType = ResourceType.Server };
            studioResourceRepository.AddServerNode(serverExplorerItem);
            //------------Execute Test---------------------------
            studioResourceRepository.AddServerNode(serverExplorerItem);
            //------------Assert Results-------------------------
            Assert.AreEqual(2, studioResourceRepository.ExplorerItemModels.Count);
            Assert.IsTrue(studioResourceRepository.ExplorerItemModels[1].IsExplorerSelected);
            Assert.IsTrue(studioResourceRepository.ExplorerItemModels[1].IsExplorerExpanded);
        }