public UserAccountViewModel(IUserAccount userAccount) { UserAccount = userAccount; AccountName = userAccount.AccountName; Task <Person> personTask; try { var dataSourceFactory = GoogleCloudExtensionPackage.Instance.GetMefService <IDataSourceFactory>(); IGPlusDataSource dataSource = dataSourceFactory.CreatePlusDataSource(userAccount.GetGoogleCredential()); personTask = dataSource.GetProfileAsync(); } catch (Exception) { personTask = Task.FromResult <Person>(null); } // TODO: Show the default image while it is being loaded. ProfilePictureAsync = AsyncPropertyUtils.CreateAsyncProperty(personTask, x => x?.Image.Url); NameAsync = AsyncPropertyUtils.CreateAsyncProperty( personTask, x => x?.DisplayName, Resources.CloudExplorerLoadingMessage); }
public void Test0ArgCreatePlusDataSource_ReturnsNullForNoCredentials() { CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(() => null); IGPlusDataSource result = _objectUnderTest.CreatePlusDataSource(); Assert.IsNull(result); }
public void TestCurrentAccountChanged_UpdatesGPlusDataSource() { IGPlusDataSource origianlGPlusDataSource = _objectUnderTest.GPlusDataSource; CredentialStoreMock.Raise(cs => cs.CurrentAccountChanged += null, EventArgs.Empty); Assert.AreNotEqual(origianlGPlusDataSource, _objectUnderTest.GPlusDataSource); }
public void TestGPlusDataSource_Returns() { CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(_userAccount.GetGoogleCredential()); IGPlusDataSource result = _objectUnderTest.GPlusDataSource; Assert.That.DataSource(result).IsBuiltFrom(_userAccount); }
protected override void BeforeEach() { _gPlusDataSourceMock = new Mock <IGPlusDataSource>(); _mockedResourceManagerDataSource = null; _mockedGPlusDataSource = null; DataSourceFactoryMock.Setup(f => f.CreateResourceManagerDataSource()) .Returns(() => _mockedResourceManagerDataSource); DataSourceFactoryMock.Setup(f => f.CreatePlusDataSource()).Returns(() => _mockedGPlusDataSource); _mockedSelectionUtils = Mock.Of <ISelectionUtils>(); _objectUnderTest = new CloudExplorerViewModel(_mockedSelectionUtils); _propertiesChanged = new SynchronizedCollection <string>(); _objectUnderTest.PropertyChanged += (sender, args) => _propertiesChanged.Add(args.PropertyName); }
public void TestGPlusDataSource_ResetByAccountChange() { CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential) .Returns(() => null); IGPlusDataSource emptyCredentailsSource = _objectUnderTest.GPlusDataSource; CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential) .Returns(_userAccount.GetGoogleCredential()); CredentialStoreMock.Raise(cs => cs.CurrentAccountChanged += null, EventArgs.Empty); IGPlusDataSource updatedCredentialsSource = _objectUnderTest.GPlusDataSource; Assert.IsNull(emptyCredentailsSource); Assert.That.DataSource(updatedCredentialsSource).IsBuiltFrom(_userAccount); }
public async Task TestRefreshCommand_ResetsCredentialsAsync() { _mockedGPlusDataSource = _gPlusDataSourceMock.Object; const string profileName = "NewProfileName"; var getProfileResult = new Person { Emails = new[] { new Person.EmailsData { Value = profileName } }, Image = new Person.ImageData() }; _gPlusDataSourceMock.Setup(ds => ds.GetProfileAsync()).Returns(Task.FromResult(getProfileResult)); _propertiesChanged.Clear(); _objectUnderTest.RefreshCommand.Execute(null); await _objectUnderTest.RefreshCommand.LatestExecution.SafeTask; CollectionAssert.Contains(_propertiesChanged, "ProfileNameAsync"); Assert.AreEqual(profileName, _objectUnderTest.ProfileNameAsync.Value); }
public void Test1ArgCreatePlusDataSource_Returns() { var userAccount = new UserAccount { AccountName = "TestAccountName", ClientId = "TestClientId", ClientSecret = "TestClientSecret", RefreshToken = "TestRefreshToken" }; IGPlusDataSource result = _objectUnderTest.CreatePlusDataSource(userAccount.GetGoogleCredential()); var dataSource = (GPlusDataSource)result; var googleCredential = (GoogleCredential)dataSource.Service.HttpClientInitializer; var userCredential = (UserCredential)googleCredential.UnderlyingCredential; var flow = (GoogleAuthorizationCodeFlow)userCredential.Flow; Assert.AreEqual(userAccount.ClientSecret, flow.ClientSecrets.ClientSecret); Assert.AreEqual(userAccount.ClientId, flow.ClientSecrets.ClientId); Assert.AreEqual(userAccount.RefreshToken, userCredential.Token.RefreshToken); Assert.AreEqual(GoogleCloudExtensionPackage.Instance.VersionedApplicationName, dataSource.Service.ApplicationName); }
public UserAccountViewModel(IUserAccount userAccount) { UserAccount = userAccount; AccountName = userAccount.AccountName; Task <Person> personTask; try { IDataSourceFactory dataSourceFactory = DataSourceFactory.Default; IGPlusDataSource dataSource = dataSourceFactory.CreatePlusDataSource(userAccount.GetGoogleCredential()); personTask = dataSource.GetProfileAsync(); } catch (Exception) { personTask = Task.FromResult <Person>(null); } // TODO: Show the default image while it is being loaded. ProfilePictureAsync = AsyncProperty.Create(personTask, x => x?.Image.Url); NameAsync = AsyncProperty.Create(personTask, x => x?.DisplayName, Resources.UiLoadingMessage); }
public void Test1ArgCreatePlusDataSource_ReturnsNullForNoCredentials() { IGPlusDataSource result = _objectUnderTest.CreatePlusDataSource(null); Assert.IsNull(result); }
public void Test1ArgCreatePlusDataSource_Returns() { IGPlusDataSource result = _objectUnderTest.CreatePlusDataSource(_userAccount.GetGoogleCredential()); Assert.That.DataSource(result).IsBuiltFrom(_userAccount); }