Skip to content

Instantly share code, notes, and snippets.

View josephwoodward's full-sized avatar

Joseph Woodward josephwoodward

View GitHub Profile
var fault = new SocketException(errorCode: 10013);
var policy = MonkeyPolicy.InjectFault(
fault,
injectionRate: 0.05,
enabled: () => isEnabled()
);
// Before
public class Person
{
private readonly string _firstName;
private readonly string _surname;
private readonly int _age;
public Person(string firstName, string surname, int age)
{
// Arrange
var options = new HttpClientInterceptorOptions {ThrowOnMissingRegistration = true};
new HttpRequestInterceptionBuilder()
.Requests()
.ForHttps()
.ForHost("bbc.co.uk")
.ForPath("/news")
.Responds()
.WithStatus(500)
.RegisterWith(options);
// Arrange
var options = new HttpClientInterceptorOptions {ThrowOnMissingRegistration = true};
new HttpRequestInterceptionBuilder()
.Requests()
.ForHttps()
.ForHost("bbc.co.uk")
.ForPath("/news")
.Responds()
.WithStatus(500)
.RegisterWith(options);
@josephwoodward
josephwoodward / hc3.cs
Last active May 22, 2020 00:23
hc3.cs
// Arrange
var options = new HttpClientInterceptorOptions {ThrowOnMissingRegistration = true};
new HttpRequestInterceptionBuilder()
.Requests()
.ForHttps()
.ForHost("bbc.co.uk")
.ForPath("/news")
.Responds()
.WithStatus(500)
.RegisterWith(options);
[ApiController]
[Route("api/[controller]")]
public class ReposController : Controller
{
private readonly IGitHub _github;
public ReposController(IGitHub github)
{
_github = github;
}
public class Fixture<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
public HttpClientInterceptorOptions InterceptorOptions { get; } =
new HttpClientInterceptorOptions {ThrowOnMissingRegistration = true};
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(s
=> s.AddSingleton<IHttpMessageHandlerBuilderFilter, InterceptionFilter>(
_ => new InterceptionFilter(InterceptorOptions)));
public class ControllerTests : IClassFixture<Fixture<Startup>>
{
private readonly Fixture<Startup> _fixture;
public ControllerTests(Fixture<Startup> fixture) => _fixture = fixture;
[Fact]
public async Task ReturnsOrganizationRepositories()
{
// Arrange
@josephwoodward
josephwoodward / skip1.cs
Created July 21, 2020 14:36
xunitskip1.cs
#if IS_LINUX
[Fact]
public void ShouldlyApi()
{
...
}
#endif
[Fact(Skip = "Doesn't work at the moment")]
public void ClassScenarioShouldFail()
{
...
}