public void TestUpdatingProjectId()
        {
            CredentialStoreMock.Raise(
                cs => cs.CurrentProjectIdChanged += null, CredentialsStore.Default, null);

            Assert.IsTrue(_objectUnderTest.IsAccountChanged);
        }
Exemple #2
0
        public void TestDisposeDisablesResetProjectId()
        {
            _objectUnderTest.Dispose();
            CredentialStoreMock.Raise(cs => cs.Reset += null, CredentialsStore.Default, null);

            Assert.IsFalse(_objectUnderTest.IsAccountChanged);
        }
        public void TestDeleteCredentialsForInstance_DeletesFile()
        {
            const string testUserName     = "******";
            const string testProjectId    = "test-project-id";
            const string testZone         = "test-zone";
            const string testInstanceName = "TestInstanceName";

            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns(testProjectId);
            _fileExistsMock.Setup(f => f(It.IsAny <string>())).Returns(true);

            var testInstance = new Instance
            {
                Name = testInstanceName,
                Zone = $"https://uri/zones/{testZone}"
            };

            _objectUnderTest.DeleteCredentialsForInstance(testInstance, new WindowsInstanceCredentials(testUserName, "password"));

            _deleteFileMock.Verify(
                f => f(
                    It.Is <string>(
                        s => Path.GetFileNameWithoutExtension(s) == testUserName &&
                        Path.GetExtension(s) == WindowsCredentialsStore.PasswordFileExtension &&
                        GetNameAtDepth(s, 1) == testInstanceName &&
                        GetNameAtDepth(s, 2) == testZone &&
                        GetNameAtDepth(s, 3) == testProjectId)));
        }
        public void TestCurrentAccountChanged_UpdatesGPlusDataSource()
        {
            IGPlusDataSource origianlGPlusDataSource = _objectUnderTest.GPlusDataSource;

            CredentialStoreMock.Raise(cs => cs.CurrentAccountChanged += null, EventArgs.Empty);

            Assert.AreNotEqual(origianlGPlusDataSource, _objectUnderTest.GPlusDataSource);
        }
        public void TestCreateGkeDataSource_BuildsFromCurrentAccount()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(_userAccount.GetGoogleCredential());

            IGkeDataSource result = _objectUnderTest.CreateGkeDataSource();

            Assert.That.DataSource(result).IsBuiltFrom(_userAccount);
        }
        public void TestGPlusDataSource_Returns()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(_userAccount.GetGoogleCredential());

            IGPlusDataSource result = _objectUnderTest.GPlusDataSource;

            Assert.That.DataSource(result).IsBuiltFrom(_userAccount);
        }
Exemple #7
0
        public void TestSignIn_PromptsForNoUser()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount).Returns(() => null);

            _objectUnderTest.SignIn();

            PackageMock.Verify(p => p.UserPromptService.PromptUser(It.IsAny <ManageAccountsWindowContent>()));
        }
        public void TestIsCurrentAccount_True()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount).Returns(s_defaultUserAccount);

            var objectUnderTest = new UserAccountViewModel(s_defaultUserAccount);

            Assert.IsTrue(objectUnderTest.IsCurrentAccount);
        }
        public void Test0ArgCreatePlusDataSource_ReturnsNullForNoCredentials()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(() => null);

            IGPlusDataSource result = _objectUnderTest.CreatePlusDataSource();

            Assert.IsNull(result);
        }
        public void TestIsGridVisibleProperty()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns("new-project-id");
            CredentialStoreMock.Raise(cs => cs.CurrentProjectIdChanged += null, CredentialsStore.Default, null);

            Assert.IsTrue(_objectUnderTest.IsGridVisible);
            CollectionAssert.Contains(_propertiesChanged, nameof(_objectUnderTest.IsGridVisible));
        }
        public void TestResourceManagerDataSource_ReturnsNullForNoCredentials()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(() => null);

            IResourceManagerDataSource result = _objectUnderTest.ResourceManagerDataSource;

            Assert.IsNull(result);
        }
        public void TestIsCurrentAccount_FalseForNoCurrentAccount()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount).Returns(() => null);

            var objectUnderTest = new UserAccountViewModel(s_defaultUserAccount);

            Assert.IsFalse(objectUnderTest.IsCurrentAccount);
        }
Exemple #13
0
        public void TestDoubleClickedItem_UpdatesCurrentAccount()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount.AccountName).Returns("CurrentAccountName");
            var userAccount = Mock.Of <IUserAccount>(ua => ua.AccountName == "SelectedAccountName");

            _objectUnderTest.DoubleClickedItem(new UserAccountViewModel(userAccount));

            CredentialStoreMock.Verify(cs => cs.UpdateCurrentAccount(userAccount));
        }
Exemple #14
0
        public void TestDoubleClickedItem_InvokesClose()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount.AccountName).Returns("CurrentAccountName");

            _objectUnderTest.DoubleClickedItem(
                new UserAccountViewModel(Mock.Of <IUserAccount>(ua => ua.AccountName == "SelectedAccountName")));

            _closeHandlerMock.Verify(a => a());
        }
        public void TestProjectIdReset()
        {
            _objectUnderTest.Frame = _frameMock.Object;
            ILogsViewerViewModel oldViewModel = _objectUnderTest.ViewModel;

            CredentialStoreMock.Raise(cs => cs.Reset += null, CredentialsStore.Default, null);

            Assert.AreNotEqual(oldViewModel, _objectUnderTest.ViewModel);
        }
Exemple #16
0
        public void TestInvalidateAllPropertiesEmptyProjectId()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns("");
            AsyncProperty oldAction = _objectUnderTest.AsyncAction;

            _objectUnderTest.InvalidateAllProperties();

            Assert.AreEqual(oldAction, _objectUnderTest.AsyncAction);
        }
        public void TestCurrentAccountChanged_InvokesDataSourcesUpdated()
        {
            var eventHandlerMock = new Mock <Action <object, EventArgs> >();

            _objectUnderTest.DataSourcesUpdated += new EventHandler(eventHandlerMock.Object);

            CredentialStoreMock.Raise(cs => cs.CurrentAccountChanged += null, EventArgs.Empty);

            eventHandlerMock.Verify(h => h(_objectUnderTest, EventArgs.Empty));
        }
        public void TestValidateProjectAsync_NoProjectSetsNeedsAppCreated()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns(() => null);
            _objectUnderTest.NeedsAppCreated = true;

            _objectUnderTest.OnVisible();

            Assert.IsFalse(_objectUnderTest.NeedsAppCreated);
            _gaeDataSourceMock.Verify(src => src.GetApplicationAsync(), Times.Never());
        }
Exemple #19
0
        public void TestChangeUserCommandNoUser()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(() => null);
            _testObject = BuildTestObject();

            _testObject.ChangeUserCommand.Execute(null);

            _manageAccoutMock.Verify(f => f(), Times.Once);
            Assert.IsNull(_testObject.LoadTask);
        }
Exemple #20
0
        public void TestChangeUserCommand_UpdatesHasAccount()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(() => null);
            _testObject = BuildTestObject();

            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(s_defaultAccount);
            _testObject.ChangeUserCommand.Execute(null);

            Assert.IsTrue(_testObject.HasAccount);
        }
        public void TestCloseDisablesProjectIdReset()
        {
            _objectUnderTest.Frame = _frameMock.Object;
            ILogsViewerViewModel oldViewModel = _objectUnderTest.ViewModel;

            ((IVsWindowPane)_objectUnderTest).ClosePane();
            CredentialStoreMock.Raise(cs => cs.Reset += null, CredentialsStore.Default, null);

            Assert.AreEqual(oldViewModel, _objectUnderTest.ViewModel);
        }
Exemple #22
0
        public void TestDoubleClickedItem_ShortCircutsCurrentAccount()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount.AccountName).Returns("CurrentAccountName");
            var userAccount = Mock.Of <IUserAccount>(ua => ua.AccountName == "CurrentAccountName");

            _objectUnderTest.DoubleClickedItem(new UserAccountViewModel(userAccount));

            CredentialStoreMock.Verify(cs => cs.UpdateCurrentAccount(userAccount), Times.Never);
            _closeHandlerMock.Verify(a => a(), Times.Never);
        }
        public void TestChangeUserCommand_UpdatesHasAccount()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(() => null);
            _testObject = new PickProjectIdViewModel(DefaultHelpText, false);

            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(s_defaultAccount);
            _testObject.ChangeUserCommand.Execute(null);

            Assert.IsTrue(_testObject.HasAccount);
        }
Exemple #24
0
        public void TestEnableMenuItemOnValidProjectIdInvalidProjectId()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns(() => null);
            var menuCommand = new OleMenuCommand((sender, args) => { }, (sender, args) => { },
                                                 (sender, args) => { }, new CommandID(Guid.Empty, 0));

            ToolWindowCommandUtils.EnableMenuItemOnValidProjectId(menuCommand, null);

            Assert.IsFalse(menuCommand.Enabled);
        }
Exemple #25
0
        public void TestSetAsCurrentAccount_UpdatesCurrentAccount()
        {
            var userAccount = Mock.Of <IUserAccount>(ua => ua.AccountName == "SelectedAccountName");

            _objectUnderTest.CurrentUserAccount = new UserAccountViewModel(userAccount);

            _objectUnderTest.SetAsCurrentAccountCommand.Execute(null);

            CredentialStoreMock.Verify(cs => cs.UpdateCurrentAccount(userAccount));
        }
Exemple #26
0
        public void TestCreateClusterCommand()
        {
            const string projectId = "test-project-id";

            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns(projectId);
            _objectUnderTest.CreateClusterCommand.Execute(null);

            _startProcessMock.Verify(
                f => f(string.Format(GkeStepViewModel.GkeAddClusterUrlFormat, projectId)), Times.Once);
        }
        public void TestRefreshInstancesCommand_EnabledByValidProject()
        {
            _getInstanceListTaskSource.SetResult(s_allInstances);
            _objectUnderTest.OnVisible();

            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns("project-id");
            CredentialStoreMock.Raise(cs => cs.CurrentProjectIdChanged += null, CredentialsStore.Default, null);

            Assert.IsTrue(_objectUnderTest.RefreshInstancesCommand.CanExecuteCommand);
        }
Exemple #28
0
        public async Task TestRefreshCommand_EmptyStateMessageSetWhenNoProject()
        {
            CredentialStoreMock.Setup(cs => cs.CurrentAccount).Returns(new UserAccount());

            _objectUnderTest.RefreshCommand.Execute(null);
            _currentProjectSource.SetResult(null);
            await _objectUnderTest.RefreshCommand.LatestExecution;

            Assert.AreEqual(Resources.CloudExploreNoProjectMessage, _objectUnderTest.EmptyStateMessage);
        }
        public void TestChangeUserCommandNoUser()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentAccount).Returns(() => null);
            _testObject = new PickProjectIdViewModel(DefaultHelpText, false);

            _testObject.ChangeUserCommand.Execute(null);

            PackageMock.Verify(p => p.UserPromptService.PromptUser(It.IsAny <ManageAccountsWindowContent>()));
            Assert.IsNull(_testObject.LoadTask);
        }
        public void TestValidateProjectAsync_MissingProjectDisablesCommands()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentProjectId).Returns(() => null);
            _objectUnderTest.RefreshClustersListCommand.CanExecuteCommand = true;
            _objectUnderTest.CreateClusterCommand.CanExecuteCommand       = true;

            _objectUnderTest.OnVisible();

            Assert.IsFalse(_objectUnderTest.RefreshClustersListCommand.CanExecuteCommand);
            Assert.IsFalse(_objectUnderTest.CreateClusterCommand.CanExecuteCommand);
        }