├── NetCore.2.2
├── Mock
│ ├── Class1.cs
│ ├── Mock.csproj
│ └── __admin
│ │ └── mappings
│ │ └── example.json
├── NUnit.Example
│ ├── NUnit.Example.csproj
│ ├── ExampleWithFile.cs
│ └── ExampleWithStub.cs
├── XUnit.Example
│ ├── XUnit.Example.csproj
│ ├── ExampleWithFile.cs
│ └── ExampleWithStub.cs
├── MSTest.Example
│ ├── MSTest.Example.csproj
│ ├── ExampleWithFile.cs
│ └── ExampleWithStub.cs
└── csharp-wiremock.sln
├── .github
└── dependabot.yml
├── Net.4.7
├── Mock
│ ├── __admin
│ │ └── mappings
│ │ │ └── example.json
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Mock.csproj
├── MSTest.Example
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ExampleWithFile.cs
│ ├── ExampleWithStub.cs
│ └── MSTest.Example.csproj
└── csharp-wiremock.sln
├── readme.md
└── .gitignore
/NetCore.2.2/Mock/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Mock
4 | {
5 | public class Class1
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/NetCore.2.2/Mock/Mock.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 |
6 |
7 |
8 |
9 | PreserveNewest
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "nuget" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "weekly"
12 |
--------------------------------------------------------------------------------
/Net.4.7/Mock/__admin/mappings/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "Request": {
3 | "Path": {
4 | "Matchers": [
5 | {
6 | "Name": "WildcardMatcher",
7 | "Pattern": "/api/products"
8 | }
9 | ]
10 | },
11 | "Methods": [ "get" ]
12 | },
13 | "Response": {
14 | "Status": 200,
15 | "BodyAsJson": [
16 | {
17 | "id": 1,
18 | "description": "Book A"
19 | },
20 | {
21 | "id": 2,
22 | "description": "Book B"
23 | }
24 | ],
25 | "Headers": { "Content-Type": "application/json" }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/NetCore.2.2/Mock/__admin/mappings/example.json:
--------------------------------------------------------------------------------
1 | {
2 | "Request": {
3 | "Path": {
4 | "Matchers": [
5 | {
6 | "Name": "WildcardMatcher",
7 | "Pattern": "/api/products"
8 | }
9 | ]
10 | },
11 | "Methods": [ "get" ]
12 | },
13 | "Response": {
14 | "Status": 200,
15 | "BodyAsJson": [
16 | {
17 | "id": 1,
18 | "description": "Book A"
19 | },
20 | {
21 | "id": 2,
22 | "description": "Book B"
23 | }
24 | ],
25 | "Headers": { "Content-Type": "application/json" }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/NetCore.2.2/NUnit.Example/NUnit.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Net.4.7/MSTest.Example/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("MSTest.Example")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("")]
9 | [assembly: AssemblyProduct("MSTest.Example")]
10 | [assembly: AssemblyCopyright("Copyright © 2019")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("0b8e6971-88c2-40a8-acd1-c2d3ff5e3d98")]
17 |
18 | // [assembly: AssemblyVersion("1.0.*")]
19 | [assembly: AssemblyVersion("1.0.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0.0")]
21 |
--------------------------------------------------------------------------------
/NetCore.2.2/XUnit.Example/XUnit.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # WireMock.Net examples
2 |
3 | WireMock.Net is a flexible library for stubbing and mocking web HTTP responses using request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
4 |
5 | Some examples of using the WireMock with .Net technologies.
6 |
7 | | Version | Framework | Result |
8 | | ------------- | --------- | ------------------ |
9 | | framework 4.7 | MSTest | :heavy_check_mark: |
10 | | netcore 2.2 | MSTest | :heavy_check_mark: |
11 | | netcore 2.2 | NUnit | :heavy_check_mark: |
12 | | netcore 2.2 | xUnit | :heavy_check_mark: |
13 |
14 | For more details, access the project [repository](https://github.com/WireMock-Net/WireMock.Net).
15 |
--------------------------------------------------------------------------------
/NetCore.2.2/MSTest.Example/MSTest.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Net.4.7/Mock/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Mock")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Mock")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6e8a41fe-57c0-461a-984a-7f0bd35fa486")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/NetCore.2.2/NUnit.Example/ExampleWithFile.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using NUnit.Framework;
3 | using RestSharp;
4 | using System;
5 | using WireMock.Server;
6 | using WireMock.Settings;
7 |
8 | namespace NUnit.Example
9 | {
10 | public class ExampleWithFile
11 | {
12 |
13 | private static FluentMockServer stub;
14 | private static string baseUrl;
15 |
16 | [OneTimeSetUp]
17 | public static void PrepareClass()
18 | {
19 | var port = new Random().Next(5000, 6000);
20 | baseUrl = "http://localhost:" + port;
21 |
22 | stub = FluentMockServer.Start(new FluentMockServerSettings
23 | {
24 | Urls = new[] { "http://+:" + port },
25 | ReadStaticMappings = true
26 | }); ;
27 | }
28 |
29 | [OneTimeTearDown]
30 | public static void CleanClass()
31 | {
32 | stub.Stop();
33 | }
34 |
35 |
36 | [Test]
37 | public void Test()
38 | {
39 | var bodyContent = new[] {
40 | new {id = 1, description = "Book A" },
41 | new {id = 2, description = "Book B" }
42 | };
43 |
44 | var client = new RestClient(baseUrl);
45 | var request = new RestRequest("/api/products");
46 |
47 | var response = client.Execute(request);
48 | Assert.AreEqual(200, (int)response.StatusCode);
49 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
50 | }
51 |
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Net.4.7/csharp-wiremock.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29326.143
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.Example", "MSTest.Example\MSTest.Example.csproj", "{0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mock", "Mock\Mock.csproj", "{6E8A41FE-57C0-461A-984A-7F0BD35FA486}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {6E8A41FE-57C0-461A-984A-7F0BD35FA486}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {6E8A41FE-57C0-461A-984A-7F0BD35FA486}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {6E8A41FE-57C0-461A-984A-7F0BD35FA486}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {6E8A41FE-57C0-461A-984A-7F0BD35FA486}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {C891C770-59DA-49E0-B365-34A895EEB0F3}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/NetCore.2.2/XUnit.Example/ExampleWithFile.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using RestSharp;
3 | using System;
4 | using WireMock.Server;
5 | using WireMock.Settings;
6 | using Xunit;
7 |
8 | namespace XUnit.Example
9 | {
10 | public class ExampleWithFile : IDisposable
11 | {
12 | private readonly FluentMockServer stub;
13 | private readonly string baseUrl;
14 | public ExampleWithFile()
15 | {
16 | var port = new Random().Next(5000, 6000);
17 | baseUrl = "http://localhost:" + port;
18 |
19 | stub = FluentMockServer.Start(new FluentMockServerSettings
20 | {
21 | Urls = new[] { "http://+:" + port },
22 | ReadStaticMappings = true
23 | }); ;
24 | }
25 |
26 | public void Dispose() => Dispose(true);
27 |
28 | protected virtual void Dispose(bool disposing)
29 | {
30 | if (disposing)
31 | {
32 | stub.Stop();
33 | stub.Dispose();
34 | }
35 | }
36 |
37 |
38 | [Fact]
39 | public void Test()
40 | {
41 | var bodyContent = new[] {
42 | new {id = 1, description = "Book A" },
43 | new {id = 2, description = "Book B" }
44 | };
45 |
46 | var client = new RestClient(baseUrl);
47 | var request = new RestRequest("/api/products");
48 |
49 | var response = client.Execute(request);
50 | Assert.Equal(200, (int)response.StatusCode);
51 | Assert.Equal(JsonConvert.SerializeObject(bodyContent), response.Content);
52 | }
53 |
54 |
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Net.4.7/MSTest.Example/ExampleWithFile.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Newtonsoft.Json;
3 | using RestSharp;
4 | using System;
5 | using WireMock.Server;
6 | using WireMock.Settings;
7 |
8 | namespace MSTest.Example
9 | {
10 | [TestClass]
11 | public class ExampleWithFile
12 | {
13 |
14 | private static FluentMockServer stub;
15 | private static string baseUrl;
16 |
17 | [ClassInitialize]
18 | public static void PrepareClass(TestContext context)
19 | {
20 | if (context is null) { throw new ArgumentNullException(nameof(context)); }
21 |
22 | var port = new Random().Next(5000, 6000);
23 | baseUrl = "http://localhost:" + port;
24 |
25 | stub = FluentMockServer.Start(new FluentMockServerSettings
26 | {
27 | Urls = new[] { "http://+:" + port },
28 | ReadStaticMappings = true
29 | }); ;
30 | }
31 |
32 | [ClassCleanup]
33 | public static void CleanClass()
34 | {
35 | stub.Stop();
36 | }
37 |
38 |
39 | [TestMethod]
40 | public void Test()
41 | {
42 | var bodyContent = new[] {
43 | new {id = 1, description = "Book A" },
44 | new {id = 2, description = "Book B" }
45 | };
46 |
47 | var client = new RestClient(baseUrl);
48 | var request = new RestRequest("/api/products");
49 |
50 | var response = client.Execute(request);
51 | Assert.AreEqual(200, (int)response.StatusCode);
52 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
53 | }
54 |
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NetCore.2.2/MSTest.Example/ExampleWithFile.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Newtonsoft.Json;
3 | using RestSharp;
4 | using System;
5 | using WireMock.Server;
6 | using WireMock.Settings;
7 |
8 | namespace MSTest.Example
9 | {
10 | [TestClass]
11 | public class ExampleWithFile
12 | {
13 |
14 | private static FluentMockServer stub;
15 | private static string baseUrl;
16 |
17 | [ClassInitialize]
18 | public static void PrepareClass(TestContext context)
19 | {
20 | if (context is null) { throw new ArgumentNullException(nameof(context)); }
21 |
22 | var port = new Random().Next(5000, 6000);
23 | baseUrl = "http://localhost:" + port;
24 |
25 | stub = FluentMockServer.Start(new FluentMockServerSettings
26 | {
27 | Urls = new[] { "http://+:" + port },
28 | ReadStaticMappings = true
29 | }); ;
30 | }
31 |
32 | [ClassCleanup]
33 | public static void CleanClass()
34 | {
35 | stub.Stop();
36 | }
37 |
38 |
39 | [TestMethod]
40 | public void Test()
41 | {
42 | var bodyContent = new[] {
43 | new {id = 1, description = "Book A" },
44 | new {id = 2, description = "Book B" }
45 | };
46 |
47 | var client = new RestClient(baseUrl);
48 | var request = new RestRequest("/api/products");
49 |
50 | var response = client.Execute(request);
51 | Assert.AreEqual(200, (int)response.StatusCode);
52 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
53 | }
54 |
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NetCore.2.2/NUnit.Example/ExampleWithStub.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using NUnit.Framework;
3 | using RestSharp;
4 | using System;
5 | using WireMock.RequestBuilders;
6 | using WireMock.ResponseBuilders;
7 | using WireMock.Server;
8 | using WireMock.Settings;
9 |
10 | namespace NUnit.Example
11 | {
12 | public class ExampleWithStub
13 | {
14 | private static FluentMockServer stub;
15 | private static string baseUrl;
16 |
17 | [OneTimeSetUp]
18 | public static void PrepareClass()
19 | {
20 | var port = new Random().Next(5000, 6000);
21 | baseUrl = "http://localhost:" + port;
22 |
23 | stub = FluentMockServer.Start(new FluentMockServerSettings
24 | {
25 | Urls = new[] { "http://+:" + port },
26 | ReadStaticMappings = true
27 | });
28 | }
29 |
30 | [OneTimeTearDown]
31 | public static void TearDown()
32 | {
33 | stub.Stop();
34 | }
35 |
36 | [Test]
37 | public void Test()
38 | {
39 | var bodyContent = new[] {
40 | new {id = 1, description = "Book A" },
41 | new {id = 2, description = "Book B" }
42 | };
43 |
44 | stub.Given(
45 | Request
46 | .Create()
47 | .WithPath("/api/products"))
48 | .RespondWith(
49 | Response.Create()
50 | .WithStatusCode(200)
51 | .WithHeader("Content-Type", "aplication/json")
52 | .WithBodyAsJson(bodyContent));
53 |
54 | var client = new RestClient(baseUrl);
55 | var request = new RestRequest("/api/products");
56 |
57 | var response = client.Execute(request);
58 | Assert.AreEqual(200, (int)response.StatusCode);
59 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
60 | }
61 |
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/NetCore.2.2/XUnit.Example/ExampleWithStub.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using RestSharp;
3 | using System;
4 | using WireMock.RequestBuilders;
5 | using WireMock.ResponseBuilders;
6 | using WireMock.Server;
7 | using WireMock.Settings;
8 | using Xunit;
9 |
10 | namespace XUnit.Example
11 | {
12 | public class ExampleWithStub : IDisposable
13 | {
14 | private readonly FluentMockServer stub;
15 | private readonly string baseUrl;
16 | public ExampleWithStub()
17 | {
18 | var port = new Random().Next(5000, 6000);
19 | baseUrl = "http://localhost:" + port;
20 |
21 | stub = FluentMockServer.Start(new FluentMockServerSettings
22 | {
23 | Urls = new[] { "http://+:" + port }
24 | });
25 | }
26 |
27 | public void Dispose() => Dispose(true);
28 |
29 | protected virtual void Dispose(bool disposing)
30 | {
31 | if (disposing)
32 | {
33 | stub.Stop();
34 | stub.Dispose();
35 | }
36 | }
37 |
38 | [Fact]
39 | public void Test()
40 | {
41 | var bodyContent = new[] {
42 | new {id = 1, description = "Book A" },
43 | new {id = 2, description = "Book B" }
44 | };
45 |
46 | stub.Given(
47 | Request
48 | .Create()
49 | .WithPath("/api/products"))
50 | .RespondWith(
51 | Response.Create()
52 | .WithStatusCode(200)
53 | .WithHeader("Content-Type", "aplication/json")
54 | .WithBodyAsJson(bodyContent));
55 |
56 | var client = new RestClient(baseUrl);
57 | var request = new RestRequest("/api/products");
58 |
59 | var response = client.Execute(request);
60 | Assert.Equal(200, (int)response.StatusCode);
61 | Assert.Equal(JsonConvert.SerializeObject(bodyContent), response.Content);
62 | }
63 |
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Net.4.7/MSTest.Example/ExampleWithStub.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Newtonsoft.Json;
3 | using RestSharp;
4 | using System;
5 | using WireMock.RequestBuilders;
6 | using WireMock.ResponseBuilders;
7 | using WireMock.Server;
8 | using WireMock.Settings;
9 |
10 | namespace MSTest.Example
11 | {
12 | [TestClass]
13 | public class ExampleWithStub
14 | {
15 | private static FluentMockServer stub;
16 | private static string baseUrl;
17 |
18 | [ClassInitialize]
19 | public static void PrepareClass(TestContext context)
20 | {
21 | if (context is null){throw new ArgumentNullException(nameof(context));}
22 |
23 | var port = new Random().Next(5000, 6000);
24 | baseUrl = "http://localhost:" + port;
25 |
26 | stub = FluentMockServer.Start(new FluentMockServerSettings
27 | {
28 | Urls = new[] { "http://+:" + port },
29 | ReadStaticMappings = true
30 | });
31 | }
32 |
33 | [ClassCleanup]
34 | public static void TearDown()
35 | {
36 | stub.Stop();
37 | }
38 |
39 | [TestMethod]
40 | public void Test()
41 | {
42 | var bodyContent = new[] {
43 | new {id = 1, description = "Book A" },
44 | new {id = 2, description = "Book B" }
45 | };
46 |
47 | stub.Given(
48 | Request
49 | .Create()
50 | .WithPath("/api/products"))
51 | .RespondWith(
52 | Response.Create()
53 | .WithStatusCode(200)
54 | .WithHeader("Content-Type", "aplication/json")
55 | .WithBodyAsJson(bodyContent));
56 |
57 | var client = new RestClient(baseUrl);
58 | var request = new RestRequest("/api/products");
59 |
60 | var response = client.Execute(request);
61 | Assert.AreEqual(200, (int)response.StatusCode);
62 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
63 | }
64 |
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/NetCore.2.2/MSTest.Example/ExampleWithStub.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Newtonsoft.Json;
3 | using RestSharp;
4 | using System;
5 | using WireMock.RequestBuilders;
6 | using WireMock.ResponseBuilders;
7 | using WireMock.Server;
8 | using WireMock.Settings;
9 |
10 | namespace MSTest.Example
11 | {
12 | [TestClass]
13 | public class ExampleWithStub
14 | {
15 | private static FluentMockServer stub;
16 | private static string baseUrl;
17 |
18 | [ClassInitialize]
19 | public static void PrepareClass(TestContext context)
20 | {
21 | if (context is null){throw new ArgumentNullException(nameof(context));}
22 |
23 | var port = new Random().Next(5000, 6000);
24 | baseUrl = "http://localhost:" + port;
25 |
26 | stub = FluentMockServer.Start(new FluentMockServerSettings
27 | {
28 | Urls = new[] { "http://+:" + port },
29 | ReadStaticMappings = true
30 | });
31 | }
32 |
33 | [ClassCleanup]
34 | public static void TearDown()
35 | {
36 | stub.Stop();
37 | }
38 |
39 | [TestMethod]
40 | public void Test()
41 | {
42 | var bodyContent = new[] {
43 | new {id = 1, description = "Book A" },
44 | new {id = 2, description = "Book B" }
45 | };
46 |
47 | stub.Given(
48 | Request
49 | .Create()
50 | .WithPath("/api/products"))
51 | .RespondWith(
52 | Response.Create()
53 | .WithStatusCode(200)
54 | .WithHeader("Content-Type", "aplication/json")
55 | .WithBodyAsJson(bodyContent));
56 |
57 | var client = new RestClient(baseUrl);
58 | var request = new RestRequest("/api/products");
59 |
60 | var response = client.Execute(request);
61 | Assert.AreEqual(200, (int)response.StatusCode);
62 | Assert.AreEqual(JsonConvert.SerializeObject(bodyContent), response.Content);
63 | }
64 |
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Net.4.7/Mock/Mock.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {6E8A41FE-57C0-461A-984A-7F0BD35FA486}
8 | Library
9 | Properties
10 | Mock
11 | Mock
12 | v4.7
13 | 512
14 | true
15 |
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | PreserveNewest
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/NetCore.2.2/csharp-wiremock.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29326.143
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnit.Example", "XUnit.Example\XUnit.Example.csproj", "{03FEA195-B029-4EB6-978D-22D1BF1AEC51}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Example", "MSTest.Example\MSTest.Example.csproj", "{C48F8291-C301-4946-83DE-BF4EC078F505}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock", "Mock\Mock.csproj", "{53BA2DA1-7502-4EF8-8FF7-8053C2F262DD}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnit.Example", "NUnit.Example\NUnit.Example.csproj", "{FA0911B5-D7F6-43DC-83A5-4077513E688A}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {03FEA195-B029-4EB6-978D-22D1BF1AEC51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {03FEA195-B029-4EB6-978D-22D1BF1AEC51}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {03FEA195-B029-4EB6-978D-22D1BF1AEC51}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {03FEA195-B029-4EB6-978D-22D1BF1AEC51}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {C48F8291-C301-4946-83DE-BF4EC078F505}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {C48F8291-C301-4946-83DE-BF4EC078F505}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {C48F8291-C301-4946-83DE-BF4EC078F505}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {C48F8291-C301-4946-83DE-BF4EC078F505}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {53BA2DA1-7502-4EF8-8FF7-8053C2F262DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {53BA2DA1-7502-4EF8-8FF7-8053C2F262DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {53BA2DA1-7502-4EF8-8FF7-8053C2F262DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {53BA2DA1-7502-4EF8-8FF7-8053C2F262DD}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {FA0911B5-D7F6-43DC-83A5-4077513E688A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {FA0911B5-D7F6-43DC-83A5-4077513E688A}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {FA0911B5-D7F6-43DC-83A5-4077513E688A}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {FA0911B5-D7F6-43DC-83A5-4077513E688A}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {2AF3C698-B584-47E0-B3D3-F2035DEA2603}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/Net.4.7/MSTest.Example/MSTest.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {0B8E6971-88C2-40A8-ACD1-C2D3FF5E3D98}
8 | Library
9 | Properties
10 | MSTest.Example
11 | MSTest.Example
12 | v4.7
13 | 512
14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 15.0
16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
18 | False
19 | UnitTest
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug\
29 | DEBUG;TRACE
30 | prompt
31 | 4
32 |
33 |
34 | pdbonly
35 | true
36 | bin\Release\
37 | TRACE
38 | prompt
39 | 4
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | 1.3.2
53 |
54 |
55 | 1.3.2
56 |
57 |
58 | 106.6.10
59 |
60 |
61 | 1.0.36
62 |
63 |
64 |
65 |
66 | {6e8a41fe-57c0-461a-984a-7f0bd35fa486}
67 | Mock
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/dotnetcore,visualstudio,visualstudiocode
3 | # Edit at https://www.gitignore.io/?templates=dotnetcore,visualstudio,visualstudiocode
4 |
5 | ### DotnetCore ###
6 | # .NET Core build folders
7 | /bin
8 | /obj
9 |
10 | # Common node modules locations
11 | /node_modules
12 | /wwwroot/node_modules
13 |
14 |
15 | ### VisualStudioCode ###
16 | .vscode/*
17 | !.vscode/settings.json
18 | !.vscode/tasks.json
19 | !.vscode/launch.json
20 | !.vscode/extensions.json
21 |
22 | ### VisualStudioCode Patch ###
23 | # Ignore all local history of files
24 | .history
25 |
26 | ### VisualStudio ###
27 | ## Ignore Visual Studio temporary files, build results, and
28 | ## files generated by popular Visual Studio add-ons.
29 | ##
30 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
31 |
32 | # User-specific files
33 | *.rsuser
34 | *.suo
35 | *.user
36 | *.userosscache
37 | *.sln.docstates
38 |
39 | # User-specific files (MonoDevelop/Xamarin Studio)
40 | *.userprefs
41 |
42 | # Mono auto generated files
43 | mono_crash.*
44 |
45 | # Build results
46 | [Dd]ebug/
47 | [Dd]ebugPublic/
48 | [Rr]elease/
49 | [Rr]eleases/
50 | x64/
51 | x86/
52 | [Aa][Rr][Mm]/
53 | [Aa][Rr][Mm]64/
54 | bld/
55 | [Bb]in/
56 | [Oo]bj/
57 | [Ll]og/
58 |
59 | # Visual Studio 2015/2017 cache/options directory
60 | .vs/
61 | # Uncomment if you have tasks that create the project's static files in wwwroot
62 | #wwwroot/
63 |
64 | # Visual Studio 2017 auto generated files
65 | Generated\ Files/
66 |
67 | # MSTest test Results
68 | [Tt]est[Rr]esult*/
69 | [Bb]uild[Ll]og.*
70 |
71 | # NUnit
72 | *.VisualState.xml
73 | TestResult.xml
74 | nunit-*.xml
75 |
76 | # Build Results of an ATL Project
77 | [Dd]ebugPS/
78 | [Rr]eleasePS/
79 | dlldata.c
80 |
81 | # Benchmark Results
82 | BenchmarkDotNet.Artifacts/
83 |
84 | # .NET Core
85 | project.lock.json
86 | project.fragment.lock.json
87 | artifacts/
88 |
89 | # StyleCop
90 | StyleCopReport.xml
91 |
92 | # Files built by Visual Studio
93 | *_i.c
94 | *_p.c
95 | *_h.h
96 | *.ilk
97 | *.meta
98 | *.obj
99 | *.iobj
100 | *.pch
101 | *.pdb
102 | *.ipdb
103 | *.pgc
104 | *.pgd
105 | *.rsp
106 | *.sbr
107 | *.tlb
108 | *.tli
109 | *.tlh
110 | *.tmp
111 | *.tmp_proj
112 | *_wpftmp.csproj
113 | *.log
114 | *.vspscc
115 | *.vssscc
116 | .builds
117 | *.pidb
118 | *.svclog
119 | *.scc
120 |
121 | # Chutzpah Test files
122 | _Chutzpah*
123 |
124 | # Visual C++ cache files
125 | ipch/
126 | *.aps
127 | *.ncb
128 | *.opendb
129 | *.opensdf
130 | *.sdf
131 | *.cachefile
132 | *.VC.db
133 | *.VC.VC.opendb
134 |
135 | # Visual Studio profiler
136 | *.psess
137 | *.vsp
138 | *.vspx
139 | *.sap
140 |
141 | # Visual Studio Trace Files
142 | *.e2e
143 |
144 | # TFS 2012 Local Workspace
145 | $tf/
146 |
147 | # Guidance Automation Toolkit
148 | *.gpState
149 |
150 | # ReSharper is a .NET coding add-in
151 | _ReSharper*/
152 | *.[Rr]e[Ss]harper
153 | *.DotSettings.user
154 |
155 | # JustCode is a .NET coding add-in
156 | .JustCode
157 |
158 | # TeamCity is a build add-in
159 | _TeamCity*
160 |
161 | # DotCover is a Code Coverage Tool
162 | *.dotCover
163 |
164 | # AxoCover is a Code Coverage Tool
165 | .axoCover/*
166 | !.axoCover/settings.json
167 |
168 | # Visual Studio code coverage results
169 | *.coverage
170 | *.coveragexml
171 |
172 | # NCrunch
173 | _NCrunch_*
174 | .*crunch*.local.xml
175 | nCrunchTemp_*
176 |
177 | # MightyMoose
178 | *.mm.*
179 | AutoTest.Net/
180 |
181 | # Web workbench (sass)
182 | .sass-cache/
183 |
184 | # Installshield output folder
185 | [Ee]xpress/
186 |
187 | # DocProject is a documentation generator add-in
188 | DocProject/buildhelp/
189 | DocProject/Help/*.HxT
190 | DocProject/Help/*.HxC
191 | DocProject/Help/*.hhc
192 | DocProject/Help/*.hhk
193 | DocProject/Help/*.hhp
194 | DocProject/Help/Html2
195 | DocProject/Help/html
196 |
197 | # Click-Once directory
198 | publish/
199 |
200 | # Publish Web Output
201 | *.[Pp]ublish.xml
202 | *.azurePubxml
203 | # Note: Comment the next line if you want to checkin your web deploy settings,
204 | # but database connection strings (with potential passwords) will be unencrypted
205 | *.pubxml
206 | *.publishproj
207 |
208 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
209 | # checkin your Azure Web App publish settings, but sensitive information contained
210 | # in these scripts will be unencrypted
211 | PublishScripts/
212 |
213 | # NuGet Packages
214 | *.nupkg
215 | # NuGet Symbol Packages
216 | *.snupkg
217 | # The packages folder can be ignored because of Package Restore
218 | **/[Pp]ackages/*
219 | # except build/, which is used as an MSBuild target.
220 | !**/[Pp]ackages/build/
221 | # Uncomment if necessary however generally it will be regenerated when needed
222 | #!**/[Pp]ackages/repositories.config
223 | # NuGet v3's project.json files produces more ignorable files
224 | *.nuget.props
225 | *.nuget.targets
226 |
227 | # Microsoft Azure Build Output
228 | csx/
229 | *.build.csdef
230 |
231 | # Microsoft Azure Emulator
232 | ecf/
233 | rcf/
234 |
235 | # Windows Store app package directories and files
236 | AppPackages/
237 | BundleArtifacts/
238 | Package.StoreAssociation.xml
239 | _pkginfo.txt
240 | *.appx
241 | *.appxbundle
242 | *.appxupload
243 |
244 | # Visual Studio cache files
245 | # files ending in .cache can be ignored
246 | *.[Cc]ache
247 | # but keep track of directories ending in .cache
248 | !?*.[Cc]ache/
249 |
250 | # Others
251 | ClientBin/
252 | ~$*
253 | *~
254 | *.dbmdl
255 | *.dbproj.schemaview
256 | *.jfm
257 | *.pfx
258 | *.publishsettings
259 | orleans.codegen.cs
260 |
261 | # Including strong name files can present a security risk
262 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
263 | #*.snk
264 |
265 | # Since there are multiple workflows, uncomment next line to ignore bower_components
266 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
267 | #bower_components/
268 |
269 | # RIA/Silverlight projects
270 | Generated_Code/
271 |
272 | # Backup & report files from converting an old project file
273 | # to a newer Visual Studio version. Backup files are not needed,
274 | # because we have git ;-)
275 | _UpgradeReport_Files/
276 | Backup*/
277 | UpgradeLog*.XML
278 | UpgradeLog*.htm
279 | ServiceFabricBackup/
280 | *.rptproj.bak
281 |
282 | # SQL Server files
283 | *.mdf
284 | *.ldf
285 | *.ndf
286 |
287 | # Business Intelligence projects
288 | *.rdl.data
289 | *.bim.layout
290 | *.bim_*.settings
291 | *.rptproj.rsuser
292 | *- [Bb]ackup.rdl
293 | *- [Bb]ackup ([0-9]).rdl
294 | *- [Bb]ackup ([0-9][0-9]).rdl
295 |
296 | # Microsoft Fakes
297 | FakesAssemblies/
298 |
299 | # GhostDoc plugin setting file
300 | *.GhostDoc.xml
301 |
302 | # Node.js Tools for Visual Studio
303 | .ntvs_analysis.dat
304 | node_modules/
305 |
306 | # Visual Studio 6 build log
307 | *.plg
308 |
309 | # Visual Studio 6 workspace options file
310 | *.opt
311 |
312 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
313 | *.vbw
314 |
315 | # Visual Studio LightSwitch build output
316 | **/*.HTMLClient/GeneratedArtifacts
317 | **/*.DesktopClient/GeneratedArtifacts
318 | **/*.DesktopClient/ModelManifest.xml
319 | **/*.Server/GeneratedArtifacts
320 | **/*.Server/ModelManifest.xml
321 | _Pvt_Extensions
322 |
323 | # Paket dependency manager
324 | .paket/paket.exe
325 | paket-files/
326 |
327 | # FAKE - F# Make
328 | .fake/
329 |
330 | # CodeRush personal settings
331 | .cr/personal
332 |
333 | # Python Tools for Visual Studio (PTVS)
334 | __pycache__/
335 | *.pyc
336 |
337 | # Cake - Uncomment if you are using it
338 | # tools/**
339 | # !tools/packages.config
340 |
341 | # Tabs Studio
342 | *.tss
343 |
344 | # Telerik's JustMock configuration file
345 | *.jmconfig
346 |
347 | # BizTalk build output
348 | *.btp.cs
349 | *.btm.cs
350 | *.odx.cs
351 | *.xsd.cs
352 |
353 | # OpenCover UI analysis results
354 | OpenCover/
355 |
356 | # Azure Stream Analytics local run output
357 | ASALocalRun/
358 |
359 | # MSBuild Binary and Structured Log
360 | *.binlog
361 |
362 | # NVidia Nsight GPU debugger configuration file
363 | *.nvuser
364 |
365 | # MFractors (Xamarin productivity tool) working folder
366 | .mfractor/
367 |
368 | # Local History for Visual Studio
369 | .localhistory/
370 |
371 | # BeatPulse healthcheck temp database
372 | healthchecksdb
373 |
374 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
375 | MigrationBackup/
376 |
377 | # End of https://www.gitignore.io/api/dotnetcore,visualstudio,visualstudiocode
--------------------------------------------------------------------------------