示例#1
0
        public async Task FetchChildren_ReturnsListOfOrgs_WithoutUpdatingChildren()
        {
            var receivedEvents = new List <string>();
            var fakeCfInstance = new CloudFoundryInstance("junk", null, null);

            cfivm = new CfInstanceViewModel(fakeCfInstance, services);

            cfivm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance))
            .ReturnsAsync(new List <CloudFoundryOrganization>
            {
                new CloudFoundryOrganization("fake org name 1", "fake org id 1", fakeCfInstance),
                new CloudFoundryOrganization("fake org name 2", "fake org id 2", fakeCfInstance)
            });

            var orgs = await cfivm.FetchChildren();

            Assert.AreEqual(2, orgs.Count);

            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.IsNull(cfivm.Children[0]);

            // property changed events should not be raised
            Assert.AreEqual(0, receivedEvents.Count);

            mockCloudFoundryService.VerifyAll();
        }
示例#2
0
 public void TestInit()
 {
     cfService      = new CloudFoundryService(services);
     fakeCfInstance = new CloudFoundryInstance("fake cf", fakeValidTarget, fakeValidAccessToken);
     fakeOrg        = new CloudFoundryOrganization("fake org", "fake org guid", fakeCfInstance);
     fakeSpace      = new CloudFoundrySpace("fake space", "fake space guid", fakeOrg);
     fakeApp        = new CloudFoundryApp("fake app", "fake app guid", fakeSpace);
 }
        public async Task RefreshAllCloudConnections_DoesNotThrowExceptions_WhenOrgsHaveNullChildren()
        {
            var fakeCfInstance = new CloudFoundryInstance("fake cf name", "http://fake.api.address", "fake-token");

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances)
            .Returns(new Dictionary <string, CloudFoundryInstance> {
                { "fake cf name", fakeCfInstance }
            });

            var cfivm = new CfInstanceViewModel(fakeCfInstance, services);

            var fakeOrg = new CloudFoundryOrganization("fake org name", "fake org id", fakeCfInstance);
            var ovm     = new OrgViewModel(fakeOrg, services);

            cfivm.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                ovm
            };

            // check for presence of Dummy child (sanity check)
            Assert.AreEqual(1, ovm.Children.Count);
            Assert.IsNull(ovm.Children[0]);

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance)).ReturnsAsync(new List <CloudFoundryOrganization>
            {
                fakeOrg
            });

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(new List <CloudFoundrySpace>());

            vm.CloudFoundryList = new List <CfInstanceViewModel>
            {
                cfivm
            };

            Exception shouldStayNull = null;

            try
            {
                await vm.RefreshAllCloudConnections(null);
            }
            catch (Exception e)
            {
                shouldStayNull = e;
            }

            Assert.IsNull(shouldStayNull);

            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.AreEqual(ovm, cfivm.Children[0]);

            Assert.AreEqual(1, ovm.Children.Count);
            Assert.IsNull(ovm.Children[0]);

            mockCloudFoundryService.VerifyAll();
        }
        public async Task RefreshCfInstance_UpdatesChildrenOnCfInstanceViewModel()
        {
            var fakeCfInstance          = new CloudFoundryInstance("fake space name", "fake space id", null);
            var fakeCfInstanceViewModel = new CfInstanceViewModel(fakeCfInstance, services);

            var fakeOrgName1 = "fake org 1";
            var fakeOrgName2 = "fake org 2";
            var fakeOrgName3 = "fake org 3";

            var fakeOrgGuid1 = "fake org 1";
            var fakeOrgGuid2 = "fake org 2";
            var fakeOrgGuid3 = "fake org 3";

            fakeCfInstanceViewModel.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new OrgViewModel(new CloudFoundryOrganization(fakeOrgName1, fakeOrgGuid1, fakeCfInstance), services)
            };

            fakeCfInstanceViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            Assert.AreEqual(1, fakeCfInstanceViewModel.Children.Count);
            OrgViewModel firstChildOrg = (OrgViewModel)fakeCfInstanceViewModel.Children[0];

            Assert.AreEqual(fakeOrgName1, firstChildOrg.Org.OrgName);

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance)).ReturnsAsync(new List <CloudFoundryOrganization>
            {
                new CloudFoundryOrganization(fakeOrgName2, fakeOrgGuid2, fakeCfInstance),
                new CloudFoundryOrganization(fakeOrgName3, fakeOrgGuid3, fakeCfInstance)
            });

            await vm.RefreshCfInstance(fakeCfInstanceViewModel);

            Assert.AreEqual(2, fakeCfInstanceViewModel.Children.Count);
            OrgViewModel firstNewChildOrg  = (OrgViewModel)fakeCfInstanceViewModel.Children[0];
            OrgViewModel secondNewChildOrg = (OrgViewModel)fakeCfInstanceViewModel.Children[1];

            Assert.AreEqual(fakeOrgName2, firstNewChildOrg.Org.OrgName);
            Assert.AreEqual(fakeOrgName3, secondNewChildOrg.Org.OrgName);

            // property changed events should not be raised
            Assert.AreEqual(0, receivedEvents.Count);

            mockCloudFoundryService.VerifyAll();
        }
        public CfInstanceViewModel(CloudFoundryInstance cloudFoundryInstance, TasExplorerViewModel parentTasExplorer, IServiceProvider services, bool expanded = false)
            : base(null, parentTasExplorer, services, expanded: expanded)
        {
            _dialogService       = services.GetRequiredService <IErrorDialog>();
            CloudFoundryInstance = cloudFoundryInstance;
            DisplayText          = CloudFoundryInstance.InstanceName;

            LoadingPlaceholder = new PlaceholderViewModel(parent: this, services)
            {
                DisplayText = _loadingMsg,
            };

            EmptyPlaceholder = new PlaceholderViewModel(parent: this, Services)
            {
                DisplayText = _emptyOrgsPlaceholderMsg,
            };
        }
        public async Task <DetailedResult> DeployAppAsync(CloudFoundryInstance targetCf, CloudFoundryOrganization targetOrg, CloudFoundrySpace targetSpace, string appName, string appProjPath, StdOutDelegate stdOutHandler)
        {
            if (!_fileLocatorService.DirContainsFiles(appProjPath))
            {
                return(new DetailedResult(false, emptyOutputDirMessage));
            }

            DetailedResult cfTargetResult = await _cfCliService.ExecuteCfCliCommandAsync(arguments : $"target -o {targetOrg.OrgName} -s {targetSpace.SpaceName}", stdOutHandler : stdOutHandler);

            if (!cfTargetResult.Succeeded)
            {
                return(new DetailedResult(false, $"Unable to target org '{targetOrg.OrgName}' or space '{targetSpace.SpaceName}'.\n{cfTargetResult.Explanation}"));
            }

            DetailedResult cfPushResult = await _cfCliService.ExecuteCfCliCommandAsync(arguments : "push " + appName, workingDir : appProjPath, stdOutHandler : stdOutHandler);

            if (!cfPushResult.Succeeded)
            {
                return(new DetailedResult(false, $"Successfully targeted org '{targetOrg.OrgName}' and space '{targetSpace.SpaceName}' but app deployment failed at the `cf push` stage.\n{cfPushResult.Explanation}"));
            }

            return(new DetailedResult(true, $"App successfully deploying to org '{targetOrg.OrgName}', space '{targetSpace.SpaceName}'..."));
        }
        public async Task RefreshAllCloudConnections_UpdatesCfListWithInstancesFromCfService()
        {
            var fakeCfInstance1 = new CloudFoundryInstance("fake cf name1", "http://fake1.api.address", "fake-token1");
            var fakeCfInstance2 = new CloudFoundryInstance("fake cf name2", "http://fake2.api.address", "fake-token2");
            var fakeCfInstance3 = new CloudFoundryInstance("fake cf name3", "http://fake3.api.address", "fake-token3");

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances)
            .Returns(new Dictionary <string, CloudFoundryInstance> {
                { "instance1", fakeCfInstance1 },
                { "instance2", fakeCfInstance2 },
                { "instance3", fakeCfInstance3 },
            });
            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(It.IsAny <CloudFoundryInstance>())).ReturnsAsync(
                new List <CloudFoundryOrganization> {
            });

            vm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            var listCount = vm.CloudFoundryList.Count;

            Assert.AreEqual(0, listCount);

            await vm.RefreshAllCloudConnections(null);

            var newListCount = vm.CloudFoundryList.Count;

            // ensure the refresh method actually queried the dictionary
            mockCloudFoundryService.VerifyAll();

            Assert.AreEqual(3, newListCount);

            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreEqual("HasCloudTargets", receivedEvents[0]);
        }
        public TasExplorerViewModel(IServiceProvider services)
            : base(services)
        {
            _errorDialogService     = services.GetRequiredService <IErrorDialog>();
            _threadingService       = services.GetRequiredService <IThreadingService>();
            _dataPersistenceService = services.GetRequiredService <IDataPersistenceService>();
            _confirmDelete          = services.GetRequiredService <IAppDeletionConfirmationViewModel>();
            _viewLocatorService     = services.GetRequiredService <IViewLocatorService>();

            string existingSavedConnectionName    = _dataPersistenceService.ReadStringData(ConnectionNameKey);
            string existingSavedConnectionAddress = _dataPersistenceService.ReadStringData(ConnectionAddressKey);
            bool   savedConnectionCredsExist      = CloudFoundryService.IsValidConnection();

            if (existingSavedConnectionName == null || existingSavedConnectionAddress == null || !savedConnectionCredsExist)
            {
                TasConnection = null;
            }
            else
            {
                var restoredConnection = new CloudFoundryInstance(name: existingSavedConnectionName, apiAddress: existingSavedConnectionAddress);

                SetConnection(restoredConnection);
            }
        }
示例#9
0
 public CfInstanceViewModel(CloudFoundryInstance cloudFoundryInstance, IServiceProvider services)
     : base(null, services)
 {
     CloudFoundryInstance = cloudFoundryInstance;
     DisplayText          = CloudFoundryInstance.InstanceName;
 }
示例#10
0
 public CloudFoundryOrganization(string orgName, string guid, CloudFoundryInstance parentCf)
 {
     OrgName  = orgName;
     OrgId    = guid;
     ParentCf = parentCf;
 }
        public async Task RefreshAllCloudConnections_RefreshesEachTreeViewItemViewModel()
        {
            var eventsRaisedByCFIVM = new List <string>();
            var eventsRaisedByOVM   = new List <string>();
            var eventsRaisedBySVM   = new List <string>();
            var eventsRaisedByAVM   = new List <string>();

            var fakeCfInstance = new CloudFoundryInstance("fake cf name", "http://fake.api.address", "fake-token");

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances)
            .Returns(new Dictionary <string, CloudFoundryInstance> {
                { "fake cf name", fakeCfInstance }
            });

            var cfivm = new CfInstanceViewModel(fakeCfInstance, services);

            cfivm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByCFIVM.Add(e.PropertyName);
            };

            var fakeOrg = new CloudFoundryOrganization("fake org name", "fake org id", fakeCfInstance);
            var ovm     = new OrgViewModel(fakeOrg, services);

            ovm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByOVM.Add(e.PropertyName);
            };

            var fakeSpace = new CloudFoundrySpace("fake space name", "fake space id", fakeOrg);
            var svm       = new SpaceViewModel(fakeSpace, services);

            svm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedBySVM.Add(e.PropertyName);
            };

            var fakeApp = new CloudFoundryApp("fake app name", "fake app id", fakeSpace);
            var avm     = new AppViewModel(fakeApp, services);

            avm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByAVM.Add(e.PropertyName);
            };

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance)).ReturnsAsync(
                new List <CloudFoundryOrganization> {
                fakeOrg
            });

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(
                new List <CloudFoundrySpace> {
                fakeSpace
            });

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace)).ReturnsAsync(
                new List <CloudFoundryApp> {
                fakeApp
            });

            cfivm.Children = new ObservableCollection <TreeViewItemViewModel> {
                ovm
            };

            ovm.Children = new ObservableCollection <TreeViewItemViewModel> {
                svm
            };

            svm.Children = new ObservableCollection <TreeViewItemViewModel> {
                avm
            };

            vm.CloudFoundryList = new List <CfInstanceViewModel> {
                cfivm
            };


            await vm.RefreshAllCloudConnections(null);

            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.AreEqual(ovm, cfivm.Children[0]);
            Assert.AreEqual(1, eventsRaisedByCFIVM.Count);
            Assert.AreEqual("Children", eventsRaisedByCFIVM[0]);

            Assert.AreEqual(1, ovm.Children.Count);
            Assert.AreEqual(svm, ovm.Children[0]);
            Assert.AreEqual(1, eventsRaisedByOVM.Count);
            Assert.AreEqual("Children", eventsRaisedByOVM[0]);

            Assert.AreEqual(1, svm.Children.Count);
            Assert.AreEqual(avm, svm.Children[0]);
            Assert.AreEqual(1, eventsRaisedBySVM.Count);
            Assert.AreEqual("Children", eventsRaisedBySVM[0]);

            Assert.AreEqual(1, eventsRaisedByAVM.Count);
            Assert.AreEqual("IsStopped", eventsRaisedByAVM[0]);

            // ensure all view models issued queries for updated lists of children
            mockCloudFoundryService.VerifyAll();
        }
        public async Task <List <CloudFoundryOrganization> > GetOrgsForCfInstanceAsync(CloudFoundryInstance cf)
        {
            var target      = cf.ApiAddress;
            var accessToken = cf.AccessToken;

            List <Org> orgsResults = await _cfApiClient.ListOrgs(target, accessToken);

            var orgs = new List <CloudFoundryOrganization>();

            if (orgsResults != null)
            {
                orgsResults.ForEach(delegate(Org org)
                {
                    orgs.Add(new CloudFoundryOrganization(org.name, org.guid, cf));
                });
            }

            return(orgs);
        }