-
Notifications
You must be signed in to change notification settings - Fork 132
/
SmokeTests.cs
62 lines (50 loc) · 1.68 KB
/
SmokeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Net;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;
namespace TodoDapper.Tests;
public class SmokeTests
{
[Fact]
public async Task GetTodos_Returns_OK()
{
await using var application = new TodoApplication();
var client = application.CreateClient();
var response = await client.GetAsync("/todos");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Fact]
public async Task GetSwaggerDoc_Returns_OK()
{
await using var application = new TodoApplication();
var client = application.CreateClient();
var response = await client.GetAsync("/swagger/v1/swagger.json");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Fact]
public async Task GetSwaggerUI_Returns_OK()
{
await using var application = new TodoApplication();
var client = application.CreateClient();
var response = await client.GetAsync("/swagger/index.html");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
class TodoApplication : WebApplicationFactory<Program>
{
protected override IHost CreateHost(IHostBuilder builder)
{
// Add mock/test services to the builder here
builder.ConfigureServices(services =>
{
services.AddScoped(sp =>
{
// Replace SQL Lite with test DB
return new SqliteConnection("Data Source=testtodos.db");
});
});
return base.CreateHost(builder);
}
}
}