Beispiel #1
0
 public void TestCleanup()
 {
     MockCloudFoundryService.VerifyAll();
     MockDialogService.VerifyAll();
     MockLoginViewModel.VerifyAll();
 }
Beispiel #2
0
        public async Task RefreshCfInstance_UpdatesChildrenOnCfInstanceViewModel()
        {
            var fakeOrgName1 = "fake org 1";
            var fakeOrgName2 = "fake org 2";
            var fakeOrgName3 = "fake org 3";
            var fakeOrgName4 = "fake org 4";

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

            _sut.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                // to be removed:
                new OrgViewModel(new CloudFoundryOrganization(fakeOrgName1, fakeOrgGuid1, _sut.CloudFoundryInstance), null, null, Services),
                // to stay:
                new OrgViewModel(new CloudFoundryOrganization(fakeOrgName2, fakeOrgGuid2, _sut.CloudFoundryInstance), null, null, Services, expanded: true),  // should stay expanded after refresh
                new OrgViewModel(new CloudFoundryOrganization(fakeOrgName3, fakeOrgGuid3, _sut.CloudFoundryInstance), null, null, Services, expanded: false), // should stay collapsed after refresh
            };

            var fakeOrgsList = new List <CloudFoundryOrganization>
            {
                // original:
                new CloudFoundryOrganization(fakeOrgName2, fakeOrgGuid2, _sut.CloudFoundryInstance),
                new CloudFoundryOrganization(fakeOrgName3, fakeOrgGuid3, _sut.CloudFoundryInstance),
                // new:
                new CloudFoundryOrganization(fakeOrgName4, fakeOrgGuid4, _sut.CloudFoundryInstance),
            };

            var fakeSuccessResult = new DetailedResult <List <CloudFoundryOrganization> >(succeeded: true, content: fakeOrgsList);

            Assert.AreEqual(3, _sut.Children.Count);
            OrgViewModel initialChildOrg1 = (OrgViewModel)_sut.Children[0];
            OrgViewModel initialChildOrg2 = (OrgViewModel)_sut.Children[1];
            OrgViewModel initialChildOrg3 = (OrgViewModel)_sut.Children[2];

            Assert.AreEqual(fakeOrgName1, initialChildOrg1.Org.OrgName);
            Assert.AreEqual(fakeOrgName2, initialChildOrg2.Org.OrgName);
            Assert.AreEqual(fakeOrgName3, initialChildOrg3.Org.OrgName);
            Assert.IsFalse(initialChildOrg1.IsExpanded);
            Assert.IsTrue(initialChildOrg2.IsExpanded);
            Assert.IsFalse(initialChildOrg3.IsExpanded);

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

            _receivedEvents.Clear();

            await _sut.RefreshChildren();

            Assert.AreEqual(3, _sut.Children.Count);
            OrgViewModel refreshedChildOrg1 = (OrgViewModel)_sut.Children[0];
            OrgViewModel refreshedChildOrg2 = (OrgViewModel)_sut.Children[1];
            OrgViewModel refreshedChildOrg3 = (OrgViewModel)_sut.Children[2];

            Assert.AreEqual(fakeOrgName2, refreshedChildOrg1.Org.OrgName);
            Assert.AreEqual(fakeOrgName3, refreshedChildOrg2.Org.OrgName);
            Assert.AreEqual(fakeOrgName4, refreshedChildOrg3.Org.OrgName);
            Assert.IsTrue(refreshedChildOrg1.IsExpanded);  // children that aren't new shouldn't change expansion
            Assert.IsFalse(refreshedChildOrg2.IsExpanded); // children that aren't new shouldn't change expansion
            Assert.IsFalse(refreshedChildOrg2.IsExpanded); // new children should start collapsed

            // property changed events should only be raised for "IsRefreshing" (1 to set as true, 1 to set as false)
            Assert.AreEqual(2, _receivedEvents.Count);
            Assert.AreEqual("IsRefreshing", _receivedEvents[0]);

            MockCloudFoundryService.VerifyAll();
        }
Beispiel #3
0
 public void TestCleanup()
 {
     MockCloudFoundryService.VerifyAll();
 }
Beispiel #4
0
        public async Task RefreshSpace_UpdatesChildrenOnSpaceViewModel()
        {
            var fakeAppName1 = "fake app 1";
            var fakeAppName2 = "fake app 2";
            var fakeAppName3 = "fake app 3";
            var fakeAppName4 = "fake app 4";

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

            var initialState1 = "junk";
            var initialState2 = "asdf";
            var initialState3 = "xkcd";

            _sut.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                // to be removed:
                new AppViewModel(new CloudFoundryApp(fakeAppName1, fakeAppGuid1, _sut.Space, initialState1), Services),
                // to stay:
                new AppViewModel(new CloudFoundryApp(fakeAppName2, fakeAppGuid2, _sut.Space, state: initialState2), Services), // should keep state after refresh
                new AppViewModel(new CloudFoundryApp(fakeAppName3, fakeAppGuid3, _sut.Space, state: initialState3), Services), // should change state after refresh
            };

            var fakeAppsList = new List <CloudFoundryApp>
            {
                // original:
                new CloudFoundryApp(fakeAppName2, fakeAppGuid2, _sut.Space, initialState2),
                new CloudFoundryApp(fakeAppName3, fakeAppGuid3, _sut.Space, "new state"),
                // new:
                new CloudFoundryApp(fakeAppName4, fakeAppGuid4, _sut.Space, "new app, new state"),
            };

            var fakeSuccessResult = new DetailedResult <List <CloudFoundryApp> >(succeeded: true, content: fakeAppsList);

            Assert.AreEqual(3, _sut.Children.Count);
            AppViewModel initialChildApp1 = (AppViewModel)_sut.Children[0];
            AppViewModel initialChildApp2 = (AppViewModel)_sut.Children[1];
            AppViewModel initialChildApp3 = (AppViewModel)_sut.Children[2];

            Assert.AreEqual(fakeAppName1, initialChildApp1.App.AppName);
            Assert.AreEqual(fakeAppName2, initialChildApp2.App.AppName);
            Assert.AreEqual(fakeAppName3, initialChildApp3.App.AppName);
            Assert.AreEqual(initialState2, initialChildApp2.App.State);
            Assert.AreEqual(initialState3, initialChildApp3.App.State);

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

            _receivedEvents.Clear();

            await _sut.RefreshChildren();

            Assert.AreEqual(3, _sut.Children.Count);
            AppViewModel refreshedChildApp1 = (AppViewModel)_sut.Children[0];
            AppViewModel refreshedChildApp2 = (AppViewModel)_sut.Children[1];
            AppViewModel refreshedChildApp3 = (AppViewModel)_sut.Children[2];

            Assert.AreEqual(fakeAppName2, refreshedChildApp1.App.AppName);
            Assert.AreEqual(fakeAppName3, refreshedChildApp2.App.AppName);
            Assert.AreEqual(fakeAppName4, refreshedChildApp3.App.AppName);
            Assert.AreEqual(initialState2, refreshedChildApp1.App.State);    // previous state shouldn't have changed
            Assert.AreNotEqual(initialState3, refreshedChildApp2.App.State); // previous state should have changed

            // property changed event should be raised twice for IsRefreshing (set true when starting, false when done)
            Assert.AreEqual(2, _receivedEvents.Count);
            Assert.AreEqual("IsRefreshing", _receivedEvents[0]);
            Assert.AreEqual("IsRefreshing", _receivedEvents[1]);

            MockCloudFoundryService.VerifyAll();
        }