Skip to content

Commit 8ff4fb0

Browse files
committed
Add StringEquals sut and its driver and tests for it
1 parent 0f0cc88 commit 8ff4fb0

File tree

10 files changed

+378
-14
lines changed

10 files changed

+378
-14
lines changed

Dotnet.sln

+31-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EvoMaster.Instrumentation_S
4141
EndProject
4242
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EvoMaster.Client.Util.Tests", "client-dotnet\test\EvoMaster.Client.Util.Tests\EvoMaster.Client.Util.Tests.csproj", "{6C2CC8C2-CF24-442B-A77A-AC1A6C2EBDF3}"
4343
EndProject
44-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EvoMaster.Instrumentation.Examples", "client-dotnet\test\EvoMaster.Instrumentation.Examples\EvoMaster.Instrumentation.Examples.csproj", "{1054495C-0550-4C60-A44A-D873F99317DB}"
44+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EvoMaster.Instrumentation.Examples", "client-dotnet\test\EvoMaster.Instrumentation.Examples\EvoMaster.Instrumentation.Examples.csproj", "{1054495C-0550-4C60-A44A-D873F99317DB}"
45+
EndProject
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestApis.StringEquals", "e2e-tests\dotnet-rest\src\RestApis.StringEquals\RestApis.StringEquals.csproj", "{00F24DBE-E677-44EE-87DC-37138758FE99}"
47+
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestApis.Tests.StringEquals", "e2e-tests\dotnet-rest\test\RestApis.Tests.StringEquals\RestApis.Tests.StringEquals.csproj", "{DC9939DF-6C94-453D-A397-C6866BBA7543}"
4549
EndProject
4650
Global
4751
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -281,6 +285,30 @@ Global
281285
{1054495C-0550-4C60-A44A-D873F99317DB}.Release|x64.Build.0 = Release|Any CPU
282286
{1054495C-0550-4C60-A44A-D873F99317DB}.Release|x86.ActiveCfg = Release|Any CPU
283287
{1054495C-0550-4C60-A44A-D873F99317DB}.Release|x86.Build.0 = Release|Any CPU
288+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
289+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|Any CPU.Build.0 = Debug|Any CPU
290+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|x64.ActiveCfg = Debug|Any CPU
291+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|x64.Build.0 = Debug|Any CPU
292+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|x86.ActiveCfg = Debug|Any CPU
293+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Debug|x86.Build.0 = Debug|Any CPU
294+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|Any CPU.ActiveCfg = Release|Any CPU
295+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|Any CPU.Build.0 = Release|Any CPU
296+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|x64.ActiveCfg = Release|Any CPU
297+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|x64.Build.0 = Release|Any CPU
298+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|x86.ActiveCfg = Release|Any CPU
299+
{00F24DBE-E677-44EE-87DC-37138758FE99}.Release|x86.Build.0 = Release|Any CPU
300+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
301+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|Any CPU.Build.0 = Debug|Any CPU
302+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|x64.ActiveCfg = Debug|Any CPU
303+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|x64.Build.0 = Debug|Any CPU
304+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|x86.ActiveCfg = Debug|Any CPU
305+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Debug|x86.Build.0 = Debug|Any CPU
306+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|Any CPU.ActiveCfg = Release|Any CPU
307+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|Any CPU.Build.0 = Release|Any CPU
308+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|x64.ActiveCfg = Release|Any CPU
309+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|x64.Build.0 = Release|Any CPU
310+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|x86.ActiveCfg = Release|Any CPU
311+
{DC9939DF-6C94-453D-A397-C6866BBA7543}.Release|x86.Build.0 = Release|Any CPU
284312
EndGlobalSection
285313
GlobalSection(SolutionProperties) = preSolution
286314
HideSolutionNode = FALSE
@@ -294,6 +322,8 @@ Global
294322
{24AEA586-3C16-494E-8C4D-61FEC22D38DE} = {C7482DD5-AD81-49FE-9395-80C952893534}
295323
{7202DC0F-F4A8-4BAD-95A5-5E79081CDCE0} = {C7482DD5-AD81-49FE-9395-80C952893534}
296324
{255D26A1-4213-4206-891B-D9280350BC42} = {C7482DD5-AD81-49FE-9395-80C952893534}
325+
{00F24DBE-E677-44EE-87DC-37138758FE99} = {C7482DD5-AD81-49FE-9395-80C952893534}
326+
{DC9939DF-6C94-453D-A397-C6866BBA7543} = {C7482DD5-AD81-49FE-9395-80C952893534}
297327
EndGlobalSection
298328
GlobalSection(ExtensibilityGlobals) = postSolution
299329
SolutionGuid = {FC853D6D-A64F-4069-9CDF-646677D77CC8}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace RestApis.StringEquals.Controllers {
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class EqualsController : ControllerBase {
8+
[HttpGet("getConstant/{value}")]
9+
public IActionResult GetConstant(string value) => Ok(value);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Concurrent;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using Microsoft.AspNetCore;
12+
13+
namespace RestApis.StringEquals
14+
{
15+
public class Program {
16+
private static ConcurrentDictionary<int, CancellationTokenSource> tokens =
17+
new ConcurrentDictionary<int, CancellationTokenSource>();
18+
19+
public static void Main(string[] args) {
20+
if (args.Length > 0) {
21+
var port = Convert.ToInt32(args[0]);
22+
23+
tokens.TryAdd(port, new CancellationTokenSource());
24+
25+
var host = CreateWebHostBuilder(args).Build();
26+
27+
host.RunAsync(tokens[port].Token).GetAwaiter().GetResult();
28+
}
29+
else {
30+
var host = CreateWebHostBuilder(args).Build();
31+
32+
host.RunAsync().GetAwaiter().GetResult();
33+
}
34+
}
35+
36+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
37+
var webHostBuilder = WebHost.CreateDefaultBuilder(args)
38+
.UseStartup<Startup>();
39+
40+
return args.Length > 0 ? webHostBuilder.UseUrls($"http://*:{args[0]}") : webHostBuilder;
41+
}
42+
43+
public static void Shutdown() {
44+
foreach (var pair in tokens) {
45+
pair.Value.Cancel();
46+
}
47+
48+
tokens.Clear();
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3"/>
9+
</ItemGroup>
10+
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
using Microsoft.OpenApi.Models;
11+
12+
namespace RestApis.StringEquals
13+
{
14+
public class Startup {
15+
public Startup(IConfiguration configuration) {
16+
Configuration = configuration;
17+
}
18+
19+
public IConfiguration Configuration { get; }
20+
21+
// This method gets called by the runtime. Use this method to add services to the container.
22+
public void ConfigureServices(IServiceCollection services) {
23+
services.AddControllers();
24+
25+
services.AddSwaggerGen(c => {
26+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "StringEquals API", Version = "v1" });
27+
});
28+
}
29+
30+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
32+
if (env.IsDevelopment()) {
33+
app.UseDeveloperExceptionPage();
34+
}
35+
36+
//app.UseHttpsRedirection();
37+
38+
app.UseRouting();
39+
40+
app.UseAuthorization();
41+
42+
app.UseSwagger();
43+
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "StringEquals API"); });
44+
45+
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

e2e-tests/dotnet-rest/test/RestApis.Tests.HelloWorld/RestApis.Tests.HelloWorld.csproj

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212

1313
<ItemGroup>
1414

15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
16-
<PackageReference Include="xunit" Version="2.4.0" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
18-
<PackageReference Include="coverlet.collector" Version="1.0.1" />
19-
<!-- <PackageReference Include="EvoMaster.Instrumentation" Version="1.1.1-SNAPSHOT"/>-->
20-
<!-- <PackageReference Include="EvoMaster.Controller" Version="1.1.1-SNAPSHOT"/>-->
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0"/>
16+
<PackageReference Include="xunit" Version="2.4.0"/>
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"/>
18+
<PackageReference Include="coverlet.collector" Version="1.0.1"/>
19+
<!-- <PackageReference Include="EvoMaster.Instrumentation" Version="1.1.1-SNAPSHOT"/>-->
20+
<!-- <PackageReference Include="EvoMaster.Controller" Version="1.1.1-SNAPSHOT"/>-->
2121
</ItemGroup>
2222

2323
<Target Name="PostClean" AfterTargets="Clean">
24-
<RemoveDir Directories="generated" />
25-
<RemoveDir Directories="bin-temp" />
24+
<RemoveDir Directories="generated"/>
25+
<RemoveDir Directories="bin-temp"/>
2626
</Target>
27-
27+
2828
<ItemGroup>
29-
<ProjectReference Include="../../src/RestApis.HelloWorld/RestApis.HelloWorld.csproj" />
30-
<ProjectReference Include="../../../../client-dotnet/src/EvoMaster.Controller/EvoMaster.Controller.csproj" />
29+
<ProjectReference Include="../../src/RestApis.HelloWorld/RestApis.HelloWorld.csproj"/>
30+
<ProjectReference Include="../../../../client-dotnet/src/EvoMaster.Controller/EvoMaster.Controller.csproj"/>
3131
</ItemGroup>
3232

3333
<!-- Read all the comments below to get an understanding of what's happening for putting up the scaffolding
@@ -57,7 +57,7 @@
5757

5858
<!-- Run the instrumentation and specify bin-temp as output directory -->
5959
<Exec Command="cd $(OutputPath)
60-
dotnet EvoMaster.Instrumentation.dll @(Sut) @(TempDirectory)"/>
60+
dotnet EvoMaster.Instrumentation.dll @(Sut) @(TempDirectory)"/>
6161

6262
</Target>
6363

@@ -70,5 +70,5 @@
7070
<Exec Command="cp @(SutPath) $(OutputPath)" Condition="$(OS.Contains('Unix'))"/>
7171
<Exec Command="copy @(SutPath) $(OutputPath)" Condition="$(OS.Contains('Windows'))"/>
7272
</Target>
73-
73+
7474
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using EvoMaster.Controller;
5+
using EvoMaster.Controller.Api;
6+
using EvoMaster.Controller.Problem;
7+
8+
namespace RestApis.Tests.StringEquals {
9+
public class EmbeddedEvoMasterController : EmbeddedSutController {
10+
private bool isSutRunning;
11+
private int sutPort;
12+
13+
public static void Main(string[] args) {
14+
15+
var embeddedEvoMasterController = new EmbeddedEvoMasterController();
16+
17+
if (args.Length > 0) {
18+
var controllerPort = int.Parse(args[0]);
19+
embeddedEvoMasterController.SetControllerPort(controllerPort);
20+
}
21+
22+
var instrumentedSutStarter = new InstrumentedSutStarter(embeddedEvoMasterController);
23+
24+
System.Console.WriteLine("Driver is starting...\n");
25+
26+
instrumentedSutStarter.Start();
27+
}
28+
29+
public override string GetDatabaseDriverName() => null;
30+
31+
public override List<AuthenticationDto> GetInfoForAuthentication() => null;
32+
33+
public override string GetPackagePrefixesToCover() => "RestApis.StringEquals";
34+
35+
public override OutputFormat GetPreferredOutputFormat() => OutputFormat.CSHARP_XUNIT;
36+
37+
//TODO: check again
38+
public override IProblemInfo GetProblemInfo() =>
39+
GetSutPort() != 0
40+
? new RestProblem("http://localhost:" + GetSutPort() + "/swagger/v1/swagger.json", null)
41+
: new RestProblem(null, null);
42+
43+
public override bool IsSutRunning() => isSutRunning;
44+
45+
public override void ResetStateOfSut() { }
46+
47+
public override string StartSut() {
48+
//TODO: check this again
49+
var ephemeralPort = GetEphemeralTcpPort();
50+
51+
var task = Task.Run(() => { RestApis.StringEquals.Program.Main(new string[] { ephemeralPort.ToString() }); });
52+
53+
WaitUntilSutIsRunning(ephemeralPort);
54+
55+
sutPort = ephemeralPort;
56+
57+
isSutRunning = true;
58+
59+
return $"http://localhost:{ephemeralPort}";
60+
}
61+
62+
public override void StopSut() {
63+
RestApis.StringEquals.Program.Shutdown();
64+
65+
isSutRunning = false;
66+
}
67+
68+
protected int GetSutPort() => sutPort;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
8+
<!-->TODO</-->
9+
<StartupObject>RestApis.Tests.StringEquals.EmbeddedEvoMasterController</StartupObject>
10+
</PropertyGroup>
11+
12+
13+
<ItemGroup>
14+
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
16+
<PackageReference Include="xunit" Version="2.4.0" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
18+
<PackageReference Include="coverlet.collector" Version="1.0.1" />
19+
<!-- <PackageReference Include="EvoMaster.Instrumentation" Version="1.1.1-SNAPSHOT"/>-->
20+
<!-- <PackageReference Include="EvoMaster.Controller" Version="1.1.1-SNAPSHOT"/>-->
21+
</ItemGroup>
22+
23+
<Target Name="PostClean" AfterTargets="Clean">
24+
<RemoveDir Directories="generated" />
25+
<RemoveDir Directories="bin-temp" />
26+
</Target>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="../../src/RestApis.StringEquals/RestApis.StringEquals.csproj" />
30+
<ProjectReference Include="../../../../client-dotnet/src/EvoMaster.Controller/EvoMaster.Controller.csproj" />
31+
</ItemGroup>
32+
33+
<!-- Read all the comments below to get an understanding of what's happening for putting up the scaffolding
34+
In Summary, what's happeing here is nothing but the instrumentation of the SUT and creating a new dll for it
35+
For more details, read the codes & comments below
36+
-->
37+
<ItemGroup>
38+
<!-- You may only need to modify values for these three items based on the project names -->
39+
<Sut Include="RestApis.StringEquals.dll"/>
40+
<!--Do not change the \ to / as it may lead to error on Windows, just change the substring after the \-->
41+
<SutPath Include="$(ProjectDir)bin-temp\RestApis.StringEquals.dll" />
42+
<CurrentRuntimeConfig Include="$(OutputPath)RestApis.Tests.StringEquals.runtimeconfig.json" />
43+
44+
<!-- Don't need to touch these two lines -->
45+
<TempDirectory Include="$(ProjectDir)bin-temp" />
46+
<InstrumentationRuntimeConfig Include="$(OutputPath)EvoMaster.Instrumentation.runtimeconfig.json" />
47+
</ItemGroup>
48+
49+
<Target Name="Instrument" AfterTargets="Build">
50+
51+
<!-- Remove temp folder in case it exists to make sure everything gets updated -->
52+
<RemoveDir Directories="@(TempDirectory)" />
53+
<MakeDir Directories="@(TempDirectory)" />
54+
55+
<!-- create a runtimeconfig.json because it is needed for EvoMaster.Instrumentation.dll to be runnable -->
56+
<Copy SourceFiles="@(CurrentRuntimeConfig)" DestinationFiles="@(InstrumentationRuntimeConfig)" />
57+
58+
<!-- Run the instrumentation and specify bin-temp as output directory -->
59+
<Exec Command="cd $(OutputPath)
60+
dotnet EvoMaster.Instrumentation.dll @(Sut) @(TempDirectory)" />
61+
62+
</Target>
63+
64+
65+
<!--This section is for enabling the test methods pass. The actual instrumentation is done before
66+
The instrumented dll is copied into the bin folder and replaces the actual sut
67+
-->
68+
<Target Name="TestInstrumentation" AfterTargets="Build">
69+
70+
<Exec Command="cp @(SutPath) $(OutputPath)" Condition="$(OS.Contains('Unix'))" />
71+
<Exec Command="copy @(SutPath) $(OutputPath)" Condition="$(OS.Contains('Windows'))" />
72+
</Target>
73+
74+
</Project>

0 commit comments

Comments
 (0)