Created
April 13, 2013 14:07
-
-
Save ielcoro/5378536 to your computer and use it in GitHub Desktop.
xUnit Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void GetAllShouldReturnResults() | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApiTestBase | |
: IUseFixture<ApiClientFixture> | |
{ | |
public HttpClient Client { get; private set; } | |
//Runs before every test | |
public void SetFixture(ApiClientFixture data) | |
{ | |
this.Client = data.Client | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment