Beispiel #1
0
        public async Task FetchChildren_ReturnsListOfOrgs_WithoutUpdatingChildren()
        {
            var fakeOrgsList = 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 fakeSuccessResult = new DetailedResult <List <CloudFoundryOrganization> >(succeeded: true, content: fakeOrgsList);

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

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

            var orgs = await _sut.FetchChildren();

            Assert.AreEqual(2, orgs.Count);
            foreach (TreeViewItemViewModel child in orgs)
            {
                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);
        }
Beispiel #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();
        }
Beispiel #3
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);
        }