diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SetupFixtures.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/SetupFixtures.cs deleted file mode 100644 index 97ace4d70d..0000000000 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SetupFixtures.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace E2ETests -{ - public class DefaultLocationSetupFixture : BaseStoreSetupFixture - { - public DefaultLocationSetupFixture() : - base( - createInDefaultLocation: true, - loggerName: nameof(DefaultLocationSetupFixture)) - { - } - } - - public class CustomLocationSetupFixture : BaseStoreSetupFixture - { - public CustomLocationSetupFixture() : - base( - createInDefaultLocation: false, - loggerName: nameof(CustomLocationSetupFixture)) - { - } - } -} diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStore.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStore.cs deleted file mode 100644 index f8a970ecf3..0000000000 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStore.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Server.IntegrationTesting; -using Microsoft.AspNetCore.Testing.xunit; -using Xunit; -using Xunit.Abstractions; - -namespace E2ETests -{ - public class SmokeTestsUsingDefaultLocation : IClassFixture - { - private readonly DefaultLocationSetupFixture _testFixture; - private readonly ITestOutputHelper _output; - - public SmokeTestsUsingDefaultLocation( - DefaultLocationSetupFixture testFixure, - ITestOutputHelper output) - { - _testFixture = testFixure; - _output = output; - } - - [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] - [ConditionalFact] - [Trait("smoketests", "usestore")] - [Trait("smoketests", "usestore-defaultlocation")] - public async Task DefaultLocation_Kestrel() - { - var tests = new SmokeTestsUsingStoreHelper(_output); - await tests.SmokeTestSuite( - ServerType.Kestrel, - _testFixture.CreateStoreInDefaultLocation, - _testFixture.StoreDirectory); - } - - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] - [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] - [ConditionalFact] - [Trait("smoketests", "usestore")] - [Trait("smoketests", "usestore-defaultlocation")] - public async Task DefaultLocation_WebListener() - { - var tests = new SmokeTestsUsingStoreHelper(_output); - await tests.SmokeTestSuite( - ServerType.WebListener, - _testFixture.CreateStoreInDefaultLocation, - _testFixture.StoreDirectory); - } - } - - public class SmokeTestsUsingInCustomLocation : IClassFixture - { - private readonly CustomLocationSetupFixture _testFixture; - private readonly ITestOutputHelper _output; - - public SmokeTestsUsingInCustomLocation( - CustomLocationSetupFixture testFixure, - ITestOutputHelper output) - { - _testFixture = testFixure; - _output = output; - } - - [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] - [ConditionalFact] - [Trait("smoketests", "usestore")] - [Trait("smoketests", "usestore-customlocation")] - public async Task CustomLocation_Kestrel() - { - var tests = new SmokeTestsUsingStoreHelper(_output); - await tests.SmokeTestSuite( - ServerType.Kestrel, - _testFixture.CreateStoreInDefaultLocation, - _testFixture.StoreDirectory); - } - - [OSSkipCondition(OperatingSystems.Linux)] - [OSSkipCondition(OperatingSystems.MacOSX)] - [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] - [ConditionalFact] - [Trait("smoketests", "usestore")] - [Trait("smoketests", "usestore-customlocation")] - public async Task CustomLocation_WebListener() - { - var tests = new SmokeTestsUsingStoreHelper(_output); - await tests.SmokeTestSuite( - ServerType.WebListener, - _testFixture.CreateStoreInDefaultLocation, - _testFixture.StoreDirectory); - } - } -} \ No newline at end of file diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs index 806d71e998..00643bf10b 100644 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Store.cs @@ -7,7 +7,6 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Server.IntegrationTesting; -using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Logging; using NuGet.Configuration; using NuGet.Packaging.Core; @@ -29,9 +28,9 @@ namespace E2ETests _logger = loggerFactory.CreateLogger(); } - public string CreateStore(bool createInDefaultLocation) + public string CreateStore() { - var storeParentDir = GetStoreParentDirectory(createInDefaultLocation); + var storeParentDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); InstallStore(storeParentDir); @@ -226,22 +225,5 @@ namespace E2ETests } } } - - private string GetStoreParentDirectory(bool createInDefaultLocation) - { - string storeParentDir; - if (createInDefaultLocation) - { - // On Windows: ..\.dotnet\x64\dotnet.exe - // On Linux : ../.dotnet/dotnet - var dotnetDir = new FileInfo(DotNetMuxer.MuxerPath).Directory.FullName; - storeParentDir = dotnetDir; - } - else - { - storeParentDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - } - return storeParentDir; - } } } diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/BaseStoreSetupFixture.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs similarity index 52% rename from test/MusicStore.E2ETests/SmokeTestsUsingStore/BaseStoreSetupFixture.cs rename to test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs index c53658f22e..3960a6265b 100644 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/BaseStoreSetupFixture.cs +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/StoreSetupFixture.cs @@ -4,36 +4,31 @@ using Microsoft.Extensions.Logging.Testing; namespace E2ETests { - public class BaseStoreSetupFixture : IDisposable + public class StoreSetupFixture : IDisposable { private readonly IDisposable _logToken; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly Store _store; - public BaseStoreSetupFixture(bool createInDefaultLocation, string loggerName) + public StoreSetupFixture() { if (!Store.IsEnabled()) { return; } - var testLog = AssemblyTestLog.ForAssembly(typeof(BaseStoreSetupFixture).Assembly); + var loggerName = nameof(StoreSetupFixture); + var testLog = AssemblyTestLog.ForAssembly(typeof(StoreSetupFixture).Assembly); ILoggerFactory loggerFactory; _logToken = testLog.StartTestLog(null, loggerName, out loggerFactory, testName: loggerName); - _logger = loggerFactory.CreateLogger(); - - CreateStoreInDefaultLocation = createInDefaultLocation; - - _logger.LogInformation( - "Setting up store in the location: {location}", - createInDefaultLocation ? "default" : "custom"); - + _logger = loggerFactory.CreateLogger(); + _store = new Store(loggerFactory); - StoreDirectory = _store.CreateStore(createInDefaultLocation); - } + StoreDirectory = _store.CreateStore(); - public bool CreateStoreInDefaultLocation { get; } + _logger.LogInformation($"Store was setup at {StoreDirectory}"); + } public string StoreDirectory { get; } diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStoreHelper.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs similarity index 81% rename from test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStoreHelper.cs rename to test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs index 4f97573842..37397d4e99 100644 --- a/test/MusicStore.E2ETests/SmokeTestsUsingStore/SmokeTestsUsingStoreHelper.cs +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/TestHelper.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IntegrationTesting; @@ -6,21 +7,21 @@ using Microsoft.Extensions.Logging.Testing; using Xunit; using Xunit.Abstractions; -namespace E2ETests +namespace E2ETests.SmokeTestsUsingStore { - public class SmokeTestsUsingStoreHelper : LoggedTest + public class TestHelper : LoggedTest { - public SmokeTestsUsingStoreHelper(ITestOutputHelper output) : base(output) + public TestHelper(ITestOutputHelper output) : base(output) { } - public async Task SmokeTestSuite(ServerType serverType, bool isStoreInDefaultLocation, string storeDirectory) + public async Task SmokeTestSuite(ServerType serverType, string storeDirectory) { var targetFramework = "netcoreapp2.0"; var testName = $"SmokeTestsUsingStore_{serverType}"; using (StartLog(out var loggerFactory, testName)) { - var logger = loggerFactory.CreateLogger(nameof(SmokeTestsUsingStoreHelper)); + var logger = loggerFactory.CreateLogger(nameof(TestHelper)); var musicStoreDbName = DbUtils.GetUniqueName(); var deploymentParameters = new DeploymentParameters( @@ -45,11 +46,8 @@ namespace E2ETests MusicStoreConfig.ConnectionStringKey, DbUtils.CreateConnectionString(musicStoreDbName))); - if (!isStoreInDefaultLocation) - { - deploymentParameters.EnvironmentVariables.Add( - new KeyValuePair("DOTNET_SHARED_STORE", storeDirectory)); - } + deploymentParameters.EnvironmentVariables.Add( + new KeyValuePair("DOTNET_SHARED_STORE", storeDirectory)); using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) { diff --git a/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs new file mode 100644 index 0000000000..7caf19f597 --- /dev/null +++ b/test/MusicStore.E2ETests/SmokeTestsUsingStore/Tests.cs @@ -0,0 +1,46 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Testing.xunit; +using Xunit; +using Xunit.Abstractions; + +namespace E2ETests.SmokeTestsUsingStore +{ + public class SmokeTests : IClassFixture + { + private readonly StoreSetupFixture _testFixture; + private readonly ITestOutputHelper _output; + + public SmokeTests( + StoreSetupFixture testFixure, + ITestOutputHelper output) + { + _testFixture = testFixure; + _output = output; + } + + [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] + [ConditionalFact] + [Trait("smoketests", "usestore1")] + public async Task DefaultLocation_Kestrel() + { + var tests = new TestHelper(_output); + await tests.SmokeTestSuite( + ServerType.Kestrel, + _testFixture.StoreDirectory); + } + + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + [EnvironmentVariableSkipCondition(Store.MusicStoreAspNetCoreStoreFeed, null, SkipOnMatch = false)] + [ConditionalFact] + [Trait("smoketests", "usestore")] + public async Task DefaultLocation_WebListener() + { + var tests = new TestHelper(_output); + await tests.SmokeTestSuite( + ServerType.WebListener, + _testFixture.StoreDirectory); + } + } +} \ No newline at end of file