ielcoro
4/13/2013 - 2:07 PM

xUnit Post

xUnit Post

[Fact]
public void GetAllShouldReturnResults()
{
    
}
public class ApiClientFixture : IDisposable
{
    public ApiClientFixture(HttpServer server)
    {  
        var uri = new Uri(Properties.Settings.Default.ApiClientUri);
        this.Client = HttpClientFactory.Create(server);
    }

    public HttpClient Client { get; private set; }

    #region Disposable

    public bool Disposed { get; private set; }

    public void Dispose()
    {
        if (this.Disposed) return;

        //this.Client = null;
        this.Disposed = true;
    }

    #endregion
}
public class ApiTests : IDisposable
{
  private HttpClient client;
  private string apiEndpoint;
  
  //Initialize before every test execution
  public ApiTest(string apiEndpoint)
  {
    this.apiEndpoint = apiEndpoint;
    this.client = new HttpClient();
  }
  
  [Fact]
  public void GetAllShouldReturnResults()
  {
    var response = this.client.GetStringAsync(this.apiEndpoint).Result;
    var data = JObject.Parse<DataViewModel>(response);
  
    Assert.True(data.Count() > 0);    
  }
  
  //Clean after every test execution
  public void Dispose()
  {
    if (this.client != null)
      this.client = null;
  }
}
public class ApiTestBase 
    : IUseFixture<ApiClientFixture>
{
    public HttpClient Client { get; private set; }

    //Runs before every test
    public void SetFixture(ApiClientFixture data)
    {
        this.Client = data.Client
    }
}