Updated runtime store tests and friends

This commit is contained in:
Kiran Challa 2017-06-29 10:13:27 -07:00
parent fc56105d83
commit f8ccf05715
6 changed files with 67 additions and 160 deletions

View File

@ -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))
{
}
}
}

View File

@ -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<DefaultLocationSetupFixture>
{
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<CustomLocationSetupFixture>
{
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);
}
}
}

View File

@ -7,7 +7,6 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Configuration; using NuGet.Configuration;
using NuGet.Packaging.Core; using NuGet.Packaging.Core;
@ -29,9 +28,9 @@ namespace E2ETests
_logger = loggerFactory.CreateLogger<Store>(); _logger = loggerFactory.CreateLogger<Store>();
} }
public string CreateStore(bool createInDefaultLocation) public string CreateStore()
{ {
var storeParentDir = GetStoreParentDirectory(createInDefaultLocation); var storeParentDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
InstallStore(storeParentDir); 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;
}
} }
} }

View File

@ -4,36 +4,31 @@ using Microsoft.Extensions.Logging.Testing;
namespace E2ETests namespace E2ETests
{ {
public class BaseStoreSetupFixture : IDisposable public class StoreSetupFixture : IDisposable
{ {
private readonly IDisposable _logToken; private readonly IDisposable _logToken;
private readonly ILogger<BaseStoreSetupFixture> _logger; private readonly ILogger<StoreSetupFixture> _logger;
private readonly Store _store; private readonly Store _store;
public BaseStoreSetupFixture(bool createInDefaultLocation, string loggerName) public StoreSetupFixture()
{ {
if (!Store.IsEnabled()) if (!Store.IsEnabled())
{ {
return; return;
} }
var testLog = AssemblyTestLog.ForAssembly(typeof(BaseStoreSetupFixture).Assembly); var loggerName = nameof(StoreSetupFixture);
var testLog = AssemblyTestLog.ForAssembly(typeof(StoreSetupFixture).Assembly);
ILoggerFactory loggerFactory; ILoggerFactory loggerFactory;
_logToken = testLog.StartTestLog(null, loggerName, out loggerFactory, testName: loggerName); _logToken = testLog.StartTestLog(null, loggerName, out loggerFactory, testName: loggerName);
_logger = loggerFactory.CreateLogger<BaseStoreSetupFixture>(); _logger = loggerFactory.CreateLogger<StoreSetupFixture>();
CreateStoreInDefaultLocation = createInDefaultLocation;
_logger.LogInformation(
"Setting up store in the location: {location}",
createInDefaultLocation ? "default" : "custom");
_store = new Store(loggerFactory); _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; } public string StoreDirectory { get; }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
@ -6,21 +7,21 @@ using Microsoft.Extensions.Logging.Testing;
using Xunit; using Xunit;
using Xunit.Abstractions; 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 targetFramework = "netcoreapp2.0";
var testName = $"SmokeTestsUsingStore_{serverType}"; var testName = $"SmokeTestsUsingStore_{serverType}";
using (StartLog(out var loggerFactory, testName)) using (StartLog(out var loggerFactory, testName))
{ {
var logger = loggerFactory.CreateLogger(nameof(SmokeTestsUsingStoreHelper)); var logger = loggerFactory.CreateLogger(nameof(TestHelper));
var musicStoreDbName = DbUtils.GetUniqueName(); var musicStoreDbName = DbUtils.GetUniqueName();
var deploymentParameters = new DeploymentParameters( var deploymentParameters = new DeploymentParameters(
@ -45,11 +46,8 @@ namespace E2ETests
MusicStoreConfig.ConnectionStringKey, MusicStoreConfig.ConnectionStringKey,
DbUtils.CreateConnectionString(musicStoreDbName))); DbUtils.CreateConnectionString(musicStoreDbName)));
if (!isStoreInDefaultLocation) deploymentParameters.EnvironmentVariables.Add(
{ new KeyValuePair<string, string>("DOTNET_SHARED_STORE", storeDirectory));
deploymentParameters.EnvironmentVariables.Add(
new KeyValuePair<string, string>("DOTNET_SHARED_STORE", storeDirectory));
}
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{ {

View File

@ -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<StoreSetupFixture>
{
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);
}
}
}