示例#1
0
        public async Task LoadChildren_CollapsesTreeViewItem_WhenOrgsRequestFails()
        {
            var expandedViewModel = new CfInstanceViewModel(FakeCfInstance, null, Services)
            {
                IsExpanded = true,
            };

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

            var fakeFailedResult = new DetailedResult <List <CloudFoundryOrganization> >(
                succeeded: false,
                content: null,
                explanation: "junk",
                cmdDetails: FakeFailureCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetOrgsForCfInstanceAsync(expandedViewModel.CloudFoundryInstance, true, 1))
            .ReturnsAsync(fakeFailedResult);

            Assert.IsTrue(expandedViewModel.IsExpanded);

            await expandedViewModel.LoadChildren();

            Assert.IsFalse(expandedViewModel.IsLoading);
            Assert.IsFalse(expandedViewModel.IsExpanded);
            Assert.IsTrue(_receivedEvents.Contains("IsExpanded"));

            MockErrorDialogService.Verify(mock => mock.
                                          DisplayErrorDialog(CfInstanceViewModel._getOrgsFailureMsg, fakeFailedResult.Explanation),
                                          Times.Once);
        }
示例#2
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();
        }
示例#3
0
        public void LoadChildren_UpdatesAllOrgs()
        {
            var initialOrgsList = new System.Collections.ObjectModel.ObservableCollection <TreeViewItemViewModel>
            {
                new OrgViewModel(new CloudFoundryOrganization("initial org 1", "initial org 1 guid", null), services),
                new OrgViewModel(new CloudFoundryOrganization("initial org 2", "initial org 2 guid", null), services),
                new OrgViewModel(new CloudFoundryOrganization("initial org 3", "initial org 3 guid", null), services)
            };

            cfivm = new CfInstanceViewModel(new CloudFoundryInstance("fake cf instance", null, null), services)
            {
                Children = initialOrgsList
            };

            var newOrgsList = new List <CloudFoundryOrganization>
            {
                new CloudFoundryOrganization("initial org 1", "initial org 1 guid", null),
                new CloudFoundryOrganization("initial org 2", "initial org 2 guid", null)
            };

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(It.IsAny <CloudFoundryInstance>()))
            .ReturnsAsync(newOrgsList);

            Assert.AreEqual(initialOrgsList.Count, cfivm.Children.Count);

            cfivm.IsExpanded = true;

            Assert.AreEqual(newOrgsList.Count, cfivm.Children.Count);
            mockCloudFoundryService.VerifyAll();
        }
示例#4
0
        public void Constructor_SetsDisplayTextToInstanceName()
        {
            string instanceName = "junk";

            cfivm = new CfInstanceViewModel(new CloudFoundryInstance(instanceName, null, null), services);

            Assert.AreEqual(instanceName, cfivm.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();
        }
示例#6
0
        public void LoadChildren_SetsSpecialDisplayText_WhenThereAreNoOrgs()
        {
            cfivm = new CfInstanceViewModel(new CloudFoundryInstance("fake cf instance", null, null), services);
            var emptyOrgsList = new List <CloudFoundryOrganization>();

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(It.IsAny <CloudFoundryInstance>()))
            .ReturnsAsync(emptyOrgsList);

            cfivm.IsExpanded = true;

            Assert.IsTrue(cfivm.DisplayText.Contains(" (no orgs)"));
        }
        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();
        }
示例#8
0
        public void TestInit()
        {
            RenewMockServices();

            MockUiDispatcherService.Setup(mock => mock.
                                          RunOnUiThread(It.IsAny <Action>()))
            .Callback <Action>(action =>
            {
                // Run whatever method is passed to MockUiDispatcherService.RunOnUiThread; do not delegate to the UI Dispatcher
                action();
            });

            _fakeTasExplorerViewModel = new TasExplorerViewModel(Services);
            _sut = new CfInstanceViewModel(FakeCfInstance, _fakeTasExplorerViewModel, Services);

            _receivedEvents       = new List <string>();
            _sut.PropertyChanged += (sender, e) =>
            {
                _receivedEvents.Add(e.PropertyName);
            };
        }
示例#9
0
        public async Task FetchChildren_SetsAuthenticationRequiredToTrue_WhenOrgsRequestFailsBecauseOfInvalidRefreshToken()
        {
            _sut = new CfInstanceViewModel(FakeCfInstance, _fakeTasExplorerViewModel, Services, expanded: true);

            var fakeFailedResult =
                new DetailedResult <List <CloudFoundryOrganization> >(succeeded: false, content: null, explanation: "junk", cmdDetails: FakeFailureCmdResult)
            {
                FailureType = FailureType.InvalidRefreshToken,
            };

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

            Assert.IsFalse(_sut.ParentTasExplorer.AuthenticationRequired);

            var result = await _sut.FetchChildren();

            Assert.IsTrue(_sut.ParentTasExplorer.AuthenticationRequired);

            MockErrorDialogService.Verify(mock => mock.
                                          DisplayErrorDialog(It.IsAny <string>(), It.IsAny <string>()),
                                          Times.Never);
        }
示例#10
0
        public void ChildrenAreLazilyLoaded_UponViewModelExpansion()
        {
            var fakeOrgsList = new List <CloudFoundryOrganization>
            {
                new CloudFoundryOrganization("org1", "org-1-id", null),
                new CloudFoundryOrganization("org2", "org-2-id", null),
                new CloudFoundryOrganization("org3", "org-3-id", null),
                new CloudFoundryOrganization("org4", "org-4-id", null)
            };

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(It.IsAny <CloudFoundryInstance>()))
            .ReturnsAsync(fakeOrgsList);

            cfivm = new CfInstanceViewModel(new CloudFoundryInstance("fake cf", null, null), services);

            // check presence of single placeholder child *before* CfInstanceViewModel is expanded
            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.AreEqual(null, cfivm.Children[0]);

            cfivm.IsExpanded = true;

            Assert.AreEqual(fakeOrgsList.Count, cfivm.Children.Count);
            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();
        }