Ejemplo n.º 1
0
        public async Task RefreshChildren_AddsPlaceholder_WhenAllAppsAreRemoved()
        {
            var fakeInitialApp = new CloudFoundryApp("fake app name", "fake app id", _sut.Space, null);
            var avm            = new AppViewModel(fakeInitialApp, Services);

            var fakeNoAppsResult = new DetailedResult <List <CloudFoundryApp> >(
                succeeded: true,
                content: new List <CloudFoundryApp>(), // simulate space having lost all apps before refresh
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetAppsForSpaceAsync(_sut.Space, true, It.IsAny <int>()))
            .ReturnsAsync(fakeNoAppsResult);

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

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

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());
            Assert.AreEqual(SpaceViewModel.EmptyAppsPlaceholderMsg, _sut.Children[0].DisplayText);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
        public void Constructor_SetsDisplayTextToAppName()
        {
            string appName = "junk";
            var    fakeApp = new CloudFoundryApp(appName, null, null);

            avm = new AppViewModel(fakeApp, services);

            Assert.AreEqual(appName, avm.DisplayText);
        }
Ejemplo n.º 4
0
        public void IsStopped_ReturnsFalse_WhenAppStateIsNotSTOPPED()
        {
            var fakeApp = new CloudFoundryApp("fake name", "fake guid", null)
            {
                State = "anything-other-than-STOPPED"
            };

            avm = new AppViewModel(fakeApp, services);

            Assert.IsFalse(avm.IsStopped);
        }
Ejemplo n.º 5
0
        public void IsStopped_ReturnsTrue_WhenAppStateIsSTOPPED()
        {
            var fakeApp = new CloudFoundryApp("fake name", "fake guid", null)
            {
                State = "STOPPED"
            };

            avm = new AppViewModel(fakeApp, services);

            Assert.IsTrue(avm.IsStopped);
        }
        public void RefreshApp_RaisesPropertyChangedEventForIsStopped()
        {
            CloudFoundryApp fakeApp = new CloudFoundryApp("fake app name", "fake app guid", null);
            var             avm     = new AppViewModel(fakeApp, services);

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

            vm.RefreshApp(avm);

            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreEqual("IsStopped", receivedEvents[0]);
        }
        public void RefreshApp_RaisesPropertyChangedEventForIsStopped()
        {
            CloudFoundryApp fakeApp = new CloudFoundryApp("fake app name", "fake app guid", null, null);

            _sut = new AppViewModel(fakeApp, Services);

            _sut.PropertyChanged += (sender, e) =>
            {
                _receivedEvents.Add(e.PropertyName);
            };

            _sut.RefreshAppState();

            Assert.AreEqual(1, _receivedEvents.Count);
            Assert.AreEqual("IsStopped", _receivedEvents[0]);
        }
Ejemplo n.º 8
0
        public async Task RefreshChildren_UpdatesAppState_ForAllChildren()
        {
            var initialState1 = "INITIAL_FAKE_STATE";
            var initialState2 = "INITIAL_JUNK_STATE";
            var initialState3 = "INITIAL_BOGUS_STATE";

            var fakeInitialApp1 = new CloudFoundryApp("fakeApp1", "junk", _sut.Space, initialState1);
            var fakeInitialApp2 = new CloudFoundryApp("fakeApp2", "junk", _sut.Space, initialState2);
            var fakeInitialApp3 = new CloudFoundryApp("fakeApp3", "junk", _sut.Space, initialState3);

            var fakeFreshApp1 = new CloudFoundryApp("fakeApp1", "junk", _sut.Space, initialState1);
            var fakeFreshApp2 = new CloudFoundryApp("fakeApp2", "junk", _sut.Space, "NEW_FRESH_STATE"); // simulate state change
            var fakeFreshApp3 = new CloudFoundryApp("fakeApp3", "junk", _sut.Space, "NEW_COOL_STATE");  // simulate state change

            _sut.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new AppViewModel(fakeInitialApp1, Services),
                new AppViewModel(fakeInitialApp2, Services),
                new AppViewModel(fakeInitialApp3, Services),
            };

            var fakeSuccessfulAppsResult = new DetailedResult <List <CloudFoundryApp> >(
                succeeded: true,
                content: new List <CloudFoundryApp>
            {
                fakeFreshApp1,
                fakeFreshApp2,
                fakeFreshApp3,
            },
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetAppsForSpaceAsync(_sut.Space, true, It.IsAny <int>()))
            .ReturnsAsync(fakeSuccessfulAppsResult);

            await _sut.RefreshChildren();

            Assert.AreEqual(fakeInitialApp1.State, fakeFreshApp1.State);
            Assert.AreNotEqual(fakeInitialApp2.State, fakeFreshApp2.State);
            Assert.AreNotEqual(fakeInitialApp3.State, fakeFreshApp3.State);
        }
        public async Task DeleteCfApp_CallsDeleteAppAsync()
        {
            var fakeApp = new CloudFoundryApp("junk", "junk", parentSpace: null);

            mockCloudFoundryService.Setup(mock => mock.DeleteAppAsync(fakeApp)).ReturnsAsync(true);

            Exception shouldStayNull = null;

            try
            {
                await vm.DeleteCfApp(fakeApp);
            }
            catch (Exception e)
            {
                shouldStayNull = e;
            }

            Assert.IsNull(shouldStayNull);
            mockCloudFoundryService.VerifyAll();
        }
        public async Task <bool> DeleteAppAsync(CloudFoundryApp app)
        {
            try
            {
                var target = app.ParentSpace.ParentOrg.ParentCf.ApiAddress;
                var token  = app.ParentSpace.ParentOrg.ParentCf.AccessToken;

                bool appWasDeleted = await _cfApiClient.DeleteAppWithGuid(target, token, app.AppId);

                if (appWasDeleted)
                {
                    app.State = "DELETED";
                }
                return(appWasDeleted);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
Ejemplo n.º 11
0
        public async Task StartAppAsync_ReturnsFalseAndDoesNotThrowException_WhenRequestInfoIsMissing()
        {
            var fakeApp = new CloudFoundryApp("fake app name", "fake app guid", parentSpace: null);

            mockCfApiClient.Setup(mock => mock.StartAppWithGuid(It.IsAny <string>(), It.IsAny <string>(), fakeApp.AppId))
            .ReturnsAsync(true);

            bool      startResult    = true;
            Exception shouldStayNull = null;

            try
            {
                startResult = await cfService.StartAppAsync(fakeApp);
            }
            catch (Exception e)
            {
                shouldStayNull = e;
            }

            Assert.IsFalse(startResult);
            Assert.IsNull(shouldStayNull);
        }
        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);
        }
 public AppViewModel(CloudFoundryApp app, IServiceProvider services)
     : base(null, services)
 {
     App         = app;
     DisplayText = App.AppName;
 }
        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();
        }
Ejemplo n.º 15
0
 public void ShowConfirmation(CloudFoundryApp app)
 {
     CfApp = app;
     DialogService.ShowDialog(nameof(AppDeletionConfirmationViewModel));
     CfApp = null;
 }