-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Run tests on .net core * disabled core build for unit tests until approval tests have core edition * Updated to latest sql transport. * Fixed connection string. * Fixed inspections. * Fixed dtc tests. * Fixed last 2 tests.
- Loading branch information
1 parent
dab4ff8
commit 3b234e1
Showing
15 changed files
with
235 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
src/MsSqlAcceptanceTests/ConfigureEndpointSqlServerTransport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
using System; | ||
using System.Data.SqlClient; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting.Support; | ||
using NServiceBus.Configuration.AdvancedExtensibility; | ||
using NServiceBus.Transport; | ||
|
||
public class ConfigureEndpointSqlServerTransport : IConfigureEndpointTestExecution | ||
{ | ||
public Task Configure(string endpointName, EndpointConfiguration configuration, RunSettings settings, PublisherMetadata publisherMetadata) | ||
{ | ||
queueBindings = configuration.GetSettings().Get<QueueBindings>(); | ||
var transportConfig = configuration.UseTransport<SqlServerTransport>(); | ||
connectionString = MsSqlConnectionBuilder.ConnectionString; | ||
transportConfig.ConnectionString(connectionString); | ||
|
||
transportConfig.Transactions(TransportTransactionMode.SendsAtomicWithReceive); | ||
|
||
var routingConfig = transportConfig.Routing(); | ||
|
||
foreach (var publisher in publisherMetadata.Publishers) | ||
{ | ||
foreach (var eventType in publisher.Events) | ||
{ | ||
routingConfig.RegisterPublisher(eventType, publisher.PublisherName); | ||
} | ||
} | ||
|
||
return Task.FromResult(0); | ||
} | ||
|
||
public Task Cleanup() | ||
{ | ||
using (var conn = new SqlConnection(connectionString)) | ||
{ | ||
conn.Open(); | ||
|
||
var queueAddresses = queueBindings.ReceivingAddresses.Select(QueueAddress.Parse).ToList(); | ||
foreach (var address in queueAddresses) | ||
{ | ||
TryDeleteTable(conn, address); | ||
TryDeleteTable(conn, new QueueAddress(address.Table + ".Delayed", address.Schema, address.Catalog)); | ||
} | ||
} | ||
return Task.FromResult(0); | ||
} | ||
|
||
static void TryDeleteTable(SqlConnection conn, QueueAddress address) | ||
{ | ||
try | ||
{ | ||
using (var comm = conn.CreateCommand()) | ||
{ | ||
comm.CommandText = $"IF OBJECT_ID('{address.QualifiedTableName}', 'U') IS NOT NULL DROP TABLE {address.QualifiedTableName}"; | ||
comm.ExecuteNonQuery(); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
if (!e.Message.Contains("it does not exist or you do not have permission")) | ||
{ | ||
throw; | ||
} | ||
} | ||
} | ||
|
||
string connectionString; | ||
QueueBindings queueBindings; | ||
|
||
class QueueAddress | ||
{ | ||
public QueueAddress(string table, string schemaName, string catalogName) | ||
{ | ||
Table = table; | ||
Catalog = SafeUnquote(catalogName); | ||
Schema = SafeUnquote(schemaName); | ||
} | ||
|
||
public string Catalog { get; } | ||
public string Table { get; } | ||
public string Schema { get; } | ||
|
||
public static QueueAddress Parse(string address) | ||
{ | ||
var firstAtIndex = address.IndexOf("@", StringComparison.Ordinal); | ||
|
||
if (firstAtIndex == -1) | ||
{ | ||
return new QueueAddress(address, null, null); | ||
} | ||
|
||
var tableName = address.Substring(0, firstAtIndex); | ||
address = firstAtIndex + 1 < address.Length ? address.Substring(firstAtIndex + 1) : string.Empty; | ||
|
||
address = ExtractNextPart(address, out var schemaName); | ||
|
||
string catalogName = null; | ||
|
||
if (address != string.Empty) | ||
{ | ||
ExtractNextPart(address, out catalogName); | ||
} | ||
return new QueueAddress(tableName, schemaName, catalogName); | ||
} | ||
|
||
public string QualifiedTableName => $"{Quote(Catalog)}.{Quote(Schema)}.{Quote(Table)}"; | ||
|
||
static string ExtractNextPart(string address, out string part) | ||
{ | ||
var noRightBrackets = 0; | ||
var index = 1; | ||
|
||
while (true) | ||
{ | ||
if (index >= address.Length) | ||
{ | ||
part = address; | ||
return string.Empty; | ||
} | ||
|
||
if (address[index] == '@' && (address[0] != '[' || noRightBrackets % 2 == 1)) | ||
{ | ||
part = address.Substring(0, index); | ||
return index + 1 < address.Length ? address.Substring(index + 1) : string.Empty; | ||
} | ||
|
||
if (address[index] == ']') | ||
{ | ||
noRightBrackets++; | ||
} | ||
|
||
index++; | ||
} | ||
} | ||
|
||
static string Quote(string name) | ||
{ | ||
if (name == null) | ||
{ | ||
return null; | ||
} | ||
return prefix + name.Replace(suffix, suffix + suffix) + suffix; | ||
} | ||
|
||
static string SafeUnquote(string name) | ||
{ | ||
var result = Unquote(name); | ||
return string.IsNullOrWhiteSpace(result) | ||
? null | ||
: result; | ||
} | ||
|
||
const string prefix = "["; | ||
const string suffix = "]"; | ||
static string Unquote(string quotedString) | ||
{ | ||
if (quotedString == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!quotedString.StartsWith(prefix) || !quotedString.EndsWith(suffix)) | ||
{ | ||
return quotedString; | ||
} | ||
|
||
return quotedString | ||
.Substring(prefix.Length, quotedString.Length - prefix.Length - suffix.Length).Replace(suffix + suffix, suffix); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net452</TargetFramework> | ||
<TargetFrameworks>net452;netcoreapp2.0</TargetFrameworks> | ||
<AssemblyName>MsSqlAcceptanceTests</AssemblyName> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>$(SolutionDir)Test.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'"> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Transactions" /> | ||
<Reference Include="System.Configuration" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.*" /> | ||
<PackageReference Include="NServiceBus" Version="7.0.0-*" /> | ||
<PackageReference Include="NServiceBus.SqlServer" Version="4.0.0-alpha0032" /> | ||
<PackageReference Include="NServiceBus.AcceptanceTesting" Version="7.0.0-*" /> | ||
<PackageReference Include="NServiceBus.Transport.Msmq" Version="1.0.0-*" /> | ||
<PackageReference Include="NUnit" Version="3.7.*" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Messaging" /> | ||
<Reference Include="System.Transactions" /> | ||
<Reference Include="System.Configuration" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" PrivateAssets="All" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0-alpha1" PrivateAssets="All" /> | ||
<ProjectReference Include="..\AcceptanceTestHelper\AcceptanceTestHelper.csproj" /> | ||
<ProjectReference Include="..\TestHelper\TestHelper.csproj" /> | ||
<ProjectReference Include="..\ScriptBuilder\ScriptBuilder.csproj" /> | ||
<ProjectReference Include="..\SqlPersistence\SqlPersistence.csproj" /> | ||
<Compile Include="$(SolutionDir)\AcceptanceTestsHolder\App_Packages\**\*.cs" /> | ||
<Compile Include="$(SolutionDir)\AcceptanceTestsHolder\App_Packages\**\*.cs" Exclude="$(SolutionDir)\AcceptanceTestsHolder\App_Packages\**\ConfigureEndpointMsmqTransport.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 0 additions & 114 deletions
114
src/MsSqlAcceptanceTests/When_creating_transaction_scope_in_the_pipeline.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.