Skip to content

Commit

Permalink
Run tests with and without external test broker
Browse files Browse the repository at this point in the history
  • Loading branch information
xinchen10 committed May 16, 2024
1 parent 11ce031 commit da9139a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SETLOCAL EnableExtensions EnableDelayedExpansion
ECHO Build Amqp.Net Lite
ECHO.

SET BUILD_SCRIPT=1
SET return-code=0

SET build-sln=amqp.sln
Expand Down
56 changes: 56 additions & 0 deletions test/Common/TestSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ------------------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this
// file except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
// NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Test.Amqp
{
#if (NETFX || DOTNET) && !BUILD_SCRIPT
[TestClass]
public class TestSetup
{
static Listener.IContainer.TestAmqpBroker broker;

[AssemblyInitialize]
public static void Initialize(TestContext context)
{
string address = Environment.GetEnvironmentVariable(TestTarget.envVarName);
if (address == null)
{
if (Process.GetProcessesByName("TestAmqpBroker").Length == 0)
{
string[] addresses = new[]
{
"amqp://localhost:5672",
"amqps://localhost:5671",
#if NETFX
"ws://localhost:18080"
#endif
};
broker = new Listener.IContainer.TestAmqpBroker(addresses, "guest:guest", "localhost", null);
broker.Start();
}
}
}

[AssemblyCleanup()]
public static void AssemblyCleanup()
{
broker?.Stop();
}
}
#endif
}
6 changes: 6 additions & 0 deletions test/Test.Amqp.Net/Test.Amqp.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(BUILD_SCRIPT)' != '' ">
<DefineConstants>$(DefineConstants);BUILD_SCRIPT</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Transactions" />
Expand Down Expand Up @@ -91,6 +94,9 @@
<Compile Include="..\Common\TestListener.cs">
<Link>Common\TestListener.cs</Link>
</Compile>
<Compile Include="..\Common\TestSetup.cs">
<Link>Common\TestSetup.cs</Link>
</Compile>
<Compile Include="..\Common\TestTarget.cs">
<Link>Common\TestTarget.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions test/Test.Amqp/Test.Amqp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<OutputPath>../../bin/$(Configuration)/$(MSBuildProjectName)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(BUILD_SCRIPT)' != '' ">
<DefineConstants>$(DefineConstants);BUILD_SCRIPT</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="../Common/**/*.cs;../../src/Net/TypeExtensions.cs;../../Examples/Serialization/Serialization.Poco/PocoContractResolver.cs;../../Examples/Serialization/Serialization.Poco/Shape.cs" Exclude="../Common/Extensions.cs" />
Expand Down

0 comments on commit da9139a

Please sign in to comment.