-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest1.cs
More file actions
175 lines (166 loc) · 5.72 KB
/
Copy pathUnitTest1.cs
File metadata and controls
175 lines (166 loc) · 5.72 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using hwSDI.Models;
using hwSDI.Controllers;
using hwSDI.Validation;
using Moq;
using Moq.EntityFrameworkCore;
namespace Tests
{
public class MovieTests
{
private Mock<ItemContext> _contextMock;
private Mock<Valid> _validationMock;
[SetUp]
public void Setup()
{
_contextMock = new Mock<ItemContext>();
_validationMock = new Mock<Valid>();
}
[Test]
public async Task TestGetFilteredMoviesByReleaseYear()
{
var movies = new List<Movie>
{
new Movie
{
MovieID = 1,
Title = "title1",
ReleaseYear = 2021,
Genre = "genre1",
Producer = "producer1",
LengthMinutes = 157
},
new Movie
{
MovieID = 2,
Title = "title2",
ReleaseYear = 2023,
Genre = "genre2",
Producer = "producer2",
LengthMinutes = 139
},
new Movie
{
MovieID = 3,
Title = "title3",
ReleaseYear = 2022,
Genre = "genre3",
Producer = "producer3",
LengthMinutes = 157
},
new Movie
{
MovieID = 4,
Title = "title4",
ReleaseYear = 2015,
Genre = "genre4",
Producer = "producer4",
LengthMinutes = 125
},
new Movie
{
MovieID = 5,
Title = "title5",
ReleaseYear = 2020,
Genre = "genre5",
Producer = "producer5",
LengthMinutes = 160
}
};
_contextMock.Setup(x => x.Movies).ReturnsDbSet(movies);
var ctrl = new MovieController(_contextMock.Object, _validationMock.Object);
var res = await ctrl.GetFilteredMoviesByReleaseYear(2021);
NUnit.Framework.Assert.AreEqual(2, res.Count);
NUnit.Framework.Assert.AreEqual(2, res[0].MovieID);
NUnit.Framework.Assert.AreEqual(3, res[1].MovieID);
NUnit.Framework.Assert.AreEqual(2023, res[0].ReleaseYear);
NUnit.Framework.Assert.AreEqual(2022, res[1].ReleaseYear);
}
[Test]
public async Task TestGetMovieWithAvgScreeningSeat()
{
var movies = new List<Movie>
{
new Movie
{
MovieID = 1,
Title = "title1",
ReleaseYear = 2021,
Genre = "genre1",
Producer = "producer1",
LengthMinutes = 157
},
new Movie
{
MovieID = 2,
Title = "title2",
ReleaseYear = 2023,
Genre = "genre2",
Producer = "producer2",
LengthMinutes = 139
}
};
var screenings = new List<Screening>
{
new Screening
{
ScreeningID = 1,
Location = "location1",
Room = 1,
Seats = 60,
Date = "date1",
Time = "time1",
MovieID = 2
},
new Screening
{
ScreeningID = 2,
Location = "location2",
Room = 2,
Seats = 40,
Date = "date2",
Time = "time2",
MovieID = 2
},
new Screening
{
ScreeningID = 3,
Location = "location3",
Room = 3,
Seats = 80,
Date = "date3",
Time = "time3",
MovieID = 1
},
new Screening
{
ScreeningID = 4,
Location = "location4",
Room = 4,
Seats = 60,
Date = "date4",
Time = "time4",
MovieID = 1
},
new Screening
{
ScreeningID = 5,
Location = "location5",
Room = 5,
Seats = 40,
Date = "date5",
Time = "time5",
MovieID = 1
},
};
_contextMock.Setup(x => x.Movies).ReturnsDbSet(movies);
_contextMock.Setup(x => x.Screenings).ReturnsDbSet(screenings);
var ctrl = new MovieController(_contextMock.Object, _validationMock.Object);
var res = await ctrl.GetMovieWithAvgScreeningSeat();
NUnit.Framework.Assert.AreEqual(2, res.Count);
NUnit.Framework.Assert.AreEqual(2, res[0].MovieID);
NUnit.Framework.Assert.AreEqual(1, res[1].MovieID);
NUnit.Framework.Assert.AreEqual(50, res[0].AvgScreeningSeatNo);
NUnit.Framework.Assert.AreEqual(60, res[1].AvgScreeningSeatNo);
}
}
}