From fb8f7125b814f28b695c02cc7f0cd1be99a81815 Mon Sep 17 00:00:00 2001 From: Rafferty Uy Date: Fri, 23 Aug 2024 17:42:42 +0800 Subject: [PATCH 1/2] first workflow --- .github/workflows/first-workflow.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/first-workflow.yml diff --git a/.github/workflows/first-workflow.yml b/.github/workflows/first-workflow.yml new file mode 100644 index 00000000..dfda158b --- /dev/null +++ b/.github/workflows/first-workflow.yml @@ -0,0 +1,26 @@ +name: My First Workflow +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + echo: + runs-on: ubuntu-latest + steps: + - name: Step 1 + run: echo "Step 1 complete" + - name: Step 2 + run: echo "Step 2 complete" + + cow: + name: Cowsays + runs-on: ubuntu-latest + steps: + - name: Ship it + uses: mscoutermarsh/cowsays-action@master + with: + text: 'Ready for prod–ship it!' + color: 'red' \ No newline at end of file From d6768dc065dc7d7b1bff4622a465c3cafdcf1855 Mon Sep 17 00:00:00 2001 From: Rafferty Uy Date: Tue, 27 Aug 2024 11:15:18 +0800 Subject: [PATCH 2/2] 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 --- .../src/RazorPagesTestSample/Data/Message.cs | 2 +- .../Properties/launchSettings.json | 12 +++++ .../RazorPagesTestSample.csproj | 4 +- .../RazorPagesTestSample.sln | 6 +++ .../Properties/launchSettings.json | 12 +++++ .../RazorPagesTestSample.Tests.csproj | 14 +++--- .../UnitTests/DataAccessLayerTest.cs | 44 +++++++++++++++++++ 7 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 src/Application/src/RazorPagesTestSample/Properties/launchSettings.json create mode 100644 src/Application/tests/RazorPagesTestSample.Tests/Properties/launchSettings.json diff --git a/src/Application/src/RazorPagesTestSample/Data/Message.cs b/src/Application/src/RazorPagesTestSample/Data/Message.cs index ea99cbd6..59f24395 100644 --- a/src/Application/src/RazorPagesTestSample/Data/Message.cs +++ b/src/Application/src/RazorPagesTestSample/Data/Message.cs @@ -9,7 +9,7 @@ public class Message [Required] [DataType(DataType.Text)] - [StringLength(200, ErrorMessage = "There's a 200 character limit on messages. Please shorten your message.")] + [StringLength(250, ErrorMessage = "There's a 250 character limit on messages. Please shorten your message.")] public string Text { get; set; } } #endregion diff --git a/src/Application/src/RazorPagesTestSample/Properties/launchSettings.json b/src/Application/src/RazorPagesTestSample/Properties/launchSettings.json new file mode 100644 index 00000000..e428766f --- /dev/null +++ b/src/Application/src/RazorPagesTestSample/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "RazorPagesTestSample": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:55954;http://localhost:55955" + } + } +} \ No newline at end of file diff --git a/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj b/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj index 34070413..1fd03db0 100644 --- a/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj +++ b/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.sln b/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.sln index efe43ea0..e15697e2 100644 --- a/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.sln +++ b/src/Application/src/RazorPagesTestSample/RazorPagesTestSample.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.4.33110.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample", "RazorPagesTestSample.csproj", "{BE1E794D-8E4A-4676-8711-A0DBF523EAE2}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample.Tests", "..\..\tests\RazorPagesTestSample.Tests\RazorPagesTestSample.Tests.csproj", "{67C04E03-38E8-4DCA-8670-AC6854D479DF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE1E794D-8E4A-4676-8711-A0DBF523EAE2}.Release|Any CPU.Build.0 = Release|Any CPU + {67C04E03-38E8-4DCA-8670-AC6854D479DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67C04E03-38E8-4DCA-8670-AC6854D479DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67C04E03-38E8-4DCA-8670-AC6854D479DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67C04E03-38E8-4DCA-8670-AC6854D479DF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Application/tests/RazorPagesTestSample.Tests/Properties/launchSettings.json b/src/Application/tests/RazorPagesTestSample.Tests/Properties/launchSettings.json new file mode 100644 index 00000000..866b3910 --- /dev/null +++ b/src/Application/tests/RazorPagesTestSample.Tests/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "RazorPagesTestSample.Tests": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:56864;http://localhost:56865" + } + } +} \ No newline at end of file diff --git a/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj b/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj index a66e0a92..7addb37a 100644 --- a/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj +++ b/src/Application/tests/RazorPagesTestSample.Tests/RazorPagesTestSample.Tests.csproj @@ -8,16 +8,16 @@ - - - - + + + + - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Application/tests/RazorPagesTestSample.Tests/UnitTests/DataAccessLayerTest.cs b/src/Application/tests/RazorPagesTestSample.Tests/UnitTests/DataAccessLayerTest.cs index 91a91aaa..e24385ef 100644 --- a/src/Application/tests/RazorPagesTestSample.Tests/UnitTests/DataAccessLayerTest.cs +++ b/src/Application/tests/RazorPagesTestSample.Tests/UnitTests/DataAccessLayerTest.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Xunit; using RazorPagesTestSample.Data; +using System.ComponentModel.DataAnnotations; namespace RazorPagesTestSample.Tests.UnitTests { @@ -126,5 +127,48 @@ public async Task DeleteMessageAsync_NoMessageIsDeleted_WhenMessageIsNotFound() } } #endregion + + #region snippet5 + [Theory] + [InlineData(150, true)] + [InlineData(199, true)] + [InlineData(200, true)] + [InlineData(201, true)] + [InlineData(249, true)] + [InlineData(250, true)] + [InlineData(251, false)] + [InlineData(300, false)] + public void Message_LengthValidation(int length, bool isValid) + { + // Arrange + var message = new Message + { + Id = 1, + Text = new string('a', length) + }; + + // Act + var validationResults = ValidateModel(message); + + // Assert + if (isValid) + { + Assert.Empty(validationResults); + } + else + { + Assert.NotEmpty(validationResults); + Assert.Contains(validationResults, v => v.ErrorMessage.Contains("250 character limit")); + } + } + + private IList ValidateModel(object model) + { + var validationResults = new List(); + var validationContext = new ValidationContext(model, null, null); + Validator.TryValidateObject(model, validationContext, validationResults, true); + return validationResults; + } + #endregion } }