Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/WireMock.Net.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,51 @@ static async Task Main(string[] args)
)
);

mappingBuilder.Given(m => m
.WithRequest(req => req
.WithPath("/testRequestWithQueryParams")
.UsingGet()
.WithParams(p => p.WithParam("param1", pb => pb.WithExactMatcher("value1")))
).WithResponse(rsp => rsp
.WithHeaders(h => h.Add("Content-Type", "application/json"))
.WithStatusCode(200)
.WithBodyAsJson(new
{
status = "ok"
}, true)
)
);

mappingBuilder.Given(m => m
.WithRequest(req => req
.WithPath("/testRequestWithHeaders")
.UsingGet()
.WithHeaders(h => h.WithHeader("Accept", hb => hb.WithExactMatcher("application/json")))
).WithResponse(rsp => rsp
.WithHeaders(h => h.Add("Content-Type", "application/json"))
.WithStatusCode(200)
.WithBodyAsJson(new
{
status = "ok"
}, true)
)
);

mappingBuilder.Given(m => m
.WithRequest(req => req
.WithPath("/testRequestWithCookie")
.UsingGet()
.WithCookies(c => c.WithCookie("cookie1", cb => cb.WithExactMatcher("cookievalue1")))
).WithResponse(rsp => rsp
.WithHeaders(h => h.Add("Content-Type", "application/json"))
.WithStatusCode(200)
.WithBodyAsJson(new
{
status = "ok"
}, true)
)
);

var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © WireMock.Net

namespace WireMock.Admin.Mappings;

public partial class ArrayMatcherModelBuilder
{
public ArrayMatcherModelBuilder WithExactMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("ExactMatcher", pattern, rejectOnMatch, ignoreCase);
}

public ArrayMatcherModelBuilder WithWildcardMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("WildcardMatcher", pattern, rejectOnMatch, ignoreCase);
}

public ArrayMatcherModelBuilder WithRegexMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("RegexMatcher", pattern, rejectOnMatch, ignoreCase);
}

public ArrayMatcherModelBuilder WithNotNullOrEmptyMatcher(bool rejectOnMatch = false)
{
return Add(mb => mb
.WithName("NotNullOrEmptyMatcher")
.WithRejectOnMatch(rejectOnMatch)
);
}

private ArrayMatcherModelBuilder WithMatcher(string name, object pattern, bool rejectOnMatch, bool ignoreCase = false)
{
return Add(mb => mb
.WithName(name)
.WithPattern(pattern)
.WithRejectOnMatch(rejectOnMatch)
.WithIgnoreCase(ignoreCase)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © WireMock.Net

using System;
using System.Collections.Generic;
using System.Text;

namespace WireMock.Admin.Mappings;

public partial class IListCookieModelBuilder
{
public IListCookieModelBuilder WithCookie(string name, Action<IListMatcherModelBuilder> action, bool rejectOnMatch = false)
{
return Add(cookieBuilder => cookieBuilder
.WithName(name)
.WithRejectOnMatch(rejectOnMatch)
.WithMatchers(matchersBuilder => action(matchersBuilder))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © WireMock.Net

using System;
using System.Collections.Generic;
using System.Text;

namespace WireMock.Admin.Mappings;

public partial class IListHeaderModelBuilder
{
public IListHeaderModelBuilder WithHeader(string name, Action<IListMatcherModelBuilder> action, bool rejectOnMatch = false)
{
return Add(headerBuilder => headerBuilder
.WithName(name)
.WithRejectOnMatch(rejectOnMatch)
.WithMatchers(matchersBuilder => action(matchersBuilder))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © WireMock.Net

namespace WireMock.Admin.Mappings;

public partial class IListMatcherModelBuilder
{
public IListMatcherModelBuilder WithExactMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("ExactMatcher", pattern, rejectOnMatch, ignoreCase);
}

public IListMatcherModelBuilder WithWildcardMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("WildcardMatcher", pattern, rejectOnMatch, ignoreCase);
}

public IListMatcherModelBuilder WithRegexMatcher(object pattern, bool rejectOnMatch = false, bool ignoreCase = false)
{
return WithMatcher("RegexMatcher", pattern, rejectOnMatch, ignoreCase);
}

public IListMatcherModelBuilder WithNotNullOrEmptyMatcher(bool rejectOnMatch = false)
{
return Add(mb => mb
.WithName("NotNullOrEmptyMatcher")
.WithRejectOnMatch(rejectOnMatch)
);
}

private IListMatcherModelBuilder WithMatcher(string name, object pattern, bool rejectOnMatch, bool ignoreCase = false)
{
return Add(mb => mb
.WithName(name)
.WithPattern(pattern)
.WithRejectOnMatch(rejectOnMatch)
.WithIgnoreCase(ignoreCase)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © WireMock.Net

using System;

namespace WireMock.Admin.Mappings;

public partial class IListParamModelBuilder
{
public IListParamModelBuilder WithParam(string name, Action<ArrayMatcherModelBuilder> action, bool rejectOnMatch = false)
{
return Add(paramBuilder => paramBuilder
.WithName(name)
.WithRejectOnMatch(rejectOnMatch)
.WithMatchers(matchersBuilder => action(matchersBuilder))
);
}
}