diff --git a/.gitignore b/.gitignore index ef060aea12b..d143b45f78f 100644 --- a/.gitignore +++ b/.gitignore @@ -138,6 +138,8 @@ _TeamCity* *.coverage *.coveragexml +[Cc]ode[Cc]overage/ + # NCrunch _NCrunch_* .*crunch*.local.xml diff --git a/README.md b/README.md index ece99adf323..08afcd86374 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Build Status](https://dev.azure.com/appdev-upskilling-fy26/vanessa.b.tomas/_apis/build/status%2Fvanessatomasb.mslearn-tailspin-spacegame-web?branchName=main)](https://dev.azure.com/appdev-upskilling-fy26/vanessa.b.tomas/_build/latest?definitionId=13&branchName=main) # Contributing @@ -63,3 +64,4 @@ Privacy information can be found at https://privacy.microsoft.com/en-us/ Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise. + diff --git a/Tailspin.SpaceGame.Web.Tests/DocumentDBRepository_GetItemsAsyncShould.cs b/Tailspin.SpaceGame.Web.Tests/DocumentDBRepository_GetItemsAsyncShould.cs new file mode 100644 index 00000000000..67fd4433c2c --- /dev/null +++ b/Tailspin.SpaceGame.Web.Tests/DocumentDBRepository_GetItemsAsyncShould.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq.Expressions; +using System.Threading.Tasks; +using NUnit.Framework; +using TailSpin.SpaceGame.Web; +using TailSpin.SpaceGame.Web.Models; + +namespace Tests +{ + public class DocumentDBRepository_GetItemsAsyncShould + { + private IDocumentDBRepository _scoreRepository; + + [SetUp] + public void Setup() + { + using (Stream scoresData = typeof(IDocumentDBRepository) + .Assembly + .GetManifestResourceStream("Tailspin.SpaceGame.Web.SampleData.scores.json")) + { + _scoreRepository = new LocalDocumentDBRepository(scoresData); + } + } + + [TestCase("Milky Way")] + [TestCase("Andromeda")] + [TestCase("Pinwheel")] + [TestCase("NGC 1300")] + [TestCase("Messier 82")] + public void FetchOnlyRequestedGameRegion(string gameRegion) + { + const int PAGE = 0; // take the first page of results + const int MAX_RESULTS = 10; // sample up to 10 results + + // Form the query predicate. + // Select all scores for the provided game region. + Func queryPredicate = score => (score.GameRegion == gameRegion); + + // Fetch the scores. + Task> scoresTask = _scoreRepository.GetItemsAsync( + queryPredicate, // the predicate defined above + score => 1, // we don't care about the order + PAGE, + MAX_RESULTS + ); + IEnumerable scores = scoresTask.Result; + + // Verify that each score's game region matches the provided game region. + Assert.That(scores, Is.All.Matches(score => score.GameRegion == gameRegion)); + } + } +} \ No newline at end of file diff --git a/Tailspin.SpaceGame.Web.Tests/Tailspin.SpaceGame.Web.Tests.csproj b/Tailspin.SpaceGame.Web.Tests/Tailspin.SpaceGame.Web.Tests.csproj new file mode 100644 index 00000000000..27aa861c683 --- /dev/null +++ b/Tailspin.SpaceGame.Web.Tests/Tailspin.SpaceGame.Web.Tests.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + false + {773BA444-0D67-4F37-8762-17E108CCD5F5} + + + + + + + + + + + + + diff --git a/Tailspin.SpaceGame.Web.sln b/Tailspin.SpaceGame.Web.sln index 466f2210090..4fa989cf27c 100644 --- a/Tailspin.SpaceGame.Web.sln +++ b/Tailspin.SpaceGame.Web.sln @@ -1,8 +1,10 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tailspin.SpaceGame.Web", "Tailspin.SpaceGame.Web\Tailspin.SpaceGame.Web.csproj", "{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tailspin.SpaceGame.Web.Tests", "Tailspin.SpaceGame.Web.Tests\Tailspin.SpaceGame.Web.Tests.csproj", "{773BA444-0D67-4F37-8762-17E108CCD5F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,5 +15,9 @@ Global {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Debug|Any CPU.Build.0 = Debug|Any CPU {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.ActiveCfg = Release|Any CPU {A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}.Release|Any CPU.Build.0 = Release|Any CPU + {773BA444-0D67-4F37-8762-17E108CCD5F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {773BA444-0D67-4F37-8762-17E108CCD5F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {773BA444-0D67-4F37-8762-17E108CCD5F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {773BA444-0D67-4F37-8762-17E108CCD5F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs b/Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs index 1390d78d3ec..286201d1800 100755 --- a/Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs +++ b/Tailspin.SpaceGame.Web/LocalDocumentDBRepository.cs @@ -19,6 +19,12 @@ public LocalDocumentDBRepository(string fileName) _items = JsonSerializer.Deserialize>(File.ReadAllText(fileName)); } + public LocalDocumentDBRepository(Stream stream) + { + // Serialize the items from the provided JSON document. + _items = JsonSerializer.Deserialize>(new StreamReader(stream).ReadToEnd()); + } + /// /// Retrieves the item from the store with the given identifier. /// diff --git a/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj b/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj index a3696867955..63e5a335782 100644 --- a/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj +++ b/Tailspin.SpaceGame.Web/Tailspin.SpaceGame.Web.csproj @@ -8,4 +8,26 @@ + + + + + + + + + Always + + + Always + + + + + PreserveNewest + + + PreserveNewest + + diff --git a/Tailspin.SpaceGame.Web/Views/Home/Index.cshtml b/Tailspin.SpaceGame.Web/Views/Home/Index.cshtml index f7c4c886074..70e7cc00092 100644 --- a/Tailspin.SpaceGame.Web/Views/Home/Index.cshtml +++ b/Tailspin.SpaceGame.Web/Views/Home/Index.cshtml @@ -5,7 +5,7 @@
Space Game -

An example site for learning

+

Welcome to the official Space Game site!

diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 23402e427df..0684cf2e0ce 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,3 +1,72 @@ -pool: MyAgentPool -steps: -- bash: echo hello world \ No newline at end of file +trigger: +- '*' + +pool: + vmImage: 'ubuntu-20.04' + demands: + - npm + +variables: + buildConfiguration: 'Release' + wwwrootDir: 'Tailspin.SpaceGame.Web/wwwroot' + dotnetSdkVersion: '8.x' + +steps: +- task: UseDotNet@2 + displayName: 'Use .NET SDK $(dotnetSdkVersion)' + inputs: + version: '$(dotnetSdkVersion)' + +- task: NodeTool@0 + displayName: 'Use Node.js 14.x' + inputs: + versionSpec: '14.x' + +- task: Npm@1 + displayName: 'Run npm install' + inputs: + verbose: false + +- script: './node_modules/.bin/node-sass $(wwwrootDir) --output $(wwwrootDir)' + displayName: 'Compile Sass assets' + +- task: gulp@1 + displayName: 'Run gulp tasks' + +- script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt' + displayName: 'Write build info' + workingDirectory: $(wwwrootDir) + +- task: DotNetCoreCLI@2 + displayName: 'Restore project dependencies' + inputs: + command: 'restore' + projects: '**/*.csproj' + +- task: DotNetCoreCLI@2 + displayName: 'Build the project - $(buildConfiguration)' + inputs: + command: 'build' + arguments: '--no-restore --configuration $(buildConfiguration)' + projects: '**/*.csproj' + +- task: DotNetCoreCLI@2 + displayName: 'Run unit tests - $(buildConfiguration)' + inputs: + command: 'test' + arguments: '--no-build --configuration $(buildConfiguration)' + publishTestResults: true + projects: '**/*.Tests.csproj' + +- task: DotNetCoreCLI@2 + displayName: 'Publish the project - $(buildConfiguration)' + inputs: + command: 'publish' + projects: '**/*.csproj' + publishWebProjects: false + arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)' + zipAfterPublish: true + +- task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: drop' + condition: succeeded()