-
-
Save jdmonty/822eb28aa00d67a60b36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SomeFixture : IDisposable | |
{ | |
private DockerClient client; | |
public SomeFixture() | |
{ | |
Console.WriteLine("SomeFixture ctor: This should only be run once"); | |
//Using https://github.com/ahmetalpbalkan/Docker.DotNet | |
client = new DockerClientConfiguration(new Uri("tcp://10.0.1.43:2376")).CreateClient(); | |
Setup().Wait(); | |
} | |
public void Dispose() | |
{ | |
Console.WriteLine("SomeFixture: Disposing SomeFixture"); | |
StopContainer().Wait(); | |
} | |
private async Task Setup() | |
{ | |
var stream = await client.Images.CreateImageAsync(new CreateImageParameters() | |
{ | |
FromImage = "192.168.1.95:5000/mycontainer", | |
Tag = "latest", | |
}, null); | |
await client.Containers.StartContainerAsync("0a419b7732f5", null); | |
} | |
public async Task StopContainer() | |
{ | |
var stopped = await client.Containers.StopContainerAsync("0a419b7732f5", | |
new StopContainerParameters() | |
{ | |
Wait = TimeSpan.FromSeconds(30) | |
}, | |
CancellationToken.None); | |
} | |
} | |
public class Class1 : IUseFixture<SomeFixture> | |
{ | |
[Fact] | |
public async Task FirstTest() | |
{ | |
using (HttpClient client = new HttpClient()) | |
using (HttpResponseMessage response = await client.GetAsync("http://IP_OF_MY_SERVER_IN_DOCKER_CONTAINER/Foo")) | |
using (HttpContent content = response.Content) | |
{ | |
// ... Read the string. | |
string result = await content.ReadAsStringAsync(); | |
Assert.NotNull(result); | |
} | |
} | |
[Fact] | |
public async Task SecondTest() | |
{ | |
using (HttpClient client = new HttpClient()) | |
using (HttpResponseMessage response = await client.GetAsync("http://IP_OF_MY_SERVER_IN_DOCKER_CONTAINER/Bar")) | |
using (HttpContent content = response.Content) | |
{ | |
// ... Read the string. | |
string result = await content.ReadAsStringAsync(); | |
Assert.NotNull(result); | |
} | |
} | |
public void SetFixture(SomeFixture data) | |
{ | |
//IUseFixture method called before each test | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment