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();
        }
示例#2
0
        public async Task FetchChildren_ReturnsListOfSpaces_WithoutUpdatingChildren()
        {
            List <CloudFoundrySpace> fakeSpacesList = new List <CloudFoundrySpace>
            {
                new CloudFoundrySpace("fake space name 1", "fake space id 1", FakeCfOrg),
                new CloudFoundrySpace("fake space name 2", "fake space id 2", FakeCfOrg),
            };

            var fakeSuccessResponse = new DetailedResult <List <CloudFoundrySpace> >(
                content: fakeSpacesList,
                succeeded: true,
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(FakeCfOrg, true, It.IsAny <int>()))
            .ReturnsAsync(fakeSuccessResponse);

            /* pre-check presence of placeholder */
            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());

            var spaces = await _sut.FetchChildren();

            Assert.AreEqual(2, spaces.Count);
            foreach (TreeViewItemViewModel child in spaces)
            {
                Assert.AreEqual(_sut, child.Parent);
            }

            /* confirm presence of placeholder */
            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());

            // property changed events should not be raised
            Assert.AreEqual(0, _receivedEvents.Count);
        }
示例#3
0
        public async Task FetchChildren_SetsAuthenticationRequiredToTrue_WhenOrgsRequestFailsBecauseOfInvalidRefreshToken()
        {
            _sut = new OrgViewModel(FakeCfOrg, _fakeCfInstanceViewModel, _fakeTasExplorerViewModel, Services, expanded: true);

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

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(_sut.Org, 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);
        }