├── .gitignore ├── .travis.yml ├── Depot.sln ├── LICENSE ├── README.md ├── after-success.sh ├── run-tests.sh ├── scripts ├── docker-compose.yaml ├── docker-run.sh ├── dotnet-build.sh ├── dotnet-restore.ps1 └── dotnet-restore.sh ├── src ├── Depot.Api │ ├── Controllers │ │ ├── EntriesController.cs │ │ ├── HomeController.cs │ │ └── LogsController.cs │ ├── Depot.Api.csproj │ ├── Dockerfile │ ├── Dockerfile.development │ ├── Dockerfile.production │ ├── Framework │ │ ├── ErrorHandlerMiddleware.cs │ │ ├── Extensions.cs │ │ └── RabbitMqOptions.cs │ ├── Handlers │ │ ├── CreateEntryRejectedHandler.cs │ │ └── EntryCreatedHandler.cs │ ├── Program.cs │ ├── Repositories │ │ ├── ILogRepository.cs │ │ └── LogRepository.cs │ ├── Startup.cs │ ├── appsettings.development.json │ ├── appsettings.docker.json │ ├── appsettings.json │ └── appsettings.production.json ├── Depot.Messages │ ├── Commands │ │ ├── CreateEntry.cs │ │ ├── ICommand.cs │ │ └── ICommandHandler.cs │ ├── Depot.Messages.csproj │ └── Events │ │ ├── CreateEntryRejected.cs │ │ ├── EntryCreated.cs │ │ ├── IEvent.cs │ │ └── IEventHandler.cs └── Depot.Services.Entries │ ├── Controllers │ ├── EntriesController.cs │ └── HomeController.cs │ ├── Depot.Services.Entries.csproj │ ├── Dockerfile │ ├── Dockerfile.development │ ├── Dockerfile.production │ ├── Framework │ ├── MongoConfigurator.cs │ ├── MongoOptions.cs │ ├── RabbitMqOptions.cs │ └── RedisOptions.cs │ ├── Handlers │ └── CreateEntryHandler.cs │ ├── Models │ └── Entry.cs │ ├── Program.cs │ ├── Repositories │ ├── EntryRepository.cs │ ├── IEntryRepository.cs │ └── MongoEntryRepository.cs │ ├── Startup.cs │ ├── appsettings.development.json │ ├── appsettings.docker.json │ ├── appsettings.json │ └── appsettings.production.json ├── tests ├── Depot.Tests.EndToEnd │ ├── Controllers │ │ └── EntriesControllerTests.cs │ ├── Depot.Tests.EndToEnd.csproj │ └── appsettings.json └── Depot.Tests │ ├── Depot.Tests.csproj │ └── Handlers │ └── CreateEntryHandlerTests.cs └── travis-build.sh /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # Visual Studio code coverage results 114 | *.coverage 115 | *.coveragexml 116 | 117 | # NCrunch 118 | _NCrunch_* 119 | .*crunch*.local.xml 120 | nCrunchTemp_* 121 | 122 | # MightyMoose 123 | *.mm.* 124 | AutoTest.Net/ 125 | 126 | # Web workbench (sass) 127 | .sass-cache/ 128 | 129 | # Installshield output folder 130 | [Ee]xpress/ 131 | 132 | # DocProject is a documentation generator add-in 133 | DocProject/buildhelp/ 134 | DocProject/Help/*.HxT 135 | DocProject/Help/*.HxC 136 | DocProject/Help/*.hhc 137 | DocProject/Help/*.hhk 138 | DocProject/Help/*.hhp 139 | DocProject/Help/Html2 140 | DocProject/Help/html 141 | 142 | # Click-Once directory 143 | publish/ 144 | 145 | # Publish Web Output 146 | *.[Pp]ublish.xml 147 | *.azurePubxml 148 | # TODO: Comment the next line if you want to checkin your web deploy settings 149 | # but database connection strings (with potential passwords) will be unencrypted 150 | *.pubxml 151 | *.publishproj 152 | 153 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 154 | # checkin your Azure Web App publish settings, but sensitive information contained 155 | # in these scripts will be unencrypted 156 | PublishScripts/ 157 | 158 | # NuGet Packages 159 | *.nupkg 160 | # The packages folder can be ignored because of Package Restore 161 | **/packages/* 162 | # except build/, which is used as an MSBuild target. 163 | !**/packages/build/ 164 | # Uncomment if necessary however generally it will be regenerated when needed 165 | #!**/packages/repositories.config 166 | # NuGet v3's project.json files produces more ignoreable files 167 | *.nuget.props 168 | *.nuget.targets 169 | 170 | # Microsoft Azure Build Output 171 | csx/ 172 | *.build.csdef 173 | 174 | # Microsoft Azure Emulator 175 | ecf/ 176 | rcf/ 177 | 178 | # Windows Store app package directories and files 179 | AppPackages/ 180 | BundleArtifacts/ 181 | Package.StoreAssociation.xml 182 | _pkginfo.txt 183 | 184 | # Visual Studio cache files 185 | # files ending in .cache can be ignored 186 | *.[Cc]ache 187 | # but keep track of directories ending in .cache 188 | !*.[Cc]ache/ 189 | 190 | # Others 191 | ClientBin/ 192 | ~$* 193 | *~ 194 | *.dbmdl 195 | *.dbproj.schemaview 196 | *.jfm 197 | *.pfx 198 | *.publishsettings 199 | node_modules/ 200 | orleans.codegen.cs 201 | 202 | # Since there are multiple workflows, uncomment next line to ignore bower_components 203 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 204 | #bower_components/ 205 | 206 | # RIA/Silverlight projects 207 | Generated_Code/ 208 | 209 | # Backup & report files from converting an old project file 210 | # to a newer Visual Studio version. Backup files are not needed, 211 | # because we have git ;-) 212 | _UpgradeReport_Files/ 213 | Backup*/ 214 | UpgradeLog*.XML 215 | UpgradeLog*.htm 216 | 217 | # SQL Server files 218 | *.mdf 219 | *.ldf 220 | 221 | # Business Intelligence projects 222 | *.rdl.data 223 | *.bim.layout 224 | *.bim_*.settings 225 | 226 | # Microsoft Fakes 227 | FakesAssemblies/ 228 | 229 | # GhostDoc plugin setting file 230 | *.GhostDoc.xml 231 | 232 | # Node.js Tools for Visual Studio 233 | .ntvs_analysis.dat 234 | 235 | # Visual Studio 6 build log 236 | *.plg 237 | 238 | # Visual Studio 6 workspace options file 239 | *.opt 240 | 241 | # Visual Studio LightSwitch build output 242 | **/*.HTMLClient/GeneratedArtifacts 243 | **/*.DesktopClient/GeneratedArtifacts 244 | **/*.DesktopClient/ModelManifest.xml 245 | **/*.Server/GeneratedArtifacts 246 | **/*.Server/ModelManifest.xml 247 | _Pvt_Extensions 248 | 249 | # Paket dependency manager 250 | .paket/paket.exe 251 | paket-files/ 252 | 253 | # FAKE - F# Make 254 | .fake/ 255 | 256 | # JetBrains Rider 257 | .idea/ 258 | *.sln.iml 259 | 260 | # CodeRush 261 | .cr/ 262 | 263 | # Python Tools for Visual Studio (PTVS) 264 | __pycache__/ 265 | *.pyc 266 | 267 | .vscode/* 268 | !.vscode/settings.json 269 | !.vscode/tasks.json 270 | !.vscode/launch.json 271 | 272 | appsettings.local.json 273 | .vscode/ 274 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | dist: trusty 3 | sudo: required 4 | mono: none 5 | dotnet: 1.0.1 6 | branches: 7 | only: 8 | - master 9 | - develop 10 | before_script: 11 | - chmod a+x ./travis-build.sh 12 | - chmod a+x ./run-tests.sh 13 | - chmod a+x ./after-success.sh 14 | script: 15 | - ./travis-build.sh 16 | - ./run-tests.sh 17 | after_success: 18 | - ./after-success.sh 19 | notifications: 20 | email: 21 | on_success: never 22 | on_failure: always -------------------------------------------------------------------------------- /Depot.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Depot.Api", "src\Depot.Api\Depot.Api.csproj", "{5E4E2AD3-E295-4E3E-91DA-E681A3907229}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Depot.Messages", "src\Depot.Messages\Depot.Messages.csproj", "{5CAD375E-457C-4FCF-88C5-7FB1164A70C6}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Depot.Services.Entries", "src\Depot.Services.Entries\Depot.Services.Entries.csproj", "{FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Depot.Tests", "tests\Depot.Tests\Depot.Tests.csproj", "{591FEF7E-70A1-42BC-AE09-0BB2C03F9A32}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Depot.Tests.EndToEnd", "tests\Depot.Tests.EndToEnd\Depot.Tests.EndToEnd.csproj", "{45FA1903-28FB-4682-8B2D-A3507B50B0B0}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{98A0B189-511B-4DCE-86E7-12E3FC41852C}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6D43B600-55DE-4D7C-B806-383D7D2223A1}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{901B3395-F253-4AFF-A67E-4A9C4B774D5D}" 19 | ProjectSection(SolutionItems) = preProject 20 | scripts\docker-compose.yaml = scripts\docker-compose.yaml 21 | scripts\docker-run.sh = scripts\docker-run.sh 22 | scripts\dotnet-build.sh = scripts\dotnet-build.sh 23 | scripts\dotnet-restore.ps1 = scripts\dotnet-restore.ps1 24 | scripts\dotnet-restore.sh = scripts\dotnet-restore.sh 25 | EndProjectSection 26 | EndProject 27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{984CB460-309E-420A-AF0F-3AC826808180}" 28 | ProjectSection(SolutionItems) = preProject 29 | after-success.sh = after-success.sh 30 | LICENSE = LICENSE 31 | README.md = README.md 32 | run-tests.sh = run-tests.sh 33 | travis-build.sh = travis-build.sh 34 | EndProjectSection 35 | EndProject 36 | Global 37 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 38 | Debug|Any CPU = Debug|Any CPU 39 | Release|Any CPU = Release|Any CPU 40 | EndGlobalSection 41 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 42 | {5E4E2AD3-E295-4E3E-91DA-E681A3907229}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {5E4E2AD3-E295-4E3E-91DA-E681A3907229}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {5E4E2AD3-E295-4E3E-91DA-E681A3907229}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {5E4E2AD3-E295-4E3E-91DA-E681A3907229}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {5CAD375E-457C-4FCF-88C5-7FB1164A70C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {5CAD375E-457C-4FCF-88C5-7FB1164A70C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {5CAD375E-457C-4FCF-88C5-7FB1164A70C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {5CAD375E-457C-4FCF-88C5-7FB1164A70C6}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {591FEF7E-70A1-42BC-AE09-0BB2C03F9A32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {591FEF7E-70A1-42BC-AE09-0BB2C03F9A32}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {591FEF7E-70A1-42BC-AE09-0BB2C03F9A32}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {591FEF7E-70A1-42BC-AE09-0BB2C03F9A32}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {45FA1903-28FB-4682-8B2D-A3507B50B0B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {45FA1903-28FB-4682-8B2D-A3507B50B0B0}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {45FA1903-28FB-4682-8B2D-A3507B50B0B0}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {45FA1903-28FB-4682-8B2D-A3507B50B0B0}.Release|Any CPU.Build.0 = Release|Any CPU 62 | EndGlobalSection 63 | GlobalSection(NestedProjects) = preSolution 64 | {5E4E2AD3-E295-4E3E-91DA-E681A3907229} = {98A0B189-511B-4DCE-86E7-12E3FC41852C} 65 | {5CAD375E-457C-4FCF-88C5-7FB1164A70C6} = {98A0B189-511B-4DCE-86E7-12E3FC41852C} 66 | {FDC0AAFD-CA5C-4326-9124-FA8A2362A9E0} = {98A0B189-511B-4DCE-86E7-12E3FC41852C} 67 | {591FEF7E-70A1-42BC-AE09-0BB2C03F9A32} = {6D43B600-55DE-4D7C-B806-383D7D2223A1} 68 | {45FA1903-28FB-4682-8B2D-A3507B50B0B0} = {6D43B600-55DE-4D7C-B806-383D7D2223A1} 69 | EndGlobalSection 70 | EndGlobal 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Piotr Gankiewicz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Depot is a sample distributed app (API + Service) using MongoDB, RabbitMQ, Redis & built with .NET Core. 2 | 3 | |Branch |Build status 4 | |-------------------|----------------------------------------------------- 5 | |master |[![master branch build status](https://api.travis-ci.org/spetz/Depot.svg?branch=master)](https://travis-ci.org/spetz/Depot) 6 | |develop |[![develop branch build status](https://api.travis-ci.org/spetz/Depot.svg?branch=develop)](https://travis-ci.org/spetz/Depot/branches) 7 | 8 | 9 | In order to start the application type the following commands: 10 | 11 | ``` 12 | cd scripts 13 | docker-compose build 14 | ./docker-run.sh 15 | ``` 16 | 17 | Or simply _dotnet run_ projects separately and make sure that MongoDB, RabbitMQ and Redis are running as services. 18 | 19 | Depot API will be running at [http://localhost:5000](http://localhost:5000) and Entries Service at [http://localhost:5050](http://localhost:5050). 20 | 21 | For more information take a look at my [blog post](http://piotrgankiewicz.com/2017/05/15/depot-building-asp-net-core-distributed-application/). 22 | 23 | ## Usage 24 | 25 | Create a new entry via HTTP request: 26 | 27 | ``` 28 | curl localhost:5000/entries -X POST -H "content-type: application/json" -d '{"key": "my-key", "value": "sample value"}' 29 | ``` 30 | 31 | Browse logs: [http://localhost:5000/logs](http://localhost:5000/logs) 32 | 33 | Browse keys: [http://localhost:5050/entries](http://localhost:5050/entries) 34 | 35 | Fetch value: [http://localhost:5050/entries/{key}](http://localhost:5050/entries/{key}) 36 | -------------------------------------------------------------------------------- /after-success.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo Build completed on branch $TRAVIS_BRANCH -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | dotnet test tests/Depot.Tests/Depot.Tests.csproj -------------------------------------------------------------------------------- /scripts/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | services: 4 | start_dependencies: 5 | image: dadarek/wait-for-dependencies 6 | depends_on: 7 | - mongo 8 | - rabbitmq 9 | - redis 10 | command: rabbitmq:5672 11 | 12 | api: 13 | build: ../src/Depot.Api 14 | links: 15 | - rabbitmq 16 | - entries-service 17 | ports: 18 | - '5000:5000' 19 | 20 | entries-service: 21 | build: ../src/Depot.Services.Entries 22 | links: 23 | - mongo 24 | - rabbitmq 25 | - redis 26 | ports: 27 | - '5050:5050' 28 | 29 | mongo: 30 | image: mongo 31 | volumes: 32 | - ./data/db:/data/db 33 | ports: 34 | - '27017:27017' 35 | 36 | rabbitmq: 37 | image: rabbitmq:3.6.5-management 38 | ports: 39 | - '5672:5672' 40 | - '15672:15672' 41 | 42 | redis: 43 | image: redis 44 | ports: 45 | - '6379:6379' -------------------------------------------------------------------------------- /scripts/docker-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker-compose run start_dependencies 3 | docker-compose up -------------------------------------------------------------------------------- /scripts/dotnet-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source=-"-source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/netcoretour/api/v3/index.json --no-cache" 3 | cd ../src 4 | projects=(Depot.Api Depot.Messages Depot.Services.Entries) 5 | for project in ${projects[*]} 6 | do 7 | echo ======================================================== 8 | echo Building project: $project 9 | echo ======================================================== 10 | dotnet build $project/$project.csproj 11 | done 12 | 13 | testprojects=(Depot.Tests Depot.Tests.EndToEnd) 14 | cd ../tests 15 | for project in ${testprojects[*]} 16 | do 17 | echo ======================================================== 18 | echo Building test project: $project 19 | echo ======================================================== 20 | dotnet build $project/$project.csproj 21 | done -------------------------------------------------------------------------------- /scripts/dotnet-restore.ps1: -------------------------------------------------------------------------------- 1 | $rootLocation = "$PSScriptRoot/.." 2 | $source = "-source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/netcoretour/api/v3/index.json --no-cache" 3 | $projects = @("Depot.Api", "Depot.Messages", "Depot.Services.Entries") 4 | 5 | $projects | ForEach-Object { 6 | Write-Host "========================================================" 7 | Write-Host "Restoring packages for test project: $project" 8 | Write-Host "========================================================" 9 | Set-Location "$($rootLocation)/src/$($_)" 10 | Invoke-Command -ScriptBlock { dotnet restore } 11 | } 12 | 13 | $testProjects = @("Depot.Tests", "Depot.Tests.EndToEnd") 14 | $testProjects | ForEach-Object { 15 | Write-Host "========================================================" 16 | Write-Host "Restoring packages for test project: $project" 17 | Write-Host "========================================================" 18 | Set-Location "$($rootLocation)/tests/$($_)" 19 | Invoke-Command -ScriptBlock { dotnet restore } 20 | } 21 | 22 | Set-Location "$rootLocation/scripts" -------------------------------------------------------------------------------- /scripts/dotnet-restore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source=-"-source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/netcoretour/api/v3/index.json --no-cache" 3 | cd ../src 4 | projects=(Depot.Api Depot.Messages Depot.Services.Entries) 5 | for project in ${projects[*]} 6 | do 7 | echo ======================================================== 8 | echo Restoring packages for project: $project 9 | echo ======================================================== 10 | dotnet restore $project $source 11 | done 12 | 13 | testprojects=(Depot.Tests Depot.Tests.EndToEnd) 14 | cd ../tests 15 | for project in ${testprojects[*]} 16 | do 17 | echo ======================================================== 18 | echo Restoring packages for test project: $project 19 | echo ======================================================== 20 | dotnet restore $project $source 21 | done -------------------------------------------------------------------------------- /src/Depot.Api/Controllers/EntriesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Depot.Messages.Commands; 4 | using Microsoft.AspNetCore.Mvc; 5 | using RawRabbit; 6 | 7 | namespace Depot.Api.Controllers 8 | { 9 | [Route("[controller]")] 10 | public class EntriesController : Controller 11 | { 12 | private readonly IBusClient _busClient; 13 | 14 | public EntriesController(IBusClient busClient) 15 | { 16 | _busClient = busClient; 17 | } 18 | 19 | [HttpPost] 20 | public async Task Post([FromBody]CreateEntry command) 21 | { 22 | if(string.IsNullOrWhiteSpace(command.Key)) 23 | { 24 | throw new ArgumentException("Entry key can not be empty.", nameof(command.Key)); 25 | } 26 | await _busClient.PublishAsync(command); 27 | 28 | return Accepted(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Depot.Api/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Depot.Api.Controllers 4 | { 5 | [Route("")] 6 | public class HomeController : Controller 7 | { 8 | [HttpGet] 9 | public IActionResult Get() 10 | { 11 | return Content("Welcome to the Depot API!"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Depot.Api/Controllers/LogsController.cs: -------------------------------------------------------------------------------- 1 | using Depot.Api.Repositories; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace Depot.Api.Controllers 5 | { 6 | [Route("[controller]")] 7 | public class LogsController : Controller 8 | { 9 | private readonly ILogRepository _repository; 10 | 11 | public LogsController(ILogRepository repository) 12 | { 13 | _repository = repository; 14 | } 15 | 16 | [HttpGet] 17 | public IActionResult Get() => Json(_repository.Logs); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Depot.Api/Depot.Api.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Depot.Api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5000/tcp 9 | ENV ASPNETCORE_URLS http://*:5000 10 | ENV ASPNETCORE_ENVIRONMENT docker 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Api/Dockerfile.development: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5000/tcp 9 | ENV ASPNETCORE_URLS http://*:5000 10 | ENV ASPNETCORE_ENVIRONMENT development 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Api/Dockerfile.production: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5000/tcp 9 | ENV ASPNETCORE_URLS http://*:5000 10 | ENV ASPNETCORE_ENVIRONMENT production 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Api/Framework/ErrorHandlerMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Http; 5 | using Newtonsoft.Json; 6 | 7 | namespace Depot.Api.Framework 8 | { 9 | public class ErrorHandlerMiddleware 10 | { 11 | private readonly RequestDelegate _next; 12 | 13 | public ErrorHandlerMiddleware(RequestDelegate next) 14 | { 15 | _next = next; 16 | } 17 | 18 | public async Task Invoke(HttpContext context) 19 | { 20 | try 21 | { 22 | await _next(context); 23 | } 24 | catch (Exception ex) 25 | { 26 | await HandleExceptionAsync(context, ex); 27 | } 28 | } 29 | 30 | private static Task HandleExceptionAsync(HttpContext context, Exception exception) 31 | { 32 | var statusCode = HttpStatusCode.BadRequest; 33 | var exceptionType = exception.GetType(); 34 | switch(exception) 35 | { 36 | case Exception e when exceptionType == typeof(ArgumentException): 37 | statusCode = HttpStatusCode.BadRequest; 38 | break; 39 | case Exception e when exceptionType == typeof(UnauthorizedAccessException): 40 | statusCode = HttpStatusCode.Unauthorized; 41 | break; 42 | case Exception e when exceptionType == typeof(Exception): 43 | statusCode = HttpStatusCode.InternalServerError; 44 | break; 45 | } 46 | 47 | var response = new { message = exception.Message }; 48 | var payload = JsonConvert.SerializeObject(response); 49 | context.Response.ContentType = "application/json"; 50 | context.Response.StatusCode = (int)statusCode; 51 | 52 | return context.Response.WriteAsync(payload); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Depot.Api/Framework/Extensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | 3 | namespace Depot.Api.Framework 4 | { 5 | public static class Extensions 6 | { 7 | public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder builder) 8 | => builder.UseMiddleware(typeof(ErrorHandlerMiddleware)); 9 | } 10 | } -------------------------------------------------------------------------------- /src/Depot.Api/Framework/RabbitMqOptions.cs: -------------------------------------------------------------------------------- 1 | using RawRabbit.Configuration; 2 | 3 | namespace Depot.Api.Framework 4 | { 5 | public class RabbitMqOptions : RawRabbitConfiguration 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/Depot.Api/Handlers/CreateEntryRejectedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Depot.Api.Repositories; 4 | using Depot.Messages.Events; 5 | using RawRabbit; 6 | 7 | namespace Depot.Api.Handlers 8 | { 9 | public class CreateEntryRejectedHandler : IEventHandler 10 | { 11 | private readonly IBusClient _busClient; 12 | private readonly ILogRepository _repository; 13 | 14 | public CreateEntryRejectedHandler(IBusClient busClient, ILogRepository repository) 15 | { 16 | _busClient = busClient; 17 | _repository = repository; 18 | } 19 | 20 | public async Task HandleAsync(CreateEntryRejected command) 21 | { 22 | var message = $"{DateTime.UtcNow}: Could not create an entry with key: '{command.Key}'. {command.Reason}"; 23 | Console.WriteLine(message); 24 | _repository.Logs.Add(message); 25 | await Task.CompletedTask; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Depot.Api/Handlers/EntryCreatedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Depot.Api.Repositories; 4 | using Depot.Messages.Events; 5 | using RawRabbit; 6 | 7 | namespace Depot.Api.Handlers 8 | { 9 | public class EntryCreatedHandler : IEventHandler 10 | { 11 | private readonly IBusClient _busClient; 12 | private readonly ILogRepository _repository; 13 | 14 | public EntryCreatedHandler(IBusClient busClient, ILogRepository repository) 15 | { 16 | _busClient = busClient; 17 | _repository = repository; 18 | } 19 | 20 | public async Task HandleAsync(EntryCreated command) 21 | { 22 | var message = $"{DateTime.UtcNow}: New entry with key: '{command.Key}' was created."; 23 | Console.WriteLine(message); 24 | _repository.Logs.Add(message); 25 | await Task.CompletedTask; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Depot.Api/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | 9 | namespace Depot.Api 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | var host = new WebHostBuilder() 16 | .UseKestrel() 17 | .UseContentRoot(Directory.GetCurrentDirectory()) 18 | .UseIISIntegration() 19 | .UseStartup() 20 | .Build(); 21 | 22 | host.Run(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Depot.Api/Repositories/ILogRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Depot.Api.Repositories 4 | { 5 | public interface ILogRepository 6 | { 7 | ICollection Logs { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/Depot.Api/Repositories/LogRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Depot.Api.Repositories 5 | { 6 | public class LogRepository : ILogRepository 7 | { 8 | private static readonly ICollection _logs = new List(); 9 | public ICollection Logs => _logs; 10 | } 11 | } -------------------------------------------------------------------------------- /src/Depot.Api/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Autofac; 6 | using Autofac.Extensions.DependencyInjection; 7 | using Depot.Api.Framework; 8 | using Depot.Api.Handlers; 9 | using Depot.Api.Repositories; 10 | using Depot.Messages.Events; 11 | using Microsoft.AspNetCore.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.Extensions.Configuration; 14 | using Microsoft.Extensions.DependencyInjection; 15 | using Microsoft.Extensions.Logging; 16 | using Newtonsoft.Json; 17 | using RawRabbit; 18 | using RawRabbit.vNext; 19 | 20 | namespace Depot.Api 21 | { 22 | public class Startup 23 | { 24 | public IConfigurationRoot Configuration { get; } 25 | public IContainer Container { get; set; } 26 | 27 | public Startup(IHostingEnvironment env) 28 | { 29 | var builder = new ConfigurationBuilder() 30 | .SetBasePath(env.ContentRootPath) 31 | .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 32 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 33 | .AddEnvironmentVariables(); 34 | Configuration = builder.Build(); 35 | } 36 | 37 | // This method gets called by the runtime. Use this method to add services to the container. 38 | public IServiceProvider ConfigureServices(IServiceCollection services) 39 | { 40 | // Add framework services. 41 | services.AddMvc() 42 | .AddJsonOptions(x => x.SerializerSettings.Formatting = Formatting.Indented); 43 | services.AddScoped(); 44 | ConfigureRabbitMqServices(services); 45 | 46 | var builder = new ContainerBuilder(); 47 | builder.Populate(services); 48 | Container = builder.Build(); 49 | 50 | return new AutofacServiceProvider(Container); 51 | } 52 | 53 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 54 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 55 | { 56 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 57 | loggerFactory.AddDebug(); 58 | 59 | ConfigureRabbitMqSubscriptions(app); 60 | app.UseErrorHandler(); 61 | app.UseMvc(); 62 | } 63 | 64 | private void ConfigureRabbitMqServices(IServiceCollection services) 65 | { 66 | var rabbitMqOptions = new RabbitMqOptions(); 67 | var rabbitMqOptionsSection = Configuration.GetSection("rabbitmq"); 68 | rabbitMqOptionsSection.Bind(rabbitMqOptions); 69 | 70 | var rabbitMqClient = BusClientFactory.CreateDefault(rabbitMqOptions); 71 | services.Configure(rabbitMqOptionsSection); 72 | services.AddSingleton(_ => rabbitMqClient); 73 | services.AddScoped, EntryCreatedHandler>(); 74 | services.AddScoped, CreateEntryRejectedHandler>(); 75 | } 76 | 77 | private void ConfigureRabbitMqSubscriptions(IApplicationBuilder app) 78 | { 79 | var rabbitMqClient = app.ApplicationServices.GetService(); 80 | var entryCreatedHandler = app.ApplicationServices.GetService>(); 81 | var createEntryRejectedHandler = app.ApplicationServices.GetService>(); 82 | rabbitMqClient.SubscribeAsync(async (msg, context) 83 | => await entryCreatedHandler.HandleAsync(msg)); 84 | rabbitMqClient.SubscribeAsync(async (msg, context) 85 | => await createEntryRejectedHandler.HandleAsync(msg)); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Depot.Api/appsettings.development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Depot.Api/appsettings.docker.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "rabbitmq": { 9 | "Username": "guest", 10 | "Password": "guest", 11 | "VirtualHost": "/", 12 | "Port": 5672, 13 | "Hostnames": [ "rabbitmq" ], 14 | "RequestTimeout": "00:00:10", 15 | "PublishConfirmTimeout": "00:00:01", 16 | "RecoveryInterval": "00:00:10", 17 | "PersistentDeliveryMode": true, 18 | "AutoCloseConnection": true, 19 | "AutomaticRecovery": true, 20 | "TopologyRecovery": true, 21 | "Exchange": { 22 | "Durable": true, 23 | "AutoDelete": true, 24 | "Type": "Topic" 25 | }, 26 | "Queue": { 27 | "AutoDelete": true, 28 | "Durable": true, 29 | "Exclusive": true 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Depot.Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "rabbitmq": { 9 | "Username": "guest", 10 | "Password": "guest", 11 | "VirtualHost": "/", 12 | "Port": 5672, 13 | "Hostnames": [ "localhost" ], 14 | "RequestTimeout": "00:00:10", 15 | "PublishConfirmTimeout": "00:00:01", 16 | "RecoveryInterval": "00:00:10", 17 | "PersistentDeliveryMode": true, 18 | "AutoCloseConnection": true, 19 | "AutomaticRecovery": true, 20 | "TopologyRecovery": true, 21 | "Exchange": { 22 | "Durable": true, 23 | "AutoDelete": true, 24 | "Type": "Topic" 25 | }, 26 | "Queue": { 27 | "AutoDelete": true, 28 | "Durable": true, 29 | "Exclusive": true 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Depot.Api/appsettings.production.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "rabbitmq": { 9 | "Username": "guest", 10 | "Password": "guest", 11 | "VirtualHost": "/", 12 | "Port": 5672, 13 | "Hostnames": [ "localhost" ], 14 | "RequestTimeout": "00:00:10", 15 | "PublishConfirmTimeout": "00:00:01", 16 | "RecoveryInterval": "00:00:10", 17 | "PersistentDeliveryMode": true, 18 | "AutoCloseConnection": true, 19 | "AutomaticRecovery": true, 20 | "TopologyRecovery": true, 21 | "Exchange": { 22 | "Durable": true, 23 | "AutoDelete": true, 24 | "Type": "Topic" 25 | }, 26 | "Queue": { 27 | "AutoDelete": true, 28 | "Durable": true, 29 | "Exclusive": true 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Commands/CreateEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Depot.Messages.Commands 4 | { 5 | public class CreateEntry : ICommand 6 | { 7 | public string Key { get; set; } 8 | public object Value { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Messages.Commands 2 | { 3 | //Marker interface. 4 | public interface ICommand 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Commands/ICommandHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Depot.Messages.Commands 4 | { 5 | public interface ICommandHandler where T : ICommand 6 | { 7 | Task HandleAsync(T command); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Depot.Messages.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard1.4 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Depot.Messages/Events/CreateEntryRejected.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Messages.Events 2 | { 3 | public class CreateEntryRejected: IEvent 4 | { 5 | public string Key { get; } 6 | public string Reason { get; } 7 | 8 | protected CreateEntryRejected() 9 | { 10 | } 11 | 12 | public CreateEntryRejected(string key, string reason) 13 | { 14 | Key = key; 15 | Reason = reason; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Events/EntryCreated.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Messages.Events 2 | { 3 | public class EntryCreated : IEvent 4 | { 5 | public string Key { get; } 6 | 7 | protected EntryCreated() 8 | { 9 | } 10 | 11 | public EntryCreated(string key) 12 | { 13 | Key = key; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Events/IEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Messages.Events 2 | { 3 | public interface IEvent 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/Depot.Messages/Events/IEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Depot.Messages.Events 4 | { 5 | public interface IEventHandler where T : IEvent 6 | { 7 | Task HandleAsync(T @event); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Controllers/EntriesController.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Threading.Tasks; 3 | using Depot.Services.Entries.Repositories; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.Extensions.Caching.Distributed; 6 | using Newtonsoft.Json; 7 | using RawRabbit; 8 | 9 | namespace Depot.Services.Entries.Controllers 10 | { 11 | [Route("[controller]")] 12 | public class EntriesController : Controller 13 | { 14 | private readonly IEntryRepository _repository; 15 | private readonly IDistributedCache _cache; 16 | 17 | public EntriesController(IEntryRepository repository, IDistributedCache cache) 18 | { 19 | _repository = repository; 20 | _cache = cache; 21 | } 22 | 23 | [HttpGet] 24 | public async Task Get() 25 | { 26 | var entries = await _repository.BrowseAsync(); 27 | 28 | return Json(entries.Select(x => x.Key)); 29 | } 30 | 31 | [HttpGet("{key}")] 32 | public async Task Get(string key) 33 | { 34 | var cacheItem = await _cache.GetStringAsync(key); 35 | if(cacheItem != null) 36 | { 37 | return Json(JsonConvert.DeserializeObject(cacheItem)); 38 | } 39 | var entry = await _repository.GetAsync(key); 40 | if(entry == null) 41 | { 42 | return NotFound(); 43 | } 44 | return Json(entry.Value); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Depot.Services.Entries.Controllers 4 | { 5 | [Route("")] 6 | public class HomeController : Controller 7 | { 8 | [HttpGet] 9 | public IActionResult Get() 10 | { 11 | return Content("Welcome to the Entries Service!"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Depot.Services.Entries.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5050/tcp 9 | ENV ASPNETCORE_URLS http://*:5050 10 | ENV ASPNETCORE_ENVIRONMENT docker 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Dockerfile.development: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5050/tcp 9 | ENV ASPNETCORE_URLS http://*:5050 10 | ENV ASPNETCORE_ENVIRONMENT development 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Dockerfile.production: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY . /app 3 | WORKDIR /app 4 | 5 | RUN ["dotnet", "restore", "--source", "https://api.nuget.org/v3/index.json", "--source", "https://www.myget.org/F/netcoretour/api/v3/index.json", "--no-cache"] 6 | RUN ["dotnet", "build"] 7 | 8 | EXPOSE 5050/tcp 9 | ENV ASPNETCORE_URLS http://*:5050 10 | ENV ASPNETCORE_ENVIRONMENT production 11 | 12 | ENTRYPOINT ["dotnet", "run"] -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Framework/MongoConfigurator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using MongoDB.Bson; 3 | using MongoDB.Bson.Serialization.Conventions; 4 | 5 | namespace Depot.Services.Entries.Framework 6 | { 7 | public class MongoConfigurator 8 | { 9 | private static bool _initialized; 10 | public static void Initialize() 11 | { 12 | if (_initialized) 13 | return; 14 | 15 | RegisterConventions(); 16 | } 17 | 18 | private static void RegisterConventions() 19 | { 20 | ConventionRegistry.Register("MyConventions", new MongoConvention(), x => true); 21 | _initialized = true; 22 | } 23 | 24 | private class MongoConvention : IConventionPack 25 | { 26 | public IEnumerable Conventions => new List 27 | { 28 | new IgnoreExtraElementsConvention(true), 29 | new EnumRepresentationConvention(BsonType.String), 30 | new CamelCaseElementNameConvention() 31 | }; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Framework/MongoOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Services.Entries.Framework 2 | { 3 | public class MongoOptions 4 | { 5 | public string ConnectionString { get; set; } 6 | public string Database { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Framework/RabbitMqOptions.cs: -------------------------------------------------------------------------------- 1 | using RawRabbit.Configuration; 2 | 3 | namespace Depot.Services.Entries.Framework 4 | { 5 | public class RabbitMqOptions : RawRabbitConfiguration 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Framework/RedisOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Depot.Services.Entries.Framework 2 | { 3 | public class RedisOptions 4 | { 5 | public string ConnectionString { get; set; } 6 | public string Instance { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Handlers/CreateEntryHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | using Depot.Messages.Commands; 5 | using Depot.Messages.Events; 6 | using Depot.Services.Entries.Models; 7 | using Depot.Services.Entries.Repositories; 8 | using Microsoft.Extensions.Caching.Distributed; 9 | using Newtonsoft.Json; 10 | using RawRabbit; 11 | 12 | namespace Depot.Services.Entries.Handlers 13 | { 14 | public class CreateEntryHandler : ICommandHandler 15 | { 16 | 17 | private readonly IBusClient _busClient; 18 | private readonly IEntryRepository _repository; 19 | private readonly IDistributedCache _cache; 20 | 21 | public CreateEntryHandler(IBusClient busClient, IEntryRepository repository, 22 | IDistributedCache cache) 23 | { 24 | _busClient = busClient; 25 | _repository = repository; 26 | _cache = cache; 27 | } 28 | 29 | public async Task HandleAsync(CreateEntry command) 30 | { 31 | if(string.IsNullOrWhiteSpace(command.Key)) 32 | { 33 | await PublishError(command.Key, "Entry key can not be empty."); 34 | return; 35 | } 36 | var entry = await _repository.GetAsync(command.Key); 37 | if(entry != null) 38 | { 39 | await PublishError(command.Key, $"Entry with key: '{command.Key}' already exists."); 40 | return; 41 | } 42 | await _repository.AddAsync(new Entry(command.Key, command.Value)); 43 | await _cache.SetStringAsync(command.Key, JsonConvert.SerializeObject(command.Value), 44 | new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(10))); 45 | Console.WriteLine($"Created a new entry with key: '{command.Key}'."); 46 | await _busClient.PublishAsync(new EntryCreated(command.Key)); 47 | } 48 | 49 | private async Task PublishError(string key, string reason) 50 | { 51 | Console.WriteLine(reason); 52 | await _busClient.PublishAsync(new CreateEntryRejected(key, reason)); 53 | 54 | return; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Models/Entry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Depot.Services.Entries.Models 4 | { 5 | public class Entry 6 | { 7 | public string Key { get; protected set; } 8 | public object Value { get; protected set; } 9 | public DateTime CreatedAt { get; protected set; } 10 | 11 | protected Entry() 12 | { 13 | } 14 | 15 | public Entry(string key, object value) 16 | { 17 | Key = key.Trim().ToLowerInvariant(); 18 | Value = value; 19 | CreatedAt = DateTime.UtcNow; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | 9 | namespace Depot.Services.Entries 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | var host = new WebHostBuilder() 16 | .UseKestrel() 17 | .UseContentRoot(Directory.GetCurrentDirectory()) 18 | .UseIISIntegration() 19 | .UseStartup() 20 | .UseUrls("http://*:5050") 21 | .Build(); 22 | 23 | host.Run(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Repositories/EntryRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Depot.Services.Entries.Models; 6 | 7 | namespace Depot.Services.Entries.Repositories 8 | { 9 | public class EntryRepository : IEntryRepository 10 | { 11 | private static readonly ICollection _entries = new List(); 12 | 13 | public async Task GetAsync(string key) 14 | => await Task.FromResult(_entries.SingleOrDefault(x 15 | => x.Key == key.Trim().ToLowerInvariant())); 16 | 17 | public async Task> BrowseAsync() 18 | => await Task.FromResult(_entries); 19 | 20 | public async Task AddAsync(Entry entry) 21 | { 22 | _entries.Add(entry); 23 | await Task.CompletedTask; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Repositories/IEntryRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Depot.Services.Entries.Models; 4 | 5 | namespace Depot.Services.Entries.Repositories 6 | { 7 | public interface IEntryRepository 8 | { 9 | Task GetAsync(string key); 10 | Task> BrowseAsync(); 11 | Task AddAsync(Entry entry); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Repositories/MongoEntryRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Depot.Services.Entries.Models; 4 | using MongoDB.Driver; 5 | using MongoDB.Driver.Linq; 6 | 7 | namespace Depot.Services.Entries.Repositories 8 | { 9 | public class MongoEntryRepository : IEntryRepository 10 | { 11 | private readonly IMongoDatabase _database; 12 | 13 | public MongoEntryRepository(IMongoDatabase database) 14 | { 15 | _database = database; 16 | } 17 | 18 | public async Task GetAsync(string key) 19 | => await Entries.AsQueryable() 20 | .FirstOrDefaultAsync(x => x.Key == key); 21 | 22 | public async Task> BrowseAsync() 23 | => await Entries.AsQueryable().ToListAsync(); 24 | 25 | public async Task AddAsync(Entry entry) 26 | => await Entries.InsertOneAsync(entry); 27 | 28 | private IMongoCollection Entries 29 | => _database.GetCollection("Entries"); 30 | } 31 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Autofac; 6 | using Autofac.Extensions.DependencyInjection; 7 | using Depot.Messages.Commands; 8 | using Depot.Services.Entries.Framework; 9 | using Depot.Services.Entries.Handlers; 10 | using Depot.Services.Entries.Repositories; 11 | using Microsoft.AspNetCore.Builder; 12 | using Microsoft.AspNetCore.Hosting; 13 | using Microsoft.Extensions.Configuration; 14 | using Microsoft.Extensions.DependencyInjection; 15 | using Microsoft.Extensions.Logging; 16 | using MongoDB.Driver; 17 | using Newtonsoft.Json; 18 | using RawRabbit; 19 | using RawRabbit.vNext; 20 | 21 | namespace Depot.Services.Entries 22 | { 23 | public class Startup 24 | { 25 | public IConfigurationRoot Configuration { get; } 26 | public IContainer Container { get; set; } 27 | 28 | public Startup(IHostingEnvironment env) 29 | { 30 | var builder = new ConfigurationBuilder() 31 | .SetBasePath(env.ContentRootPath) 32 | .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 33 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 34 | .AddEnvironmentVariables(); 35 | Configuration = builder.Build(); 36 | } 37 | 38 | // This method gets called by the runtime. Use this method to add services to the container. 39 | public IServiceProvider ConfigureServices(IServiceCollection services) 40 | { 41 | // Add framework services. 42 | services.AddMvc() 43 | .AddJsonOptions(x => x.SerializerSettings.Formatting = Formatting.Indented); 44 | // services.AddScoped(); 45 | ConfigureRabbitMqServices(services); 46 | ConfigureRedis(services); 47 | 48 | var builder = new ContainerBuilder(); 49 | builder.Populate(services); 50 | ConfigureMongoDb(builder); 51 | Container = builder.Build(); 52 | 53 | return new AutofacServiceProvider(Container); 54 | } 55 | 56 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 57 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 58 | { 59 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 60 | loggerFactory.AddDebug(); 61 | 62 | ConfigureRabbitMqSubscriptions(app); 63 | MongoConfigurator.Initialize(); 64 | app.UseMvc(); 65 | } 66 | 67 | private void ConfigureRabbitMqServices(IServiceCollection services) 68 | { 69 | var rabbitMqOptions = new RabbitMqOptions(); 70 | var rabbitMqOptionsSection = Configuration.GetSection("rabbitmq"); 71 | rabbitMqOptionsSection.Bind(rabbitMqOptions); 72 | 73 | var rabbitMqClient = BusClientFactory.CreateDefault(rabbitMqOptions); 74 | services.Configure(rabbitMqOptionsSection); 75 | services.AddSingleton(_ => rabbitMqClient); 76 | services.AddScoped, CreateEntryHandler>(); 77 | } 78 | 79 | private void ConfigureRabbitMqSubscriptions(IApplicationBuilder app) 80 | { 81 | var rabbitMqClient = app.ApplicationServices.GetService(); 82 | var createEntryHandler = app.ApplicationServices.GetService>(); 83 | rabbitMqClient.SubscribeAsync(async (msg, context) 84 | => await createEntryHandler.HandleAsync(msg)); 85 | } 86 | 87 | private void ConfigureMongoDb(ContainerBuilder builder) 88 | { 89 | var optionsSection = Configuration.GetSection("mongo"); 90 | var options = new MongoOptions(); 91 | optionsSection.Bind(options); 92 | builder.RegisterInstance(options).SingleInstance(); 93 | 94 | var mongoClient = new MongoClient(options.ConnectionString); 95 | builder.RegisterInstance(mongoClient.GetDatabase(options.Database)); 96 | builder.RegisterType() 97 | .As() 98 | .InstancePerLifetimeScope(); 99 | } 100 | 101 | private void ConfigureRedis(IServiceCollection services) 102 | { 103 | var optionsSection = Configuration.GetSection("redis"); 104 | var options = new RedisOptions(); 105 | optionsSection.Bind(options); 106 | services.Configure(optionsSection); 107 | 108 | services.AddDistributedRedisCache(x => 109 | { 110 | x.Configuration = options.ConnectionString; 111 | x.InstanceName = options.Instance; 112 | }); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Depot.Services.Entries/appsettings.development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Depot.Services.Entries/appsettings.docker.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "mongo": { 9 | "connectionString": "mongodb://mongo:27017", 10 | "database": "Depot" 11 | }, 12 | "rabbitmq": { 13 | "Username": "guest", 14 | "Password": "guest", 15 | "VirtualHost": "/", 16 | "Port": 5672, 17 | "Hostnames": [ "rabbitmq" ], 18 | "RequestTimeout": "00:00:10", 19 | "PublishConfirmTimeout": "00:00:01", 20 | "RecoveryInterval": "00:00:10", 21 | "PersistentDeliveryMode": true, 22 | "AutoCloseConnection": true, 23 | "AutomaticRecovery": true, 24 | "TopologyRecovery": true, 25 | "Exchange": { 26 | "Durable": true, 27 | "AutoDelete": true, 28 | "Type": "Topic" 29 | }, 30 | "Queue": { 31 | "AutoDelete": true, 32 | "Durable": true, 33 | "Exclusive": true 34 | } 35 | }, 36 | "redis": { 37 | "connectionString": "redis", 38 | "instance": "" 39 | } 40 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "mongo": { 9 | "connectionString": "mongodb://localhost:27017", 10 | "database": "Depot" 11 | }, 12 | "rabbitmq": { 13 | "Username": "guest", 14 | "Password": "guest", 15 | "VirtualHost": "/", 16 | "Port": 5672, 17 | "Hostnames": [ "localhost" ], 18 | "RequestTimeout": "00:00:10", 19 | "PublishConfirmTimeout": "00:00:01", 20 | "RecoveryInterval": "00:00:10", 21 | "PersistentDeliveryMode": true, 22 | "AutoCloseConnection": true, 23 | "AutomaticRecovery": true, 24 | "TopologyRecovery": true, 25 | "Exchange": { 26 | "Durable": true, 27 | "AutoDelete": true, 28 | "Type": "Topic" 29 | }, 30 | "Queue": { 31 | "AutoDelete": true, 32 | "Durable": true, 33 | "Exclusive": true 34 | } 35 | }, 36 | "redis": { 37 | "connectionString": "127.0.0.1", 38 | "instance": "" 39 | } 40 | } -------------------------------------------------------------------------------- /src/Depot.Services.Entries/appsettings.production.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "mongo": { 9 | "connectionString": "mongodb://localhost:27017", 10 | "database": "Depot" 11 | }, 12 | "rabbitmq": { 13 | "Username": "guest", 14 | "Password": "guest", 15 | "VirtualHost": "/", 16 | "Port": 5672, 17 | "Hostnames": [ "localhost" ], 18 | "RequestTimeout": "00:00:10", 19 | "PublishConfirmTimeout": "00:00:01", 20 | "RecoveryInterval": "00:00:10", 21 | "PersistentDeliveryMode": true, 22 | "AutoCloseConnection": true, 23 | "AutomaticRecovery": true, 24 | "TopologyRecovery": true, 25 | "Exchange": { 26 | "Durable": true, 27 | "AutoDelete": true, 28 | "Type": "Topic" 29 | }, 30 | "Queue": { 31 | "AutoDelete": true, 32 | "Durable": true, 33 | "Exclusive": true 34 | } 35 | }, 36 | "redis": { 37 | "connectionString": "127.0.0.1", 38 | "instance": "" 39 | } 40 | } -------------------------------------------------------------------------------- /tests/Depot.Tests.EndToEnd/Controllers/EntriesControllerTests.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.Http; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Depot.Api; 6 | using Depot.Messages.Commands; 7 | using FluentAssertions; 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.AspNetCore.TestHost; 10 | using Newtonsoft.Json; 11 | using Xunit; 12 | 13 | namespace Depot.Tests.EndToEnd.Controllers 14 | { 15 | public class EntriesControllerTests 16 | { 17 | protected readonly TestServer Server; 18 | protected readonly HttpClient Client; 19 | 20 | public EntriesControllerTests() 21 | { 22 | Server = new TestServer(new WebHostBuilder() 23 | .UseStartup()); 24 | Client = Server.CreateClient(); 25 | } 26 | 27 | [Fact] 28 | public async Task given_unique_key_entry_should_be_created() 29 | { 30 | //Arrange 31 | var command = new CreateEntry 32 | { 33 | Key = "test", 34 | Value = "test-entry" 35 | }; 36 | var payload = GetPayload(command); 37 | 38 | //Act 39 | var response = await Client.PostAsync("entries", payload); 40 | 41 | //Assert 42 | response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Accepted); 43 | } 44 | 45 | protected static StringContent GetPayload(object data) 46 | { 47 | var json = JsonConvert.SerializeObject(data); 48 | 49 | return new StringContent(json, Encoding.UTF8, "application/json"); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /tests/Depot.Tests.EndToEnd/Depot.Tests.EndToEnd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/Depot.Tests.EndToEnd/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "rabbitmq": { 9 | "Username": "guest", 10 | "Password": "guest", 11 | "VirtualHost": "/", 12 | "Port": 5672, 13 | "Hostnames": [ "localhost" ], 14 | "RequestTimeout": "00:00:10", 15 | "PublishConfirmTimeout": "00:00:01", 16 | "RecoveryInterval": "00:00:10", 17 | "PersistentDeliveryMode": true, 18 | "AutoCloseConnection": true, 19 | "AutomaticRecovery": true, 20 | "TopologyRecovery": true, 21 | "Exchange": { 22 | "Durable": true, 23 | "AutoDelete": true, 24 | "Type": "Topic" 25 | }, 26 | "Queue": { 27 | "AutoDelete": true, 28 | "Durable": true, 29 | "Exclusive": true 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /tests/Depot.Tests/Depot.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/Depot.Tests/Handlers/CreateEntryHandlerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Depot.Messages.Commands; 4 | using Depot.Messages.Events; 5 | using Depot.Services.Entries.Handlers; 6 | using Depot.Services.Entries.Models; 7 | using Depot.Services.Entries.Repositories; 8 | using Microsoft.Extensions.Caching.Distributed; 9 | using Moq; 10 | using RawRabbit; 11 | using RawRabbit.Configuration.Publish; 12 | using Xunit; 13 | 14 | namespace Depot.Tests.Handlers 15 | { 16 | public class CreateEntryHandlerTests 17 | { 18 | public CreateEntryHandler Handler; 19 | public Mock BusClientMock; 20 | public Mock EntryRepositoryMock; 21 | public Mock CacheMock; 22 | public CreateEntry Command; 23 | 24 | public CreateEntryHandlerTests() 25 | { 26 | BusClientMock = new Mock(); 27 | EntryRepositoryMock = new Mock(); 28 | CacheMock = new Mock(); 29 | Handler = new CreateEntryHandler(BusClientMock.Object, 30 | EntryRepositoryMock.Object, CacheMock.Object); 31 | } 32 | 33 | [Fact] 34 | public async Task Test() 35 | { 36 | //Arrange 37 | Command = new CreateEntry 38 | { 39 | Key = "test", 40 | Value = "test-value" 41 | }; 42 | 43 | //Act 44 | await Handler.HandleAsync(Command); 45 | 46 | //Assert 47 | EntryRepositoryMock.Verify(x => x.AddAsync(It.IsAny()), Times.Once()); 48 | BusClientMock.Verify(x => x.PublishAsync(It.IsAny(), It.IsAny(), 49 | It.IsAny>()), Times.Once()); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /travis-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd scripts 3 | ./dotnet-restore.sh 4 | ./dotnet-build.sh 5 | 6 | --------------------------------------------------------------------------------