<commit_before># FakeHttpContext

[![#](https://img.shields.io/nuget/v/FakeHttpContext.svg)](https://www.nuget.org/packages/FakeHttpContext/)
[![Build status](https://ci.appveyor.com/api/projects/status/l2jnlqj0vtkbr6ob?svg=true)](https://ci.appveyor.com/project/vadimzozulya/fakehttpcontext)

This util allows to initialize `HttpContex.Current` with fake context.

## Install with NuGet
You can install the utility with [NuGet](https://www.nuget.org/packages/FakeHttpContext/)

## Examples

```csharp
[Fact]
public void Should_initialize_HttpContext_Current()
{
  // Arrange
  using (new FakeHttpContext())
  {
    // Assert
    HttpContext.Current.Should().NotBeNull();
  }
}

[Fact]
public void Should_fake_user_agent()
{
  // Arrange
  const string ExpectedUserAgentString = "user agent string";
  using (new FakeHttpContext {UserAgent = ExpectedUserAgentString})
  {
    // Assert
    HttpContext.Current.Request.UserAgent.Should().Be(ExpectedUserAgentString);
  }
}

[Fact]
public void Should_allow_to_use_map_path()
{
  // Arrange
  var expectedPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "myPath");

  // Act
  using (new FakeHttpContext())
  {
  // Assert
    HttpContext.Current.Server.MapPath("myPath").Should().Be(expectedPath);
  }
}

[Theory, AutoData]
public void Should_be_possible_to_fake_http_headers(string headerKey, string headerValue)
{
    // Act
    using (new FakeHttpContext { Request = { { headerKey, headerValue } } })
    {
        // Assert
        HttpContext.Current.Request.Headers[headerKey].Should().Be(headerValue);
    }
}
```

For more examples please see `FakeHttpContext.Tests` project.<commit_msg>Update README with link to AutoFixture<commit_after># FakeHttpContext

[![#](https://img.shields.io/nuget/v/FakeHttpContext.svg)](https://www.nuget.org/packages/FakeHttpContext/)
[![Build status](https://ci.appveyor.com/api/projects/status/l2jnlqj0vtkbr6ob?svg=true)](https://ci.appveyor.com/project/vadimzozulya/fakehttpcontext)

This util allows to initialize `HttpContex.Current` with fake context.

## Install with NuGet
You can install the utility with [NuGet](https://www.nuget.org/packages/FakeHttpContext/)

## Examples

```csharp
[Fact]
public void Should_initialize_HttpContext_Current()
{
  // Arrange
  using (new FakeHttpContext())
  {
    // Assert
    HttpContext.Current.Should().NotBeNull();
  }
}

[Fact]
public void Should_fake_user_agent()
{
  // Arrange
  const string ExpectedUserAgentString = "user agent string";
  using (new FakeHttpContext {UserAgent = ExpectedUserAgentString})
  {
    // Assert
    HttpContext.Current.Request.UserAgent.Should().Be(ExpectedUserAgentString);
  }
}

[Fact]
public void Should_allow_to_use_map_path()
{
  // Arrange
  var expectedPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "myPath");

  // Act
  using (new FakeHttpContext())
  {
  // Assert
    HttpContext.Current.Server.MapPath("myPath").Should().Be(expectedPath);
  }
}

[Theory, AutoData]
public void Should_be_possible_to_fake_http_headers(string headerKey, string headerValue)
{
    // Act
    using (new FakeHttpContext { Request = { { headerKey, headerValue } } })
    {
        // Assert
        HttpContext.Current.Request.Headers[headerKey].Should().Be(headerValue);
    }
}
```

For more examples please see `FakeHttpContext.Tests` project.  
Great tool [AutoFixture](https://github.com/AutoFixture/AutoFixture) is used in
the test and examples, you definitely should try it, if you haven't yet
:thumbsup:!
{'fraction_non_alphanumeric': 0.1315413211323992, 'fraction_numerical': 0.0017157563625965113, 'mean_word_length': 4.457098283931357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 11, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3032262', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1131, 'n_words': 210}