Skip to content

Commit d6768dc

Browse files
author
Rafferty Uy
committed
Update Message class, dependencies, and add tests, resolves #6.
- Increased max length of Message.Text property to 250 chars - Upgraded EF Core packages in RazorPagesTestSample.csproj to 8.0.8 - Added RazorPagesTestSample.Tests project to solution - Updated test project dependencies to latest versions - Added Message_LengthValidation test in DataAccessLayerTest.cs - Added launchSettings.json for both projects
1 parent fb8f712 commit d6768dc

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

src/Application/src/RazorPagesTestSample/Data/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Message
99

1010
[Required]
1111
[DataType(DataType.Text)]
12-
[StringLength(200, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")]
12+
[StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")]
1313
public string Text { get; set; }
1414
}
1515
#endregion
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"RazorPagesTestSample": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:55954;http://localhost:55955"
10+
}
11+
}
12+
}

src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.3" />
8+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
1010
</ItemGroup>
1111

1212
</Project>

src/Application/src/RazorPagesTestSample/RazorPagesTestSample.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.4.33110.190
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample", "RazorPagesTestSample.csproj", "{BE1E794D-8E4A-4676-8711-A0DBF523EAE2}"
77
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample.Tests", "..\..\tests\RazorPagesTestSample.Tests\RazorPagesTestSample.Tests.csproj", "{67C04E03-38E8-4DCA-8670-AC6854D479DF}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{67C04E03-38E8-4DCA-8670-AC6854D479DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{67C04E03-38E8-4DCA-8670-AC6854D479DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{67C04E03-38E8-4DCA-8670-AC6854D479DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{67C04E03-38E8-4DCA-8670-AC6854D479DF}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"RazorPagesTestSample.Tests": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"environmentVariables": {
7+
"ASPNETCORE_ENVIRONMENT": "Development"
8+
},
9+
"applicationUrl": "https://localhost:56864;http://localhost:56865"
10+
}
11+
}
12+
}

src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.3" />
12-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.3" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.8" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
1515
<PackageReference Include="Moq" Version="4.20.70" />
16-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
16+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1717
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
1818
<PackageReference Include="System.Net.Http" Version="4.3.4" />
19-
<PackageReference Include="xunit" Version="2.7.0" />
20-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
19+
<PackageReference Include="xunit" Version="2.9.0" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
2121
<PrivateAssets>all</PrivateAssets>
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
</PackageReference>

src/Application/tests/RazorPagesTestSample.Tests/UnitTests/DataAccessLayerTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.EntityFrameworkCore;
55
using Xunit;
66
using RazorPagesTestSample.Data;
7+
using System.ComponentModel.DataAnnotations;
78

89
namespace RazorPagesTestSample.Tests.UnitTests
910
{
@@ -126,5 +127,48 @@ public async Task DeleteMessageAsync_NoMessageIsDeleted_WhenMessageIsNotFound()
126127
}
127128
}
128129
#endregion
130+
131+
#region snippet5
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 void Message_LengthValidation(int length, bool isValid)
142+
{
143+
// Arrange
144+
var message = new Message
145+
{
146+
Id = 1,
147+
Text = new string('a', length)
148+
};
149+
150+
// Act
151+
var validationResults = ValidateModel(message);
152+
153+
// Assert
154+
if (isValid)
155+
{
156+
Assert.Empty(validationResults);
157+
}
158+
else
159+
{
160+
Assert.NotEmpty(validationResults);
161+
Assert.Contains(validationResults, v => v.ErrorMessage.Contains("250 character limit"));
162+
}
163+
}
164+
165+
private IList<ValidationResult> ValidateModel(object model)
166+
{
167+
var validationResults = new List<ValidationResult>();
168+
var validationContext = new ValidationContext(model, null, null);
169+
Validator.TryValidateObject(model, validationContext, validationResults, true);
170+
return validationResults;
171+
}
172+
#endregion
129173
}
130174
}

0 commit comments

Comments
 (0)