-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTagsApiTest.cs
More file actions
111 lines (81 loc) · 3.52 KB
/
Copy pathTagsApiTest.cs
File metadata and controls
111 lines (81 loc) · 3.52 KB
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
using Nancy.Json;
using NUnit.Framework;
using System.IO;
using System.Net;
namespace StackOverflowTest
{
public class Tests
{
public class TagsApiTest
{
public class Tag
{
public int id { get; set; }
public string? name { get; set; }
public string? questionTags { get; set; }
}
private Tag? _tag;
[Test, Order(1)]
public void Get()
{
WebRequest request = WebRequest.Create("https://localhost:7001/api/tags");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
response.Close();
}
[Test, Order(2)]
public void Post()
{
WebRequest request = WebRequest.Create("https://localhost:7001/api/tags");
request.Method = "POST";
request.ContentType = "application/json";
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
requestWriter.Write("\"testTag\"");
requestWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
StreamReader responseReader = new StreamReader(response.GetResponseStream());
_tag = new JavaScriptSerializer().Deserialize<Tag>(responseReader.ReadToEnd());
Assert.AreEqual(_tag.name, "testTag");
responseReader.Close();
response.Close();
}
[Test, Order(3)]
public void GetById()
{
WebRequest request = WebRequest.Create("https://localhost:7001/api/tags/" + _tag.id);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
response.Close();
}
[Test, Order(4)]
public void Put()
{
WebRequest request = WebRequest.Create("https://localhost:7001/api/tags/" + _tag.id);
request.Method = "PUT";
request.ContentType = "application/json";
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
requestWriter.Write("\"testTagNew\"");
requestWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
StreamReader responseReader = new StreamReader(response.GetResponseStream());
_tag = new JavaScriptSerializer().Deserialize<Tag>(responseReader.ReadToEnd());
Assert.AreEqual(_tag.name, "testTagNew");
responseReader.Close();
response.Close();
}
[Test, Order(5)]
public void Delete()
{
WebRequest request = WebRequest.Create("https://localhost:7001/api/tags/" + _tag.id);
request.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
response.Close();
}
}
}
}