void TreeViewDrop(object sender, DragEventArgs e) { TreeViewItem t = sender as TreeViewItem; IStudioResourceRepository rep = StudioResourceRepository.Instance; if (t != null) { ExplorerItemModel destination = t.Header as ExplorerItemModel; if (destination != null) { var dataObject = e.Data; if (dataObject != null && dataObject.GetDataPresent(GlobalConstants.ExplorerItemModelFormat)) { var explorerItemModel = dataObject.GetData(GlobalConstants.ExplorerItemModelFormat); try { ExplorerItemModel source = explorerItemModel as ExplorerItemModel; if (ShouldNotMove(source, destination)) { e.Handled = true; } else { MoveItem(source, destination, rep); } } finally { e.Handled = true; } } } } }
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 EnvironmentTreeViewModel_PermissionsChanged_IsAuthorizedTrue_ChildrenNotCleared() { var connection = CreateConnection(); connection.Setup(c => c.IsAuthorized).Returns(true); var mockEnvironmentModel = new Mock <IEnvironmentModel>(); mockEnvironmentModel.SetupGet(x => x.Connection.AppServerUri).Returns(new Uri("http://127.0.0.1/")); mockEnvironmentModel.Setup(e => e.Connection).Returns(connection.Object); mockEnvironmentModel.Setup(model => model.Equals(It.IsAny <IEnvironmentModel>())).Returns(true); mockEnvironmentModel.Setup(e => e.IsAuthorized).Returns(true); 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); mockEnvironmentModel.Setup(e => e.IsAuthorized).Returns(true); connection.Raise(c => c.PermissionsChanged += null, EventArgs.Empty); Assert.AreEqual(3, environmentVm.Children.Count); }
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 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 bool PreventDrop(IDataObject dataObject) { if (dataObject == null) { return(false); } var formats = dataObject.GetFormats(); //If we didnt attach any data for the format - dont allow if (!formats.Any()) { return(false); } //if it is a ReourceTreeViewModel, get the data for this string var modelItemString = formats.FirstOrDefault(s => s.IndexOf("ExplorerItemModel", StringComparison.Ordinal) >= 0); if (String.IsNullOrEmpty(modelItemString)) { //else if it is a workflowItemType, get data for this modelItemString = formats.FirstOrDefault(s => s.IndexOf("WorkflowItemTypeNameFormat", StringComparison.Ordinal) >= 0); //else just bounce out, we didnt set it. if (!String.IsNullOrEmpty(modelItemString)) { return(false); } } if (string.IsNullOrEmpty(modelItemString)) { return(false); } //now get data for whichever was set above var objectData = dataObject.GetData(modelItemString); if (objectData == null) { return(false); } IWorkflowDesignerViewModel workflowDesignerViewModel = _workflowDesignerView.DataContext as IWorkflowDesignerViewModel; if (workflowDesignerViewModel != null) { ExplorerItemModel explorerItemModel = objectData as ExplorerItemModel; if (explorerItemModel != null) { if (workflowDesignerViewModel.EnvironmentModel.ID != explorerItemModel.EnvironmentId && explorerItemModel.ResourceType >= Common.Interfaces.Data.ResourceType.DbService) { return(true); } if (explorerItemModel.Permissions >= Permissions.Execute && explorerItemModel.ResourceType <= Common.Interfaces.Data.ResourceType.WebService) { return(false); } } } return(true); }
public void DeploySummaryPredicateExisting_EnvironmentContainsResourceWithSameIDButDifferentName_ExpectedTrue() { Guid resourceGuid = Guid.NewGuid(); Mock <IContextualResourceModel> mockResourceModel = CreateMockResourceModel(resourceGuid, "OtherResource"); IEnvironmentModel environmentModel; IExplorerItemModel resourceVm; IExplorerItemModel rootItem; StudioResourceRepository studioResourceRepository = CreateModels(false, mockResourceModel, out environmentModel, out resourceVm, out rootItem); Mock <IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(Studio.Core.AppResources.Enums.ResourceType.WorkflowService, resourceGuid); environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List <IResourceModel>()).Object; var navigationViewModel = CreateDeployNavigationViewModel(environmentModel, studioResourceRepository); ExplorerItemModel explorerItemModel = new ExplorerItemModel { DisplayName = "localhost", ResourceType = ResourceType.Server }; explorerItemModel.Children.Add(resourceVm); navigationViewModel.ExplorerItemModels.Add(explorerItemModel); navigationViewModel.Environment = environmentModel; resourceVm.IsChecked = true; bool actual = DeployStatsCalculator.DeploySummaryPredicateExisting(resourceVm, navigationViewModel); Assert.IsTrue(actual); Assert.IsTrue(DeployStatsCalculator.ConflictingResources.Count > 0); }
// 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------------------------- }
public void DeploySummayCalculateErrorsHasDifferentIdHasError() { Mock <IContextualResourceModel> mockResourceModel = CreateMockResourceModel(); IEnvironmentModel environmentModel; IExplorerItemModel resourceVm; IExplorerItemModel rootItem; StudioResourceRepository studioResourceRepository = CreateModels(false, mockResourceModel, out environmentModel, out resourceVm, out rootItem); ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); IExplorerItemModel model = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object) { ResourceId = Guid.NewGuid(), ResourcePath = "WORKFLOWS\\TestingWF", IsChecked = true }; var navigationViewModel = CreateDeployNavigationViewModel(environmentModel, studioResourceRepository); var actual = DeployStatsCalculator.CheckForNamingConflicts(new List <IExplorerItemModel>() { model }, navigationViewModel); Assert.IsTrue(actual.Any()); }
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 SelectForDeployPredicateWithTypeAndCategories_NullResourceOnNavigationItemViewModel_Expected_False() { ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); bool actual = DeployStatsCalculator.SelectForDeployPredicateWithTypeAndCategories(navigationItemViewModel, ResourceType.WorkflowService, new List <string>(), new List <string>()); Assert.IsFalse(actual); }
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); } }); }
public void SelectForDeployPredicate_NullResourceModelOnNavigationItemViewModel_Expected_False() { var conn = new Mock <IConnectControlSingleton>().Object; var studio = new Mock <IStudioResourceRepository>().Object; ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(conn, studio); bool actual = DeployStatsCalculator.SelectForDeployPredicate(navigationItemViewModel); Assert.IsFalse(actual); }
public void DeploySummaryPredicateNew_NullResourceOnNavigationItemViewModel_Expected_False() { ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); IEnvironmentModel environmentModel = Dev2MockFactory.SetupEnvironmentModel().Object; bool actual = DeployStatsCalculator.DeploySummaryPredicateNew(navigationItemViewModel, environmentModel); Assert.IsFalse(actual); }
//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 SelectForDeployPredicate_ValidNavigationItemViewModel_Expected_True() { ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(new Mock <IConnectControlSingleton>().Object, new Mock <IStudioResourceRepository>().Object) { IsChecked = true, ResourcePath = "bob" }; bool actual = DeployStatsCalculator.SelectForDeployPredicate(navigationItemViewModel); Assert.IsTrue(actual); }
public void DeploySummaryPredicateNew_EnvironmentContainsResource_Expected_False() { Mock <IContextualResourceModel> resourceModel = Dev2MockFactory.SetupResourceModelMock(Studio.Core.AppResources.Enums.ResourceType.WorkflowService); ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); IEnvironmentModel environmentModel = Dev2MockFactory.SetupEnvironmentModel(resourceModel, new List <IResourceModel>()).Object; bool actual = DeployStatsCalculator.DeploySummaryPredicateNew(navigationItemViewModel, environmentModel); Assert.IsFalse(actual); }
public void DragDropHelpers_PreventDrop_GetDataReturnsExplorerItemModelSource_ReturnsFalse() { //------------Setup for test-------------------------- var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView()); var data = new ExplorerItemModel { Permissions = Permissions.Execute, ResourceType = Common.Interfaces.Data.ResourceType.DbSource }; //------------Execute Test--------------------------- bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data)); //------------Assert Results------------------------- Assert.IsTrue(canDoDrop); }
public void DeploySummayCalculateStats() { List <string> exclusionCategories = new List <string> { "Website", "Human Interface Workflow", "Webpage" }; List <string> blankCategories = new List <string>(); var conn = new Mock <IConnectControlSingleton>().Object; var studio = new Mock <IStudioResourceRepository>().Object; List <ExplorerItemModel> items = new List <ExplorerItemModel>(); var vm1 = new ExplorerItemModel(conn, studio) { ResourcePath = "Services", ResourceType = ResourceType.DbService, IsChecked = true }; var vm2 = new ExplorerItemModel(conn, studio) { ResourceType = ResourceType.WorkflowService, ResourcePath = "Workflows", IsChecked = true }; var vm3 = new ExplorerItemModel(conn, studio) { ResourcePath = "Test", ResourceType = ResourceType.Folder, IsChecked = true }; var vm4 = new ExplorerItemModel(conn, studio) { ResourceType = ResourceType.Server, IsChecked = false }; items.Add(vm1); items.Add(vm2); items.Add(vm3); items.Add(vm4); Dictionary <string, Func <IExplorerItemModel, bool> > predicates = new Dictionary <string, Func <IExplorerItemModel, bool> > { { "Services", n => DeployStatsCalculator.SelectForDeployPredicateWithTypeAndCategories(n, ResourceType.DbService | ResourceType.PluginService | ResourceType.WebService, blankCategories, exclusionCategories) }, { "Workflows", n => DeployStatsCalculator.SelectForDeployPredicateWithTypeAndCategories(n, ResourceType.WorkflowService, blankCategories, exclusionCategories) }, { "Sources", n => DeployStatsCalculator.SelectForDeployPredicateWithTypeAndCategories(n, ResourceType.DbSource | ResourceType.PluginSource | ResourceType.WebSource | ResourceType.ServerSource | ResourceType.EmailSource, blankCategories, exclusionCategories) }, { "Unknown", n => DeployStatsCalculator.SelectForDeployPredicate(n) } }; ObservableCollection <DeployStatsTO> expected = new ObservableCollection <DeployStatsTO> { new DeployStatsTO("Services", "1"), new DeployStatsTO("Workflows", "1"), new DeployStatsTO("Sources", "0"), new DeployStatsTO("Unknown", "0") }; const int expectedDeployItemCount = 2; int actualDeployItemCount; ObservableCollection <DeployStatsTO> actual = new ObservableCollection <DeployStatsTO>(); DeployStatsCalculator.CalculateStats(items, predicates, actual, out actualDeployItemCount); CollectionAssert.AreEqual(expected, actual, new DeployStatsTOComparer()); Assert.AreEqual(expectedDeployItemCount, actualDeployItemCount); }
StudioResourceRepository BuildExplorerItems(IResourceRepository resourceRepository) { var resourceModels = resourceRepository.All(); var localhostItemModel = new ExplorerItemModel { DisplayName = "localhost", EnvironmentId = Guid.Empty, ResourceType = Common.Interfaces.Data.ResourceType.Server }; if (resourceModels != null) { foreach (var resourceModel in resourceModels) { var resourceItemModel = new ExplorerItemModel { ResourceId = resourceModel.ID, ResourcePath = resourceModel.Category, EnvironmentId = Guid.Empty, DisplayName = resourceModel.ResourceName }; Common.Interfaces.Data.ResourceType correctTyping = Common.Interfaces.Data.ResourceType.WorkflowService; switch (resourceModel.ResourceType) { case ResourceType.WorkflowService: correctTyping = Common.Interfaces.Data.ResourceType.WorkflowService; break; case ResourceType.Service: correctTyping = Common.Interfaces.Data.ResourceType.DbService; break; case ResourceType.Source: correctTyping = Common.Interfaces.Data.ResourceType.WebSource; break; } resourceItemModel.ResourceType = correctTyping; var categoryItem = localhostItemModel.Children.FirstOrDefault(model => model.DisplayName == resourceModel.Category); if (categoryItem == null) { categoryItem = new ExplorerItemModel { Parent = localhostItemModel, DisplayName = resourceModel.Category, EnvironmentId = Guid.Empty, ResourceType = Common.Interfaces.Data.ResourceType.Folder, ResourcePath = "" }; localhostItemModel.Children.Add(categoryItem); } resourceItemModel.Parent = categoryItem; categoryItem.Children.Add(resourceItemModel); } } var studioResourceRepository = new StudioResourceRepository(localhostItemModel, _Invoke); var explorerResourceRepository = new Mock <IClientExplorerResourceRepository>().Object; studioResourceRepository.GetExplorerProxy = guid => explorerResourceRepository; return(studioResourceRepository); }
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); }
public void DragDropHelpers_PreventDrop_GetDataReturnsExplorerItemModelSource_ReturnsFalse() { //------------Setup for test-------------------------- var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView()); var data = new ExplorerItemModel(new Mock <IConnectControlSingleton>().Object, new Mock <IStudioResourceRepository>().Object) { Permissions = Permissions.Execute, ResourceType = ResourceType.DbSource }; //------------Execute Test--------------------------- bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data)); //------------Assert Results------------------------- Assert.IsTrue(canDoDrop); }
public void DragDropHelpers_PreventDrop_FormatOfWorkflowItemTypeNameFormat_ReturnsFalse() { //------------Setup for test-------------------------- object dataContext = new object(); var dragDropHelpers = new DragDropHelpers(GetMockWorkflowDesignerView(dataContext)); var data = new ExplorerItemModel { Permissions = Permissions.Execute, ResourceType = Common.Interfaces.Data.ResourceType.DbService }; //------------Execute Test--------------------------- bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "WorkflowItemTypeNameFormat" }, data)); //------------Assert Results------------------------- Assert.IsFalse(canDoDrop); }
public bool SetModelItemForServiceTypes(IDataObject dataObject) { if (dataObject != null && dataObject.GetDataPresent(GlobalConstants.ExplorerItemModelFormat)) { var explorerItemModel = dataObject.GetData(GlobalConstants.ExplorerItemModelFormat); try { ExplorerItemModel itemModel = explorerItemModel as ExplorerItemModel; if (itemModel != null) { IEnvironmentModel environmentModel = EnvironmentRepository.Instance.FindSingle(c => c.ID == itemModel.EnvironmentId); if (environmentModel != null) { var resource = environmentModel.ResourceRepository.FindSingle(c => c.ID == itemModel.ResourceId) as IContextualResourceModel; if (resource != null) { DsfActivity d = DsfActivityFactory.CreateDsfActivity(resource, null, true, EnvironmentRepository.Instance, true); d.ServiceName = d.DisplayName = d.ToolboxFriendlyName = resource.Category; d.IconPath = resource.IconPath; if (Application.Current != null && Application.Current.Dispatcher.CheckAccess() && Application.Current.MainWindow != null) { dynamic mvm = Application.Current.MainWindow.DataContext; if (mvm != null && mvm.ActiveItem != null) { WorkflowDesignerUtils.CheckIfRemoteWorkflowAndSetProperties(d, resource, mvm.ActiveItem.Environment); } } ModelItem modelItem = ModelItemUtils.CreateModelItem(d); if (modelItem != null) { dynamic mi = ModelItem; ModelItemCollection activitiesCollection = mi.Activities; activitiesCollection.Insert(activitiesCollection.Count, d); return(true); } } } } } catch (RuntimeBinderException e) { Dev2Logger.Log.Error(e); } } return(false); }
public void DeploySummaryPredicateNew_NullResourcesOnEnvironmentModel_Expected_False() { Dev2MockFactory.SetupResourceModelMock(Studio.Core.AppResources.Enums.ResourceType.WorkflowService); ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); Mock <IEnvironmentModel> mockEnvironmentModel = Dev2MockFactory.SetupEnvironmentModel(); mockEnvironmentModel.Setup(e => e.ResourceRepository).Returns <object>(null); IEnvironmentModel environmentModel = mockEnvironmentModel.Object; bool actual = DeployStatsCalculator.DeploySummaryPredicateNew(navigationItemViewModel, environmentModel); Assert.IsFalse(actual); }
public void DragDropHelpers_PreventDrop_UserIsNotAuthorized_True() { //------------Setup for test-------------------------- var data = new ExplorerItemModel { Permissions = Permissions.View, ResourceType = Common.Interfaces.Data.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 DragDropHelpers_PreventDrop_GetDataReturnsExplorerItemModelNotWorkflowServiceDataContextNotViewModel_ReturnsTrue() { //------------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 = Common.Interfaces.Data.ResourceType.DbService }; //------------Execute Test--------------------------- bool canDoDrop = dragDropHelpers.PreventDrop(GetMockDataObjectWithFormatData(new[] { "ExplorerItemModel" }, data)); //------------Assert Results------------------------- Assert.IsTrue(canDoDrop); }
public void DeploySummaryPredicateExisting_NullResourceOnNavigationItemViewModel_Expected_False() { Mock <IContextualResourceModel> mockResourceModel = CreateMockResourceModel(); IEnvironmentModel environmentModel; IExplorerItemModel resourceVm; IExplorerItemModel rootItem; StudioResourceRepository studioResourceRepository = CreateModels(false, mockResourceModel, out environmentModel, out resourceVm, out rootItem); ExplorerItemModel navigationItemViewModel = new ExplorerItemModel(); var navigationViewModel = CreateDeployNavigationViewModel(environmentModel, studioResourceRepository); bool actual = DeployStatsCalculator.DeploySummaryPredicateExisting(navigationItemViewModel, navigationViewModel); Assert.IsFalse(actual); }
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); }
public void ThenTheExplorerTreeForWillHave(string p0, Table table) { var allItems = new List <ExplorerItemModel>(); foreach (var tableRow in table.Rows) { var parentName = tableRow["Parent"]; var childName = tableRow["Child"]; var type = tableRow["Type"]; ResourceType resourceType; Enum.TryParse(type, out resourceType); var eim = new ExplorerItemModel { DisplayName = childName, Children = new ObservableCollection <IExplorerItemModel>(), ResourceType = resourceType }; var explorerItemModel = allItems.FirstOrDefault(model => model.DisplayName == parentName); if (explorerItemModel != null) { explorerItemModel.Children.Add(eim); } allItems.Add(eim); } var folderName = ScenarioContext.Current.Get <string>("folderName"); var itemModel = ScenarioContext.Current.Get <IExplorerItem>("localhost"); var folder = itemModel.Children.FirstOrDefault(a => a.DisplayName == folderName); Assert.IsNotNull(folder); Assert.AreEqual(itemModel.DisplayName, Environment.MachineName); Assert.AreEqual(folder.DisplayName, allItems[0].Children[0].DisplayName); Assert.AreEqual(folder.Children.Count, allItems[0].Children[0].Children.Count); // assert that the test directory exists foreach (var explorerItemModel in folder.Children) { Assert.IsTrue(allItems[0].Children[0].Children.Count(a => a.ResourceType == explorerItemModel.ResourceType && a.DisplayName == explorerItemModel.DisplayName) == 1); } var environmentModel = EnvironmentRepository.Instance.FindSingle(model => model.Name == "localhost"); ServerExplorerClientProxy repository = new ServerExplorerClientProxy(environmentModel.Connection); repository.RenameItem(new ServerExplorerItem("FolderToRename", Guid.NewGuid(), ResourceType.Folder, null, Permissions.Administrator, "FolderToRename"), p0, Guid.Empty); }