public async Task RequestAccessToken_ThrowsException_WhenRequestErrors() { string fakeJsonResponse = "this is unparseable json and will cause an error"; var mockHttp = new MockHttpMessageHandler(); var request = mockHttp.When("http://some.fake.url/oauth/token") .Respond("application/json", fakeJsonResponse); var mockClient = mockHttp.ToHttpClient(); var _uaaClient = new UaaClient(mockClient); Uri uaaUri = new Uri("http://some.fake.url"); string uaaClientId = null; string uaaClientSecret = null; string cfUsername = null; string cfPassword = null; Exception expectedException = null; try { await _uaaClient.RequestAccessTokenAsync(uaaUri, uaaClientId, uaaClientSecret, cfUsername, cfPassword); } catch (Exception e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.AreEqual(1, mockHttp.GetMatchCount(request)); }
private void ConfigureServices(IServiceCollection services) { services.AddSingleton <ICloudFoundryService, CloudFoundryService>(); services.AddSingleton <IViewLocatorService, WpfViewLocatorService>(); services.AddSingleton <IDialogService, WpfDialogService>(); services.AddSingleton <ICfCliService, CfCliService>(); services.AddSingleton <ICmdProcessService, CmdProcessService>(); services.AddSingleton <IFileLocatorService, FileLocatorService>(); services.AddTransient <TanzuCloudExplorerToolWindow>(); services.AddTransient <OutputToolWindow>(); services.AddTransient <ICloudExplorerViewModel, CloudExplorerViewModel>(); services.AddTransient <ICloudExplorerView, CloudExplorerView>(); services.AddTransient <IDeploymentDialogViewModel, DeploymentDialogViewModel>(); services.AddTransient <IDeploymentDialogView, DeploymentDialogView>(); services.AddTransient <IAddCloudDialogViewModel, AddCloudDialogViewModel>(); services.AddTransient <IAddCloudDialogView, AddCloudDialogView>(); services.AddSingleton <IOutputViewModel, OutputViewModel>(); services.AddSingleton <IOutputView, OutputView>(); HttpClient concreteHttpClient = new HttpClient(); IUaaClient concreteUaaClient = new UaaClient(concreteHttpClient); services.AddSingleton(_ => concreteUaaClient); services.AddSingleton <ICfApiClient>(_ => new CfApiClient(concreteUaaClient, concreteHttpClient)); }
private void ConfigureServices(IServiceCollection services) { string assemblyBasePath = Path.GetDirectoryName(GetType().Assembly.Location); /* VSIX package */ services.AddSingleton <AsyncPackage>(this); /* Cloud Foundry API */ HttpClient httpClient = new HttpClient(); IUaaClient uaaClient = new UaaClient(httpClient); services.AddSingleton(_ => uaaClient); services.AddSingleton <ICfApiClient>(_ => new CfApiClient(uaaClient, httpClient)); /* Services */ services.AddSingleton <ICloudFoundryService, CloudFoundryService>(); services.AddSingleton <IViewLocatorService, VsViewLocatorService>(); services.AddSingleton <IDialogService, DialogService>(); services.AddSingleton <ICfCliService>(provider => new CfCliService(assemblyBasePath, provider)); services.AddSingleton <IFileService>(new FileService(assemblyBasePath)); services.AddSingleton <ILoggingService, LoggingService>(); services.AddSingleton <IToolWindowService, VsToolWindowService>(); services.AddSingleton <IThreadingService, ThreadingService>(); services.AddSingleton <IErrorDialog>(new ErrorDialogService(this)); services.AddSingleton <IUiDispatcherService, UiDispatcherService>(); services.AddSingleton <IThemeService>(new ThemeService()); services.AddTransient <ICommandProcessService, CommandProcessService>(); services.AddSingleton <ISerializationService, SerializationService>(); services.AddSingleton <IDataPersistenceService>(provider => new DataPersistenceService(this, provider)); /* Tool Windows */ services.AddTransient <TanzuTasExplorerToolWindow>(); services.AddTransient <OutputToolWindow>(); /* View Models */ services.AddTransient <IOutputViewModel, OutputViewModel>(); services.AddSingleton <ITasExplorerViewModel, TasExplorerViewModel>(); services.AddSingleton <ISsoDialogViewModel, SsoDialogViewModel>(); // must be a singleton for the view to properly show prompt services.AddSingleton <ILoginViewModel, LoginViewModel>(); services.AddTransient <IDeploymentDialogViewModel, DeploymentDialogViewModel>(); services.AddTransient <ILoginViewModel, LoginViewModel>(); services.AddSingleton <IAppDeletionConfirmationViewModel, AppDeletionConfirmationViewModel>(); /* Views */ services.AddTransient <IOutputView, OutputView>(); services.AddSingleton <ILoginView, LoginView>(); services.AddTransient <ITasExplorerView, TasExplorerView>(); services.AddTransient <IDeploymentDialogView, DeploymentDialogView>(); services.AddTransient <ISsoDialogView, SsoDialogView>(); services.AddTransient <IAppDeletionConfirmationView, AppDeletionConfirmationView>(); }
public async Task RequestAccessToken_ReturnsResponseCode_WhenResponseCodeIsNot200() { var mockHttp = new MockHttpMessageHandler(); var request = mockHttp.When("http://some.fake.url/oauth/token") .Respond(HttpStatusCode.Unauthorized); var mockClient = mockHttp.ToHttpClient(); var _uaaClient = new UaaClient(mockClient); Uri uaaUri = new Uri("http://some.fake.url"); string uaaClientId = null; string uaaClientSecret = null; string cfUsername = null; string cfPassword = null; var expectedResult = HttpStatusCode.Unauthorized; var actualResult = await _uaaClient.RequestAccessTokenAsync(uaaUri, uaaClientId, uaaClientSecret, cfUsername, cfPassword); Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(1, mockHttp.GetMatchCount(request)); }
private void ConfigureServices(IServiceCollection services) { services.AddSingleton <ICloudFoundryService, CloudFoundryService>(); services.AddSingleton <IViewLocatorService, WpfViewLocatorService>(); services.AddSingleton <IDialogService, WpfDialogService>(); services.AddTransient <IMainWindowViewModel, MainWindowViewModel>(); services.AddTransient <IMainWindowView, MainWindowView>(); services.AddTransient <ICloudExplorerViewModel, CloudExplorerViewModel>(); services.AddTransient <ICloudExplorerView, CloudExplorerView>(); services.AddTransient <IAddCloudDialogViewModel, AddCloudDialogViewModel>(); services.AddTransient <IAddCloudDialogView, AddCloudDialogView>(); HttpClient concreteHttpClient = new HttpClient(); IUaaClient concreteUaaClient = new UaaClient(concreteHttpClient); services.AddSingleton <IUaaClient>(_ => concreteUaaClient); services.AddSingleton <ICfApiClient>(_ => new CfApiClient(concreteUaaClient, concreteHttpClient)); }
public async Task RequestAccessToken_ReturnsResponseCode_WhenResponseCodeIs200() { string fakeJsonString = "{'token' : 'testToken'}"; var mockHttp = new MockHttpMessageHandler(); var request = mockHttp.When("http://some.fake.url/oauth/token") .Respond("application/json", fakeJsonString); var mockClient = mockHttp.ToHttpClient(); var uaaClient = new UaaClient(mockClient); Uri uaaUri = new Uri("http://some.fake.url"); string uaaClientId = null; string uaaClientSecret = null; string cfUsername = null; string cfPassword = null; var expectedResult = HttpStatusCode.OK; var actualResult = await uaaClient.RequestAccessTokenAsync(uaaUri, uaaClientId, uaaClientSecret, cfUsername, cfPassword); Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(1, mockHttp.GetMatchCount(request)); }