4
4
using Microsoft . EntityFrameworkCore ;
5
5
using Xunit ;
6
6
using RazorPagesTestSample . Data ;
7
+ using System . ComponentModel . DataAnnotations ;
7
8
8
9
namespace RazorPagesTestSample . Tests . UnitTests
9
10
{
@@ -25,7 +26,7 @@ public async Task GetMessagesAsync_MessagesAreReturned()
25
26
// Assert
26
27
var actualMessages = Assert . IsAssignableFrom < List < Message > > ( result ) ;
27
28
Assert . Equal (
28
- expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
29
+ expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
29
30
actualMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ) ;
30
31
}
31
32
}
@@ -77,7 +78,7 @@ public async Task DeleteMessageAsync_MessageIsDeleted_WhenMessageIsFound()
77
78
await db . AddRangeAsync ( seedMessages ) ;
78
79
await db . SaveChangesAsync ( ) ;
79
80
var recId = 1 ;
80
- var expectedMessages =
81
+ var expectedMessages =
81
82
seedMessages . Where ( message => message . Id != recId ) . ToList ( ) ;
82
83
#endregion
83
84
@@ -90,7 +91,7 @@ public async Task DeleteMessageAsync_MessageIsDeleted_WhenMessageIsFound()
90
91
// Assert
91
92
var actualMessages = await db . Messages . AsNoTracking ( ) . ToListAsync ( ) ;
92
93
Assert . Equal (
93
- expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
94
+ expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
94
95
actualMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ) ;
95
96
#endregion
96
97
}
@@ -121,10 +122,36 @@ public async Task DeleteMessageAsync_NoMessageIsDeleted_WhenMessageIsNotFound()
121
122
// Assert
122
123
var actualMessages = await db . Messages . AsNoTracking ( ) . ToListAsync ( ) ;
123
124
Assert . Equal (
124
- expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
125
+ expectedMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ,
125
126
actualMessages . OrderBy ( m => m . Id ) . Select ( m => m . Text ) ) ;
126
127
}
127
128
}
128
129
#endregion
130
+
131
+
132
+ [ Theory ]
133
+ [ InlineData ( 150 , true ) ]
134
+ [ InlineData ( 199 , true ) ]
135
+ [ InlineData ( 200 , true ) ]
136
+ [ InlineData ( 201 , true ) ]
137
+ [ InlineData ( 249 , true ) ]
138
+ [ InlineData ( 250 , true ) ]
139
+ [ InlineData ( 251 , false ) ]
140
+ [ InlineData ( 300 , false ) ]
141
+ public async Task AddMessageAsync_TestMessageLength ( int messageLength , bool expectedValidMessage )
142
+ {
143
+ using ( var db = new AppDbContext ( Utilities . TestDbContextOptions ( ) ) )
144
+ {
145
+ // Arrange
146
+ var recId = 10 ;
147
+ var expectedMessage = new Message ( ) { Id = recId , Text = new string ( 'X' , messageLength ) } ;
148
+
149
+ // Act
150
+ var isValidMessage = Validator . TryValidateObject ( expectedMessage , new ValidationContext ( expectedMessage ) , null , validateAllProperties : true ) ;
151
+
152
+ // Assert
153
+ Assert . Equal ( expectedValidMessage , isValidMessage ) ;
154
+ }
155
+ }
129
156
}
130
157
}
0 commit comments