示例#1
0
        public async Task RefreshChildren_AddsPlaceholder_WhenAllSpacesAreRemoved()
        {
            var fakeInitialSpace = new CloudFoundrySpace("fake space name", "fake space id", _sut.Org);
            var svm = new SpaceViewModel(fakeInitialSpace, null, null, Services);

            var fakeNoSpacesResult = new DetailedResult <List <CloudFoundrySpace> >(
                succeeded: true,
                content: new List <CloudFoundrySpace>(), // simulate org having lost all spaces before refresh
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(_sut.Org, true, It.IsAny <int>()))
            .ReturnsAsync(fakeNoSpacesResult);

            _sut.Children = new ObservableCollection <TreeViewItemViewModel> {
                svm
            };                                                                       // simulate org initially having 1 space child

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(SpaceViewModel), _sut.Children[0].GetType());

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());
            Assert.AreEqual(OrgViewModel._emptySpacesPlaceholderMsg, _sut.Children[0].DisplayText);
        }
示例#2
0
 public CloudFoundryApp(string appName, string appGuid, CloudFoundrySpace parentSpace, string state)
 {
     AppName     = appName;
     AppId       = appGuid;
     ParentSpace = parentSpace;
     State       = state;
 }
        public async Task FetchChildren_ReturnsListOfApps_WithoutUpdatingChildren()
        {
            var receivedEvents = new List <string>();
            var fakeSpace      = new CloudFoundrySpace("junk", null, null);

            svm = new SpaceViewModel(fakeSpace, services);

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

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace))
            .ReturnsAsync(new List <CloudFoundryApp>
            {
                new CloudFoundryApp("fake app name 1", "fake app id 1", fakeSpace),
                new CloudFoundryApp("fake app name 2", "fake app id 2", fakeSpace)
            });

            var apps = await svm.FetchChildren();

            Assert.AreEqual(2, apps.Count);

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

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

            mockCloudFoundryService.VerifyAll();
        }
示例#4
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 void Constructor_SetsDisplayTextToSpaceName()
        {
            string spaceName = "junk";
            string spaceId   = "junk";
            var    fakeSpace = new CloudFoundrySpace(spaceName, spaceId, null);

            svm = new SpaceViewModel(fakeSpace, services);

            Assert.AreEqual(spaceName, svm.DisplayText);
        }
        public async Task RefreshSpace_UpdatesChildrenOnSpaceViewModel()
        {
            var fakeSpace          = new CloudFoundrySpace("fake space name", "fake space id", null);
            var fakeSpaceViewModel = new SpaceViewModel(fakeSpace, services);

            var fakeAppName1 = "fake app 1";
            var fakeAppName2 = "fake app 2";
            var fakeAppName3 = "fake app 3";

            var fakeAppGuid1 = "fake app 1";
            var fakeAppGuid2 = "fake app 2";
            var fakeAppGuid3 = "fake app 3";

            fakeSpaceViewModel.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new AppViewModel(new CloudFoundryApp(fakeAppName1, fakeAppGuid1, fakeSpace), services)
            };

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

            Assert.AreEqual(1, fakeSpaceViewModel.Children.Count);
            AppViewModel firstChildApp = (AppViewModel)fakeSpaceViewModel.Children[0];

            Assert.AreEqual(fakeAppName1, firstChildApp.App.AppName);

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace)).ReturnsAsync(new List <CloudFoundryApp>
            {
                new CloudFoundryApp(fakeAppName2, fakeAppGuid2, fakeSpace),
                new CloudFoundryApp(fakeAppName3, fakeAppGuid3, fakeSpace)
            });

            await vm.RefreshSpace(fakeSpaceViewModel);

            Assert.AreEqual(2, fakeSpaceViewModel.Children.Count);
            AppViewModel firstNewChildApp  = (AppViewModel)fakeSpaceViewModel.Children[0];
            AppViewModel secondNewChildApp = (AppViewModel)fakeSpaceViewModel.Children[1];

            Assert.AreEqual(fakeAppName2, firstNewChildApp.App.AppName);
            Assert.AreEqual(fakeAppName3, secondNewChildApp.App.AppName);

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

            mockCloudFoundryService.VerifyAll();
        }
        public SpaceViewModel(CloudFoundrySpace space, OrgViewModel parentOrgViewModel, TasExplorerViewModel parentTasExplorer, IServiceProvider services, bool expanded = false)
            : base(parentOrgViewModel, parentTasExplorer, services, expanded: expanded)
        {
            _dialogService = services.GetRequiredService <IErrorDialog>();
            Space          = space;
            DisplayText    = Space.SpaceName;

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

            EmptyPlaceholder = new PlaceholderViewModel(parent: this, Services)
            {
                DisplayText = EmptyAppsPlaceholderMsg,
            };
        }
        public async Task <List <CloudFoundryApp> > GetAppsForSpaceAsync(CloudFoundrySpace space)
        {
            var target      = space.ParentOrg.ParentCf.ApiAddress;
            var accessToken = space.ParentOrg.ParentCf.AccessToken;

            List <App> appResults = await _cfApiClient.ListAppsForSpace(target, accessToken, space.SpaceId);

            var apps = new List <CloudFoundryApp>();

            if (appResults != null)
            {
                appResults.ForEach(delegate(App app)
                {
                    var appToAdd = new CloudFoundryApp(app.name, app.guid, space)
                    {
                        State = app.state
                    };
                    apps.Add(appToAdd);
                });
            }

            return(apps);
        }
示例#9
0
        public async Task RefreshChildren_RemovesPlaceholder_WhenEmptyOrgGainsChildren()
        {
            // simulate org initially having no space children
            _sut.Children = new ObservableCollection <TreeViewItemViewModel> {
                _sut.EmptyPlaceholder
            };
            _sut.HasEmptyPlaceholder = true;

            var fakeNewSpace = new CloudFoundrySpace("fake space name", "fake space id", _sut.Org);

            var fakeSuccessfulSpacesResult = new DetailedResult <List <CloudFoundrySpace> >(
                succeeded: true,
                content: new List <CloudFoundrySpace>
            {
                fakeNewSpace,     // simulate org having gained a space child before refresh
            },
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(_sut.Org, true, It.IsAny <int>()))
            .ReturnsAsync(fakeSuccessfulSpacesResult);

            _sut.Children = new ObservableCollection <TreeViewItemViewModel> {
                _sut.EmptyPlaceholder
            };                                                                                         // simulate org initially having no space children

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());
            Assert.AreEqual(OrgViewModel._emptySpacesPlaceholderMsg, _sut.Children[0].DisplayText);

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(SpaceViewModel), _sut.Children[0].GetType());
        }
示例#10
0
 public SpaceViewModel(CloudFoundrySpace space, IServiceProvider services)
     : base(null, services)
 {
     Space       = space;
     DisplayText = Space.SpaceName;
 }
        public async Task RefreshAllCloudConnections_DoesNotThrowExceptions_WhenSpacesHaveNullChildren()
        {
            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);

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

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

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

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

            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>());

            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.AreEqual(svm, ovm.Children[0]);

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

            mockCloudFoundryService.VerifyAll();
        }
        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 <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}'..."));
        }