Skip to content

Commit 8f877cd

Browse files
committed
update resource entity separation tests with relationships
1 parent 0146709 commit 8f877cd

File tree

10 files changed

+946
-110
lines changed

10 files changed

+946
-110
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using JsonApiDotNetCoreExample.Models.Resources;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace ResourceEntitySeparationExampleTests.Acceptance
8+
{
9+
[Collection("TestCollection")]
10+
public class AddTests
11+
{
12+
private readonly TestFixture _fixture;
13+
14+
public AddTests(TestFixture fixture)
15+
{
16+
_fixture = fixture;
17+
}
18+
19+
[Fact]
20+
public async Task Can_Create_Course()
21+
{
22+
// arrange
23+
var route = $"/api/v1/courses/";
24+
var course = _fixture.CourseFaker.Generate();
25+
var content = new
26+
{
27+
data = new
28+
{
29+
type = "courses",
30+
attributes = new Dictionary<string, object>()
31+
{
32+
{ "number", course.Number },
33+
{ "title", course.Title },
34+
{ "description", course.Description }
35+
}
36+
}
37+
};
38+
39+
// act
40+
var (response, data) = await _fixture.PostAsync<CourseResource>(route, content);
41+
42+
// assert
43+
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
44+
Assert.NotNull(data);
45+
Assert.Equal(course.Number, data.Number);
46+
Assert.Equal(course.Title, data.Title);
47+
Assert.Equal(course.Description, data.Description);
48+
}
49+
50+
[Fact]
51+
public async Task Can_Create_Department()
52+
{
53+
// arrange
54+
var route = $"/api/v1/departments/";
55+
var dept = _fixture.DepartmentFaker.Generate();
56+
var content = new
57+
{
58+
data = new
59+
{
60+
type = "departments",
61+
attributes = new Dictionary<string, string>()
62+
{
63+
{ "name", dept.Name }
64+
}
65+
}
66+
};
67+
68+
// act
69+
var (response, data) = await _fixture.PostAsync<DepartmentResource>(route, content);
70+
71+
// assert
72+
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
73+
Assert.NotNull(data);
74+
Assert.Equal(dept.Name, data.Name);
75+
}
76+
77+
[Fact]
78+
public async Task Can_Create_Student()
79+
{
80+
// arrange
81+
var route = $"/api/v1/students/";
82+
var student = _fixture.StudentFaker.Generate();
83+
var content = new
84+
{
85+
data = new
86+
{
87+
type = "students",
88+
attributes = new Dictionary<string, string>()
89+
{
90+
{ "firstname", student.FirstName },
91+
{ "lastname", student.LastName }
92+
}
93+
}
94+
};
95+
96+
// act
97+
var (response, data) = await _fixture.PostAsync<StudentResource>(route, content);
98+
99+
// assert
100+
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
101+
Assert.NotNull(data);
102+
Assert.Equal(student.FirstName, data.FirstName);
103+
Assert.Equal(student.LastName, data.LastName);
104+
}
105+
}
106+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Net;
2+
using System.Threading.Tasks;
3+
using Xunit;
4+
5+
namespace ResourceEntitySeparationExampleTests.Acceptance
6+
{
7+
[Collection("TestCollection")]
8+
public class DeleteTests
9+
{
10+
private readonly TestFixture _fixture;
11+
12+
public DeleteTests(TestFixture fixture)
13+
{
14+
_fixture = fixture;
15+
}
16+
17+
[Fact]
18+
public async Task Can_Delete_Course()
19+
{
20+
// arrange
21+
var course = _fixture.CourseFaker.Generate();
22+
_fixture.Context.Courses.Add(course);
23+
_fixture.Context.SaveChanges();
24+
25+
var route = $"/api/v1/courses/{course.Id}";
26+
27+
// act
28+
var response = await _fixture.DeleteAsync(route);
29+
30+
// assert
31+
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
32+
}
33+
34+
[Fact]
35+
public async Task Can_Delete_Department()
36+
{
37+
// arrange
38+
var dept = _fixture.DepartmentFaker.Generate();
39+
_fixture.Context.Departments.Add(dept);
40+
_fixture.Context.SaveChanges();
41+
42+
var route = $"/api/v1/departments/{dept.Id}";
43+
44+
// act
45+
var response = await _fixture.DeleteAsync(route);
46+
47+
// assert
48+
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
49+
}
50+
51+
[Fact]
52+
public async Task Can_Delete_Student()
53+
{
54+
// arrange
55+
var student = _fixture.StudentFaker.Generate();
56+
_fixture.Context.Students.Add(student);
57+
_fixture.Context.SaveChanges();
58+
59+
var route = $"/api/v1/students/{student.Id}";
60+
61+
// act
62+
var response = await _fixture.DeleteAsync(route);
63+
64+
// assert
65+
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
66+
}
67+
}
68+
}

test/ResourceEntitySeparationExampleTests/Acceptance/Extensibility/ResourceEntitySeparationExampleTests.cs

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)