|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.IO;
|
4 | 4 | using System.Net.Http;
|
|
13 | 13 |
|
14 | 14 | namespace E2ETests
|
15 | 15 | {
|
16 |
| - // Uses ports ranging 5050 - 5060. |
17 | 16 | public class NtlmAuthenticationTests : IDisposable
|
18 | 17 | {
|
19 |
| - private readonly XunitLogger _logger; |
| 18 | + private readonly ILoggerFactory _loggerFactory; |
20 | 19 |
|
21 | 20 | public NtlmAuthenticationTests(ITestOutputHelper output)
|
22 | 21 | {
|
23 |
| - _logger = new XunitLogger(output, LogLevel.Information); |
| 22 | + _loggerFactory = new LoggerFactory() |
| 23 | + .AddXunit(output); |
24 | 24 | }
|
25 | 25 |
|
26 | 26 | [ConditionalTheory, Trait("E2Etests", "E2Etests")]
|
27 | 27 | [OSSkipCondition(OperatingSystems.Linux)]
|
28 | 28 | [OSSkipCondition(OperatingSystems.MacOSX)]
|
29 |
| - [InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable, "http://localhost:5050/")] |
30 |
| - [InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone, "http://localhost:5051/")] |
31 |
| - [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable, "http://localhost:5052/")] |
32 |
| - [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone, "http://localhost:5053/")] |
33 |
| - public async Task NtlmAuthenticationTest(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType, string applicationBaseUrl) |
| 29 | + [InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable)] |
| 30 | + [InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone)] |
| 31 | + [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable)] |
| 32 | + [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone)] |
| 33 | + public async Task NtlmAuthenticationTest(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType) |
34 | 34 | {
|
35 |
| - using (_logger.BeginScope("NtlmAuthenticationTest")) |
| 35 | + try |
36 | 36 | {
|
37 |
| - var musicStoreDbName = DbUtils.GetUniqueName(); |
38 |
| - |
39 |
| - var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture) |
| 37 | + Console.WriteLine("NtlmAuthenticationTest"); |
| 38 | + var logger = _loggerFactory.CreateLogger($"NtlmAuthentication:{serverType}:{runtimeFlavor}:{architecture}:{applicationType}"); |
| 39 | + using (logger.BeginScope("NtlmAuthenticationTest")) |
40 | 40 | {
|
41 |
| - PublishApplicationBeforeDeployment = true, |
42 |
| - PreservePublishedApplicationForDebugging = Helpers.PreservePublishedApplicationForDebugging, |
43 |
| - TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net451" : "netcoreapp1.1", |
44 |
| - Configuration = Helpers.GetCurrentBuildConfiguration(), |
45 |
| - ApplicationType = applicationType, |
46 |
| - ApplicationBaseUriHint = applicationBaseUrl, |
47 |
| - EnvironmentName = "NtlmAuthentication", //Will pick the Start class named 'StartupNtlmAuthentication' |
48 |
| - ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "NtlmAuthentation.config")) : null, |
49 |
| - SiteName = "MusicStoreNtlmAuthentication", //This is configured in the NtlmAuthentication.config |
50 |
| - UserAdditionalCleanup = parameters => |
51 |
| - { |
52 |
| - DbUtils.DropDatabase(musicStoreDbName, _logger); |
53 |
| - } |
54 |
| - }; |
| 41 | + var musicStoreDbName = DbUtils.GetUniqueName(); |
55 | 42 |
|
56 |
| - if (applicationType == ApplicationType.Standalone) |
57 |
| - { |
58 |
| - deploymentParameters.AdditionalPublishParameters = " -r " + RuntimeEnvironment.GetRuntimeIdentifier(); |
59 |
| - } |
| 43 | + var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture) |
| 44 | + { |
| 45 | + PublishApplicationBeforeDeployment = true, |
| 46 | + PreservePublishedApplicationForDebugging = Helpers.PreservePublishedApplicationForDebugging, |
| 47 | + TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net451" : "netcoreapp1.1", |
| 48 | + Configuration = Helpers.GetCurrentBuildConfiguration(), |
| 49 | + ApplicationType = applicationType, |
| 50 | + EnvironmentName = "NtlmAuthentication", //Will pick the Start class named 'StartupNtlmAuthentication' |
| 51 | + ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "NtlmAuthentation.config")) : null, |
| 52 | + SiteName = "MusicStoreNtlmAuthentication", //This is configured in the NtlmAuthentication.config |
| 53 | + UserAdditionalCleanup = parameters => |
| 54 | + { |
| 55 | + DbUtils.DropDatabase(musicStoreDbName, logger); |
| 56 | + } |
| 57 | + }; |
60 | 58 |
|
61 |
| - // Override the connection strings using environment based configuration |
62 |
| - deploymentParameters.EnvironmentVariables |
63 |
| - .Add(new KeyValuePair<string, string>( |
64 |
| - MusicStoreConfig.ConnectionStringKey, |
65 |
| - DbUtils.CreateConnectionString(musicStoreDbName))); |
| 59 | + if (applicationType == ApplicationType.Standalone) |
| 60 | + { |
| 61 | + deploymentParameters.AdditionalPublishParameters = " -r " + RuntimeEnvironment.GetRuntimeIdentifier(); |
| 62 | + } |
66 | 63 |
|
67 |
| - using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, _logger)) |
68 |
| - { |
69 |
| - var deploymentResult = deployer.Deploy(); |
70 |
| - var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true }; |
71 |
| - var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) }; |
| 64 | + // Override the connection strings using environment based configuration |
| 65 | + deploymentParameters.EnvironmentVariables |
| 66 | + .Add(new KeyValuePair<string, string>( |
| 67 | + MusicStoreConfig.ConnectionStringKey, |
| 68 | + DbUtils.CreateConnectionString(musicStoreDbName))); |
72 | 69 |
|
73 |
| - // Request to base address and check if various parts of the body are rendered & measure the cold startup time. |
74 |
| - var response = await RetryHelper.RetryRequest(async () => |
| 70 | + using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, _loggerFactory)) |
75 | 71 | {
|
76 |
| - return await httpClient.GetAsync(string.Empty); |
77 |
| - }, logger: _logger, cancellationToken: deploymentResult.HostShutdownToken); |
| 72 | + var deploymentResult = await deployer.DeployAsync(); |
| 73 | + var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true }; |
| 74 | + var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) }; |
| 75 | + |
| 76 | + // Request to base address and check if various parts of the body are rendered & measure the cold startup time. |
| 77 | + var response = await RetryHelper.RetryRequest(async () => |
| 78 | + { |
| 79 | + return await httpClient.GetAsync(string.Empty); |
| 80 | + }, logger: logger, cancellationToken: deploymentResult.HostShutdownToken); |
78 | 81 |
|
79 |
| - Assert.False(response == null, "Response object is null because the client could not " + |
80 |
| - "connect to the server after multiple retries"); |
| 82 | + Assert.False(response == null, "Response object is null because the client could not " + |
| 83 | + "connect to the server after multiple retries"); |
81 | 84 |
|
82 |
| - var validator = new Validator(httpClient, httpClientHandler, _logger, deploymentResult); |
| 85 | + var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult); |
83 | 86 |
|
84 |
| - Console.WriteLine("Verifying home page"); |
85 |
| - await validator.VerifyNtlmHomePage(response); |
| 87 | + Console.WriteLine("Verifying home page"); |
| 88 | + await validator.VerifyNtlmHomePage(response); |
86 | 89 |
|
87 |
| - Console.WriteLine("Verifying access to store with permissions"); |
88 |
| - await validator.AccessStoreWithPermissions(); |
| 90 | + Console.WriteLine("Verifying access to store with permissions"); |
| 91 | + await validator.AccessStoreWithPermissions(); |
89 | 92 |
|
90 |
| - _logger.LogInformation("Variation completed successfully."); |
| 93 | + logger.LogInformation("Variation completed successfully."); |
| 94 | + } |
91 | 95 | }
|
92 | 96 | }
|
| 97 | + finally |
| 98 | + { |
| 99 | + Console.WriteLine("Finished NtlmAuthenticationTest"); |
| 100 | + } |
93 | 101 | }
|
94 | 102 |
|
95 | 103 | public void Dispose()
|
96 | 104 | {
|
97 |
| - _logger.Dispose(); |
| 105 | + _loggerFactory.Dispose(); |
98 | 106 | }
|
99 | 107 | }
|
100 | 108 | }
|
0 commit comments