-
Notifications
You must be signed in to change notification settings - Fork 2
/
RawPotatoTest.cs
114 lines (100 loc) · 3.33 KB
/
RawPotatoTest.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using HotPotato.Test.Api.Models;
using HotPotato.Core.Http;
using HotPotato.Core.Http.Default;
using HotPotato.OpenApi.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
namespace HotPotato.TestServ.Test
{
public class RawPotatoTest : IClassFixture<TestFixture<HotPotato.Test.Api.Startup>>, IDisposable
{
private HotPotatoClient client;
private List<Result> results;
private bool specTokenExists;
private readonly Order paperOrder = new Order()
{
Id = 5,
Price = 10.00,
Items = new List<Item>()
{
new Item()
{
ItemId = 1,
Name = "Paper",
Price = 10.00
}
}
};
public RawPotatoTest(TestFixture<HotPotato.Test.Api.Startup> fixture)
{
client = fixture.Client;
results = fixture.Results;
//Omit this line if you're using this as a template and don't need to use access tokens
specTokenExists = fixture.SpecTokenExists;
}
[SkippableTheory]
[InlineData("http://localhost:3232", "GET", 200)]
[InlineData("http://localhost:3232/order", "GET", 200)]
[InlineData("http://localhost:3232/order", "POST", 201, true)]
[InlineData("http://localhost:3232/order/3", "PUT", 204, true)]
[InlineData("http://localhost:3232/order/1/items/3", "DELETE", 204)]
[InlineData("http://localhost:3232/order/2", "OPTIONS", 200)]
[InlineData("http://localhost:3232/order/4", "GET", 200)]
public async Task HotPotato_Should_Process_RawPotato_HappyPaths(string path, string methodString, int expectedStatusCode, bool hasRequestBody = false)
{
//Omit this line if you're using this as a template and don't need to use access tokens
Skip.IfNot(specTokenExists, TestConstants.MissingSpecToken);
HttpMethod method = new HttpMethod(methodString);
Uri pathUri = new Uri(path);
using (HotPotatoRequest req = new HotPotatoRequest(method, pathUri))
{
if (hasRequestBody)
{
string paperOrderBody = JsonConvert.SerializeObject(paperOrder);
req.SetContent(paperOrderBody);
}
await client.SendAsync(req);
Result result = results.ElementAt(0);
Assert.True(result.State == State.Pass, result.ToString());
Assert.Equal(methodString, result.Method, ignoreCase: true);
Assert.Equal(pathUri.AbsolutePath, result.Path);
Assert.Equal(expectedStatusCode, result.StatusCode);
}
}
[SkippableTheory]
[InlineData("http://localhost:3232", "GET")]
[InlineData("http://localhost:3232/order", "GET")]
[InlineData("http://localhost:3232/expected_fail", "GET")]
[InlineData("http://localhost:3232/order/2", "OPTIONS")]
[InlineData("http://localhost:3232/order/4", "GET")]
public async Task One_Fail_Result_Should_Not_Fail_The_Whole_Set(string path, string methodString)
{
Skip.IfNot(specTokenExists, TestConstants.MissingSpecToken);
HttpMethod method = new HttpMethod(methodString);
Uri pathUri = new Uri(path);
using (HotPotatoRequest req = new HotPotatoRequest(method, pathUri))
{
await client.SendAsync(req);
Result result = results.ElementAt(0);
if (path.Contains("expected_fail"))
{
Assert.True(result.State == State.Fail, result.ToString());
}
else
{
Assert.True(result.State == State.Pass, result.ToString());
}
}
}
public void Dispose()
{
results.Clear();
GC.SuppressFinalize(this);
}
}
}