Exemple #1
0
        public async Task RefreshChildren_AddsPlaceholder_WhenAllOrgsAreRemoved()
        {
            var fakeInitialOrg = new CloudFoundryOrganization("fake org name", "fake org id", parentCf: _sut.CloudFoundryInstance);
            var ovm            = new OrgViewModel(fakeInitialOrg, null, null, Services);

            var fakeEmptyOrgsResult = new DetailedResult <List <CloudFoundryOrganization> >(
                succeeded: true,
                content: new List <CloudFoundryOrganization>(), // simulate cf having lost all orgs before refresh
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetOrgsForCfInstanceAsync(_sut.CloudFoundryInstance, true, It.IsAny <int>()))
            .ReturnsAsync(fakeEmptyOrgsResult);

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

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

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());
            Assert.AreEqual(CfInstanceViewModel._emptyOrgsPlaceholderMsg, _sut.Children[0].DisplayText);
        }
Exemple #2
0
        public async Task RefreshChildren_RemovesPlaceholder_WhenEmptyCfGainsChildren()
        {
            // simulate cf initially having no org children
            _sut.Children = new ObservableCollection <TreeViewItemViewModel> {
                _sut.EmptyPlaceholder
            };
            _sut.HasEmptyPlaceholder = true;

            var fakeNewOrg = new CloudFoundryOrganization("fake org name", "fake org id", _sut.CloudFoundryInstance);

            var fakeSuccessfulOrgsResult = new DetailedResult <List <CloudFoundryOrganization> >(
                succeeded: true,
                content: new List <CloudFoundryOrganization>
            {
                fakeNewOrg,     // simulate cf having gained an org child before refresh
            },
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetOrgsForCfInstanceAsync(_sut.CloudFoundryInstance, true, It.IsAny <int>()))
            .ReturnsAsync(fakeSuccessfulOrgsResult);

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

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(OrgViewModel), _sut.Children[0].GetType());
        }
        public async Task FetchChildren_ReturnsListOfSpaces_WithoutUpdatingChildren()
        {
            var receivedEvents = new List <string>();
            var fakeOrg        = new CloudFoundryOrganization("junk", null, null);

            ovm = new OrgViewModel(fakeOrg, services);

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

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg))
            .ReturnsAsync(new List <CloudFoundrySpace>
            {
                new CloudFoundrySpace("fake space name 1", "fake space id 1", fakeOrg),
                new CloudFoundrySpace("fake space name 2", "fake space id 2", fakeOrg)
            });

            var spaces = await ovm.FetchChildren();

            Assert.AreEqual(2, spaces.Count);

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

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

            mockCloudFoundryService.VerifyAll();
        }
Exemple #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_SetsDisplayTextToOrgName()
        {
            string orgName = "junk";
            var    fakeOrg = new CloudFoundryOrganization(orgName, null, null);

            ovm = new OrgViewModel(fakeOrg, services);

            Assert.AreEqual(orgName, ovm.DisplayText);
        }
        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 RefreshOrg_UpdatesChildrenOnOrgViewModel()
        {
            var fakeOrg          = new CloudFoundryOrganization("fake org name", "fake org id", null);
            var fakeOrgViewModel = new OrgViewModel(fakeOrg, services);

            var fakeSpaceName1 = "fake space 1";
            var fakeSpaceName2 = "fake space 2";
            var fakeSpaceName3 = "fake space 3";

            var fakeSpaceGuid1 = "fake space 1";
            var fakeSpaceGuid2 = "fake space 2";
            var fakeSpaceGuid3 = "fake space 3";

            fakeOrgViewModel.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new SpaceViewModel(new CloudFoundrySpace(fakeSpaceName1, fakeSpaceGuid1, fakeOrg), services)
            };

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

            Assert.AreEqual(1, fakeOrgViewModel.Children.Count);
            SpaceViewModel firstChildSpace = (SpaceViewModel)fakeOrgViewModel.Children[0];

            Assert.AreEqual(fakeSpaceName1, firstChildSpace.Space.SpaceName);

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(new List <CloudFoundrySpace>
            {
                new CloudFoundrySpace(fakeSpaceName2, fakeSpaceGuid2, fakeOrg),
                new CloudFoundrySpace(fakeSpaceName3, fakeSpaceGuid3, fakeOrg)
            });

            await vm.RefreshOrg(fakeOrgViewModel);

            Assert.AreEqual(2, fakeOrgViewModel.Children.Count);
            SpaceViewModel firstNewChildSpace  = (SpaceViewModel)fakeOrgViewModel.Children[0];
            SpaceViewModel secondNewChildSpace = (SpaceViewModel)fakeOrgViewModel.Children[1];

            Assert.AreEqual(fakeSpaceName2, firstNewChildSpace.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName3, secondNewChildSpace.Space.SpaceName);

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

            mockCloudFoundryService.VerifyAll();
        }
        public OrgViewModel(CloudFoundryOrganization org, CfInstanceViewModel parentCfInstanceViewModel, TasExplorerViewModel parentTasExplorer, IServiceProvider services, bool expanded = false)
            : base(parentCfInstanceViewModel, parentTasExplorer, services, expanded: expanded)
        {
            _dialogService = services.GetRequiredService <IErrorDialog>();

            Org         = org;
            DisplayText = Org.OrgName;

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

            EmptyPlaceholder = new PlaceholderViewModel(parent: this, Services)
            {
                DisplayText = _emptySpacesPlaceholderMsg,
            };
        }
        public async Task <List <CloudFoundrySpace> > GetSpacesForOrgAsync(CloudFoundryOrganization org)
        {
            var target      = org.ParentCf.ApiAddress;
            var accessToken = org.ParentCf.AccessToken;

            List <Space> spacesResults = await _cfApiClient.ListSpacesForOrg(target, accessToken, org.OrgId);

            var spaces = new List <CloudFoundrySpace>();

            if (spacesResults != null)
            {
                spacesResults.ForEach(delegate(Space space)
                {
                    spaces.Add(new CloudFoundrySpace(space.name, space.guid, org));
                });
            }

            return(spaces);
        }
 public CloudFoundrySpace(string spaceName, string guid, CloudFoundryOrganization parentOrg)
 {
     SpaceName = spaceName;
     SpaceId   = guid;
     ParentOrg = parentOrg;
 }
Exemple #11
0
 public OrgViewModel(CloudFoundryOrganization org, IServiceProvider services)
     : base(null, services)
 {
     Org         = org;
     DisplayText = Org.OrgName;
 }
        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}'..."));
        }