├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Dockerfile ├── README.md ├── circle.yml ├── global.json ├── src └── WebAPIApplication │ ├── .gitignore │ ├── .vscode │ ├── launch.json │ └── tasks.json │ ├── Controllers │ ├── PessoasController.cs │ └── ValuesController.cs │ ├── Migrations │ ├── 20161129014403_MigracaoInicial.Designer.cs │ ├── 20161129014403_MigracaoInicial.cs │ └── DataContextModelSnapshot.cs │ ├── Models │ ├── DataContext.cs │ └── Pessoa.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── README.md │ ├── Startup.cs │ ├── appsettings.json │ ├── project.json │ └── web.config └── test └── UnitTest ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Class1.cs ├── Configuration ├── BaseIntegrationTest.cs ├── BaseTestCollection.cs └── BaseTestFixture.cs ├── Controllers ├── PessoasControllerIntegrationTest.cs └── ValuesControllerIntegarationTest.cs ├── appsettings.json ├── project.json └── xunit.runner.json /.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 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (web)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}\\src\\WebAPIApplication\\bin\\Debug\\netcoreapp1.1\\WebAPIApplication.dll", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "stopAtEntry": false, 13 | "internalConsoleOptions": "openOnSessionStart", 14 | "launchBrowser": { 15 | "enabled": true, 16 | "args": "${auto-detect-url}", 17 | "windows": { 18 | "command": "cmd.exe", 19 | "args": "/C start ${auto-detect-url}" 20 | }, 21 | "osx": { 22 | "command": "open" 23 | }, 24 | "linux": { 25 | "command": "xdg-open" 26 | } 27 | }, 28 | "env": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | }, 31 | "sourceFileMap": { 32 | "/Views": "${workspaceRoot}/Views" 33 | } 34 | }, 35 | { 36 | "name": ".NET Core Attach", 37 | "type": "coreclr", 38 | "request": "attach", 39 | "processId": "${command.pickProcess}" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [ 10 | "${workspaceRoot}\\src\\WebAPIApplication\\project.json" 11 | ], 12 | "isBuildCommand": true, 13 | "problemMatcher": "$msCompile" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/aspnetcore 2 | 3 | WORKDIR /app 4 | 5 | COPY src/WebAPIApplication/bin/Release/netcoreapp1.1/publish . 6 | 7 | ENTRYPOINT ["dotnet", "WebAPIApplication.dll"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Workshop: Exemplo de Aplicação ASP.NET Core 1.1 (Web API) com EFCore acessando SqlServer rodando no Linux 2 | 3 | ##.NET Core e Node.js 4 | [Instale o Node.js](https://nodejs.org/en/) 5 | 6 | [Instale o .NET Core](http://www.dot.net) 7 | 8 | ##Yoeman 9 | Para instalar o Yoeman e o Scaffolding do ASP.NET Core (o bower é requerido pelo Scaffolding), utilize o NPM, através dos seguintes comandos: 10 | 11 | `npm i -g bower` 12 | 13 | `npm i -g yo` 14 | 15 | `npm i -g generator-aspnet` 16 | 17 | 18 | Para criar o projeto do zero, você pode utilizar o comando `yo` e seguir as instruções informadas no terminal. 19 | 20 | Neste exemplo utilizamos os projetos: `Web API Application` e `Unit test project (xUnit.net)` 21 | 22 | ## Migrations 23 | Para criar o primeiro pacote do migration, execute o comando abaixo: 24 | 25 | `dotnet ef migrations add MigracaoInicial` 26 | 27 | ## Docker - Container SqlServer no Linux 28 | [Docker](https://www.docker.com/products/docker) 29 | 30 | Para subir a imagem do container SqlServer (linux), execute o comando abaixo: 31 | 32 | `sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Workshop@123' -p 1433:1433 -d microsoft/mssql-server-Linux` 33 | 34 | ## Visual Studio Code 35 | [Visual Studio Code](https://code.visualstudio.com/) 36 | 37 | ## Visual Studio Code Extensions 38 | - C# 39 | - C# Extensions 40 | - vscode-icons 41 | 42 | ##CircleCI 43 | Integração contínua com [CircleCI](http://circleci.com) 44 | 45 | ## Material desenvolvido pelos participantes do curso 46 | - http://codefc.com.br/workshop-asp-net-core/ 47 | - http://codefc.com.br/instalando-o-visual-studio-code/ 48 | - http://joseotavio.com/2016/12/01/workshop-net-core-efcore-azure-circleci-xunit.html 49 | - https://www.youtube.com/watch?v=jNPM4FDdXjw&feature=youtu.be 50 | - https://github.com/andreluizsecco/EFCore.Demo -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | environment: 5 | ConnectionStrings__DefaultConnection: "Server=localhost;Database=WorkshopAspCore_Test;User Id=sa;Password=Workshop@123;MultipleActiveResultSets=true" 6 | post: 7 | - sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' 8 | - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 9 | - sudo apt-get update 10 | - sudo apt-get install dotnet-dev-1.0.0-preview2.1-003177 11 | 12 | dependencies: 13 | override: 14 | - dotnet restore 15 | 16 | database: 17 | override: 18 | - docker run -d -p 1433:1433 -e SA_PASSWORD=Workshop@123 -e ACCEPT_EULA=Y --name mssql microsoft/mssql-server-linux 19 | - docker inspect mssql 20 | 21 | test: 22 | pre: 23 | - dotnet build test/UnitTest/project.json 24 | override: 25 | - dotnet test test/UnitTest/project.json 26 | post: 27 | - dotnet publish --configuration Release src/WebAPIApplication/project.json 28 | - cp -R src/WebAPIApplication/bin/Release/netcoreapp1.1/ $CIRCLE_ARTIFACTS/ 29 | 30 | deployment: 31 | master: 32 | branch: master 33 | commands: 34 | - docker build -t workshop-aspnetcore-circleci-azure . 35 | - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASSWORD 36 | - docker tag workshop-aspnetcore-circleci-azure $DOCKER_USER/workshop-aspnetcore-circleci-azure:latest 37 | - docker push $DOCKER_USER/workshop-aspnetcore-circleci-azure 38 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ], 3 | "sdk": { 4 | "version": "1.0.0-preview2-003131" 5 | } 6 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/.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 | # Cake - Uncomment if you are using it 268 | # tools/ 269 | -------------------------------------------------------------------------------- /src/WebAPIApplication/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (web)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.1\\WebAPIApplication.dll", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "stopAtEntry": false, 13 | "internalConsoleOptions": "openOnSessionStart", 14 | "launchBrowser": { 15 | "enabled": true, 16 | "args": "${auto-detect-url}", 17 | "windows": { 18 | "command": "cmd.exe", 19 | "args": "/C start ${auto-detect-url}" 20 | }, 21 | "osx": { 22 | "command": "open" 23 | }, 24 | "linux": { 25 | "command": "xdg-open" 26 | } 27 | }, 28 | "env": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | }, 31 | "sourceFileMap": { 32 | "/Views": "${workspaceRoot}/Views" 33 | } 34 | }, 35 | { 36 | "name": ".NET Core Attach", 37 | "type": "coreclr", 38 | "request": "attach", 39 | "processId": "${command.pickProcess}" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [ 10 | "${workspaceRoot}\\project.json" 11 | ], 12 | "isBuildCommand": true, 13 | "problemMatcher": "$msCompile" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/Controllers/PessoasController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.EntityFrameworkCore; 4 | using System.Linq; 5 | using System.Net; 6 | 7 | namespace WebAPIApplication 8 | { 9 | [Route("api/pessoas")] 10 | public class PessoasController : Controller 11 | { 12 | private readonly DataContext _dataContext; 13 | 14 | public PessoasController(DataContext dataContext) 15 | { 16 | _dataContext = dataContext; 17 | } 18 | 19 | [HttpGet] 20 | public async Task ObterPessoas() 21 | { 22 | var pessoas = await _dataContext.Pessoas.ToListAsync(); 23 | return Json(pessoas); 24 | } 25 | 26 | [HttpPost] 27 | public async Task CriaPessoa([FromBody]Pessoa modelo) 28 | { 29 | await _dataContext.Pessoas.AddAsync(modelo); 30 | await _dataContext.SaveChangesAsync(); 31 | 32 | return Json(modelo); 33 | } 34 | 35 | [HttpGet("{id}")] 36 | public async Task ObterPessoa(int id) 37 | { 38 | var pessoa = await _dataContext.Pessoas.SingleOrDefaultAsync(x=> x.Id == id); 39 | 40 | if(pessoa == null) 41 | return NotFound(); 42 | 43 | return Json(pessoa); 44 | } 45 | 46 | [HttpPut("{id}")] 47 | public async Task AtualizaPessoa(int id, [FromBody]Pessoa modelo) 48 | { 49 | var pessoa = await _dataContext.Pessoas.SingleOrDefaultAsync(x=> x.Id == id); 50 | 51 | if(pessoa == null) 52 | return NotFound(); 53 | 54 | pessoa.Nome = modelo.Nome; 55 | pessoa.Twitter = modelo.Twitter; 56 | 57 | await _dataContext.SaveChangesAsync(); 58 | 59 | return Json(pessoa); 60 | } 61 | 62 | [HttpDelete("{id}")] 63 | public async Task RemovePessoa(int id) 64 | { 65 | var pessoa = await _dataContext.Pessoas.SingleOrDefaultAsync(x=> x.Id == id); 66 | 67 | if(pessoa == null) 68 | return NotFound(); 69 | 70 | _dataContext.Pessoas.Remove(pessoa); 71 | 72 | await _dataContext.SaveChangesAsync(); 73 | 74 | return StatusCode((int)HttpStatusCode.OK); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace WebAPIApplication.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "@rodrigokono", "@rsantosdev", "@ricardoserradas", "@lucasromao" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Migrations/20161129014403_MigracaoInicial.Designer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using WebAPIApplication; 7 | 8 | namespace WebAPIApplication.Migrations 9 | { 10 | [DbContext(typeof(DataContext))] 11 | [Migration("20161129014403_MigracaoInicial")] 12 | partial class MigracaoInicial 13 | { 14 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 15 | { 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") 18 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 19 | 20 | modelBuilder.Entity("WebAPIApplication.Pessoa", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd(); 24 | 25 | b.Property("Nome"); 26 | 27 | b.Property("Twitter"); 28 | 29 | b.HasKey("Id"); 30 | 31 | b.ToTable("Pessoas"); 32 | }); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Migrations/20161129014403_MigracaoInicial.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore.Migrations; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | 6 | namespace WebAPIApplication.Migrations 7 | { 8 | public partial class MigracaoInicial : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Pessoas", 14 | columns: table => new 15 | { 16 | Id = table.Column(nullable: false) 17 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 18 | Nome = table.Column(nullable: true), 19 | Twitter = table.Column(nullable: true) 20 | }, 21 | constraints: table => 22 | { 23 | table.PrimaryKey("PK_Pessoas", x => x.Id); 24 | }); 25 | } 26 | 27 | protected override void Down(MigrationBuilder migrationBuilder) 28 | { 29 | migrationBuilder.DropTable( 30 | name: "Pessoas"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Migrations/DataContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using WebAPIApplication; 7 | 8 | namespace WebAPIApplication.Migrations 9 | { 10 | [DbContext(typeof(DataContext))] 11 | partial class DataContextModelSnapshot : ModelSnapshot 12 | { 13 | protected override void BuildModel(ModelBuilder modelBuilder) 14 | { 15 | modelBuilder 16 | .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") 17 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 18 | 19 | modelBuilder.Entity("WebAPIApplication.Pessoa", b => 20 | { 21 | b.Property("Id") 22 | .ValueGeneratedOnAdd(); 23 | 24 | b.Property("Nome"); 25 | 26 | b.Property("Twitter"); 27 | 28 | b.HasKey("Id"); 29 | 30 | b.ToTable("Pessoas"); 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Models/DataContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace WebAPIApplication { 4 | public class DataContext : DbContext 5 | { 6 | public DataContext(DbContextOptions options) : base(options) 7 | { 8 | 9 | } 10 | 11 | public DbSet Pessoas { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/Models/Pessoa.cs: -------------------------------------------------------------------------------- 1 | namespace WebAPIApplication { 2 | public class Pessoa 3 | { 4 | public int Id { get; set; } 5 | public string Nome { get; set; } 6 | public string Twitter { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/WebAPIApplication/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.Hosting; 7 | using Microsoft.AspNetCore.Builder; 8 | using Microsoft.Extensions.Configuration; 9 | 10 | namespace WebAPIApplication 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | var config = new ConfigurationBuilder() 17 | .AddCommandLine(args) 18 | .AddEnvironmentVariables(prefix: "ASPNETCORE_") 19 | .Build(); 20 | 21 | var host = new WebHostBuilder() 22 | .UseConfiguration(config) 23 | .UseKestrel() 24 | .UseContentRoot(Directory.GetCurrentDirectory()) 25 | .UseIISIntegration() 26 | .UseStartup() 27 | .Build(); 28 | 29 | host.Run(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:1479/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "WebAPIApplication": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "http://localhost:5000/api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/WebAPIApplication/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to ASP.NET Core 2 | 3 | We've made some big updates in this release, so it’s **important** that you spend a few minutes to learn what’s new. 4 | 5 | You've created a new ASP.NET Core project. [Learn what's new](https://go.microsoft.com/fwlink/?LinkId=518016) 6 | 7 | ## This application consists of: 8 | 9 | * Sample pages using ASP.NET Core MVC 10 | * [Bower](https://go.microsoft.com/fwlink/?LinkId=518004) for managing client-side libraries 11 | * Theming using [Bootstrap](https://go.microsoft.com/fwlink/?LinkID=398939) 12 | 13 | ## How to 14 | 15 | * [Add a Controller and View](https://go.microsoft.com/fwlink/?LinkID=398600) 16 | * [Add an appsetting in config and access it in app.](https://go.microsoft.com/fwlink/?LinkID=699562) 17 | * [Manage User Secrets using Secret Manager.](https://go.microsoft.com/fwlink/?LinkId=699315) 18 | * [Use logging to log a message.](https://go.microsoft.com/fwlink/?LinkId=699316) 19 | * [Add packages using NuGet.](https://go.microsoft.com/fwlink/?LinkId=699317) 20 | * [Add client packages using Bower.](https://go.microsoft.com/fwlink/?LinkId=699318) 21 | * [Target development, staging or production environment.](https://go.microsoft.com/fwlink/?LinkId=699319) 22 | 23 | ## Overview 24 | 25 | * [Conceptual overview of what is ASP.NET Core](https://go.microsoft.com/fwlink/?LinkId=518008) 26 | * [Fundamentals of ASP.NET Core such as Startup and middleware.](https://go.microsoft.com/fwlink/?LinkId=699320) 27 | * [Working with Data](https://go.microsoft.com/fwlink/?LinkId=398602) 28 | * [Security](https://go.microsoft.com/fwlink/?LinkId=398603) 29 | * [Client side development](https://go.microsoft.com/fwlink/?LinkID=699321) 30 | * [Develop on different platforms](https://go.microsoft.com/fwlink/?LinkID=699322) 31 | * [Read more on the documentation site](https://go.microsoft.com/fwlink/?LinkID=699323) 32 | 33 | ## Run & Deploy 34 | 35 | * [Run your app](https://go.microsoft.com/fwlink/?LinkID=517851) 36 | * [Run tools such as EF migrations and more](https://go.microsoft.com/fwlink/?LinkID=517853) 37 | * [Publish to Microsoft Azure Web Apps](https://go.microsoft.com/fwlink/?LinkID=398609) 38 | 39 | We would love to hear your [feedback](https://go.microsoft.com/fwlink/?LinkId=518015) 40 | -------------------------------------------------------------------------------- /src/WebAPIApplication/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.EntityFrameworkCore; 11 | 12 | namespace WebAPIApplication 13 | { 14 | public class Startup 15 | { 16 | public Startup(IHostingEnvironment env) 17 | { 18 | var builder = new ConfigurationBuilder() 19 | .SetBasePath(env.ContentRootPath) 20 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 21 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 22 | .AddEnvironmentVariables(); 23 | Configuration = builder.Build(); 24 | } 25 | 26 | public IConfigurationRoot Configuration { get; } 27 | 28 | // This method gets called by the runtime. Use this method to add services to the container. 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | // Add framework services. 32 | services.AddMvc(); 33 | 34 | services.AddDbContext(options => 35 | options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) 36 | ); 37 | } 38 | 39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 41 | { 42 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 43 | loggerFactory.AddDebug(); 44 | 45 | app.UseMvc(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/WebAPIApplication/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=127.0.0.1;Database=WorkshopAspCore_Test;User Id=sa;Password=Workshop@123;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "IncludeScopes": false, 7 | "LogLevel": { 8 | "Default": "Debug", 9 | "System": "Information", 10 | "Microsoft": "Information" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/WebAPIApplication/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.NETCore.App": { 4 | "version": "1.1.0", 5 | "type": "platform" 6 | }, 7 | "Microsoft.AspNetCore.Mvc": "1.1.0", 8 | "Microsoft.AspNetCore.Routing": "1.1.0", 9 | "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", 10 | "Microsoft.AspNetCore.Server.Kestrel": "1.1.0", 11 | "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0", 12 | "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0", 13 | "Microsoft.Extensions.Configuration.Json": "1.1.0", 14 | "Microsoft.Extensions.Configuration.CommandLine": "1.1.0", 15 | "Microsoft.Extensions.Logging": "1.1.0", 16 | "Microsoft.Extensions.Logging.Console": "1.1.0", 17 | "Microsoft.Extensions.Logging.Debug": "1.1.0", 18 | "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", 19 | 20 | "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", 21 | "Microsoft.EntityFrameworkCore.Tools": { 22 | "version": "1.1.0-preview4-final", 23 | "type": "build" 24 | } 25 | }, 26 | 27 | "tools": { 28 | "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", 29 | "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final" 30 | }, 31 | 32 | "frameworks": { 33 | "netcoreapp1.1": { 34 | "imports": [ 35 | "dotnet5.6", 36 | "portable-net45+win8" 37 | ] 38 | } 39 | }, 40 | 41 | "buildOptions": { 42 | "emitEntryPoint": true, 43 | "preserveCompilationContext": true 44 | }, 45 | 46 | "runtimeOptions": { 47 | "configProperties": { 48 | "System.GC.Server": true 49 | } 50 | }, 51 | 52 | "publishOptions": { 53 | "include": [ 54 | "wwwroot", 55 | "**/*.cshtml", 56 | "appsettings.json", 57 | "web.config" 58 | ] 59 | }, 60 | 61 | "scripts": { 62 | "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 63 | }, 64 | 65 | "tooling": { 66 | "defaultNamespace": "WebAPIApplication" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/WebAPIApplication/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/UnitTest/.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 | # Cake - Uncomment if you are using it 268 | # tools/ 269 | -------------------------------------------------------------------------------- /test/UnitTest/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (console)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}/bin/Debug//", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "externalConsole": false, 13 | "stopAtEntry": false, 14 | "internalConsoleOptions": "openOnSessionStart" 15 | }, 16 | { 17 | "name": ".NET Core Attach", 18 | "type": "coreclr", 19 | "request": "attach", 20 | "processId": "${command.pickProcess}" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /test/UnitTest/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [ 10 | "" 11 | ], 12 | "isBuildCommand": true, 13 | "problemMatcher": "$msCompile" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /test/UnitTest/Class1.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace UnitTest 4 | { 5 | // see example explanation on xUnit.net website: 6 | // https://xunit.github.io/docs/getting-started-dotnet-core.html 7 | public class Class1 8 | { 9 | [Fact] 10 | public void PassingTest() 11 | { 12 | Assert.Equal(4, Add(2, 2)); 13 | } 14 | 15 | // [Fact] 16 | // public void FailingTest() 17 | // { 18 | // Assert.Equal(5, Add(2, 2)); 19 | // } 20 | 21 | int Add(int x, int y) 22 | { 23 | return x + y; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/UnitTest/Configuration/BaseIntegrationTest.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading.Tasks; 3 | using Microsoft.AspNetCore.TestHost; 4 | using Microsoft.EntityFrameworkCore; 5 | using WebAPIApplication; 6 | using Xunit; 7 | 8 | namespace UnitTest 9 | { 10 | [Collection("Base collection")] 11 | public abstract class BaseIntegrationTest 12 | { 13 | protected readonly TestServer Server; 14 | protected readonly HttpClient Client; 15 | protected readonly DataContext TestDataContext; 16 | 17 | protected BaseTestFixture Fixture { get; } 18 | 19 | protected BaseIntegrationTest(BaseTestFixture fixture) 20 | { 21 | Fixture = fixture; 22 | 23 | TestDataContext = fixture.TestDataContext; 24 | Server = fixture.Server; 25 | Client = fixture.Client; 26 | 27 | ClearDb().Wait(); 28 | } 29 | 30 | private async Task ClearDb() 31 | { 32 | var commands = new[] 33 | { 34 | "EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'", 35 | "EXEC sp_MSForEachTable 'DELETE FROM ?'", 36 | "EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'" 37 | }; 38 | 39 | await TestDataContext.Database.OpenConnectionAsync(); 40 | 41 | foreach (var command in commands) 42 | { 43 | await TestDataContext.Database.ExecuteSqlCommandAsync(command); 44 | } 45 | 46 | TestDataContext.Database.CloseConnection(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /test/UnitTest/Configuration/BaseTestCollection.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace UnitTest 4 | { 5 | [CollectionDefinition("Base collection")] 6 | public abstract class BaseTestCollection : ICollectionFixture 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /test/UnitTest/Configuration/BaseTestFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.AspNetCore.TestHost; 5 | using Microsoft.EntityFrameworkCore; 6 | using Microsoft.Extensions.Configuration; 7 | using WebAPIApplication; 8 | 9 | namespace UnitTest 10 | { 11 | public class BaseTestFixture : IDisposable 12 | { 13 | public readonly TestServer Server; 14 | public readonly HttpClient Client; 15 | public readonly DataContext TestDataContext; 16 | public readonly IConfigurationRoot Configuration; 17 | 18 | public BaseTestFixture() 19 | { 20 | var envName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); 21 | 22 | var builder = new ConfigurationBuilder() 23 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 24 | .AddJsonFile($"appsettings.{envName}.json", optional: true) 25 | .AddEnvironmentVariables(); 26 | 27 | Configuration = builder.Build(); 28 | 29 | var opts = new DbContextOptionsBuilder(); 30 | opts.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); 31 | TestDataContext = new DataContext(opts.Options); 32 | SetupDatabase(); 33 | 34 | Server = new TestServer(new WebHostBuilder().UseStartup()); 35 | Client = Server.CreateClient(); 36 | } 37 | 38 | private void SetupDatabase() 39 | { 40 | try 41 | { 42 | TestDataContext.Database.EnsureCreated(); 43 | TestDataContext.Database.Migrate(); 44 | } 45 | catch (Exception) 46 | { 47 | //TODO: Add a better logging 48 | // Does nothing 49 | } 50 | } 51 | 52 | public void Dispose() 53 | { 54 | TestDataContext.Dispose(); 55 | Client.Dispose(); 56 | Server.Dispose(); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /test/UnitTest/Controllers/PessoasControllerIntegrationTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Newtonsoft.Json; 4 | using WebAPIApplication; 5 | using Xunit; 6 | using System.Net.Http; 7 | using System.Text; 8 | using System.Net; 9 | 10 | namespace UnitTest 11 | { 12 | public class PessoasControllerIntegrationTest : BaseIntegrationTest 13 | { 14 | private const string BaseUrl = "/api/pessoas"; 15 | public PessoasControllerIntegrationTest(BaseTestFixture fixture) : base(fixture) 16 | { 17 | } 18 | 19 | [Fact] 20 | public async Task DeveRetornarListaDePessoasVazia() 21 | { 22 | var response = await Client.GetAsync(BaseUrl); 23 | response.EnsureSuccessStatusCode(); 24 | 25 | var responseString = await response.Content.ReadAsStringAsync(); 26 | var data = JsonConvert.DeserializeObject>(responseString); 27 | 28 | Assert.Equal(data.Count, 0); 29 | } 30 | 31 | [Fact] 32 | public async Task DeveRetornarListaDePessoas() 33 | { 34 | var pessoa = new Pessoa 35 | { 36 | Nome = "Rafael dos Santos", 37 | Twitter = "rsantosdev" 38 | }; 39 | 40 | await TestDataContext.AddAsync(pessoa); 41 | await TestDataContext.SaveChangesAsync(); 42 | 43 | var response = await Client.GetAsync(BaseUrl); 44 | response.EnsureSuccessStatusCode(); 45 | 46 | var responseString = await response.Content.ReadAsStringAsync(); 47 | var data = JsonConvert.DeserializeObject>(responseString); 48 | 49 | Assert.Equal(data.Count, 1); 50 | Assert.Contains(data, x => x.Nome == pessoa.Nome); 51 | } 52 | 53 | [Fact] 54 | public async Task DeveAdicionarPessoa() 55 | { 56 | var pessoa = new Pessoa 57 | { 58 | Nome = "Rafael dos Santos", 59 | Twitter = "rsantosdev" 60 | }; 61 | 62 | var response = await Client.PostAsync(BaseUrl, new StringContent(JsonConvert.SerializeObject(pessoa), Encoding.UTF8, "application/json")); 63 | response.EnsureSuccessStatusCode(); 64 | 65 | var responseString = await response.Content.ReadAsStringAsync(); 66 | var data = JsonConvert.DeserializeObject(responseString); 67 | 68 | Assert.Equal(data.Nome, pessoa.Nome); 69 | } 70 | 71 | [Fact] 72 | public async Task DeveAtualizarPessoa() 73 | { 74 | var pessoa = new Pessoa 75 | { 76 | Nome = "Washington Borges", 77 | Twitter = "borgeston" 78 | }; 79 | 80 | await TestDataContext.AddAsync(pessoa); 81 | await TestDataContext.SaveChangesAsync(); 82 | 83 | var pessoaEditada = new Pessoa 84 | { 85 | Id = pessoa.Id, 86 | Nome = "Ton Borges", 87 | Twitter = "borgeston" 88 | }; 89 | 90 | var response = await Client.PutAsync($"{BaseUrl}/{pessoa.Id}", new StringContent(JsonConvert.SerializeObject(pessoaEditada), Encoding.UTF8, "application/json")); 91 | response.EnsureSuccessStatusCode(); 92 | 93 | var responseString = await response.Content.ReadAsStringAsync(); 94 | var data = JsonConvert.DeserializeObject(responseString); 95 | 96 | Assert.Equal(data.Nome, pessoaEditada.Nome); 97 | Assert.Equal(data.Twitter, pessoaEditada.Twitter); 98 | } 99 | 100 | [Fact] 101 | public async Task DeveDeletarPessoa() 102 | { 103 | var pessoa = new Pessoa 104 | { 105 | Nome = "Rafael dos Santos", 106 | Twitter = "rsantosdev" 107 | }; 108 | 109 | await TestDataContext.AddAsync(pessoa); 110 | await TestDataContext.SaveChangesAsync(); 111 | 112 | var response = await Client.DeleteAsync($"{BaseUrl}/{pessoa.Id}"); 113 | response.EnsureSuccessStatusCode(); 114 | 115 | response = await Client.GetAsync(BaseUrl); 116 | response.EnsureSuccessStatusCode(); 117 | 118 | var responseString = await response.Content.ReadAsStringAsync(); 119 | var data = JsonConvert.DeserializeObject>(responseString); 120 | 121 | Assert.Equal(data.Count, 0); 122 | } 123 | 124 | 125 | [Fact] 126 | public async Task DeveObterPessoa() 127 | { 128 | var pessoa = new Pessoa 129 | { 130 | Nome = "Washington Borges", 131 | Twitter = "borgeston" 132 | }; 133 | 134 | await TestDataContext.AddAsync(pessoa); 135 | await TestDataContext.SaveChangesAsync(); 136 | 137 | var response = await Client.GetAsync($"{BaseUrl}/{pessoa.Id}"); 138 | response.EnsureSuccessStatusCode(); 139 | 140 | var responseString = await response.Content.ReadAsStringAsync(); 141 | var data = JsonConvert.DeserializeObject(responseString); 142 | 143 | Assert.Equal(data.Id, pessoa.Id); 144 | Assert.Equal(data.Nome, pessoa.Nome); 145 | Assert.Equal(data.Twitter, pessoa.Twitter); 146 | } 147 | 148 | [Fact] 149 | public async Task DeveRetornaNaoEncontraoParaAtualizarPessoaComIdInvalido() 150 | { 151 | var pessoa = new Pessoa 152 | { 153 | Id = 0, 154 | Nome = "Ton Borges", 155 | Twitter = "borgeston" 156 | }; 157 | 158 | var response = await Client.PutAsync($"{BaseUrl}/{pessoa.Id}", new StringContent(JsonConvert.SerializeObject(pessoa), Encoding.UTF8, "application/json")); 159 | 160 | Assert.Equal(response.StatusCode, HttpStatusCode.NotFound); 161 | } 162 | 163 | [Fact] 164 | public async Task DeveRetornaNaoEncontraoParaDeletarPessoaComIdInvalido() 165 | { 166 | var pessoa = new Pessoa 167 | { 168 | Id = 0, 169 | Nome = "Ton Borges", 170 | Twitter = "borgeston" 171 | }; 172 | 173 | var response = await Client.DeleteAsync($"{BaseUrl}/{pessoa.Id}"); 174 | 175 | Assert.Equal(response.StatusCode, HttpStatusCode.NotFound); 176 | } 177 | 178 | [Fact] 179 | public async Task DeveRetornaNaoEncontraoParaObterPessoaComIdInvalido() 180 | { 181 | var pessoa = new Pessoa 182 | { 183 | Id = 0, 184 | Nome = "Ton Borges", 185 | Twitter = "borgeston" 186 | }; 187 | 188 | var response = await Client.GetAsync($"{BaseUrl}/{pessoa.Id}"); 189 | 190 | Assert.Equal(response.StatusCode, HttpStatusCode.NotFound); 191 | } 192 | } 193 | } -------------------------------------------------------------------------------- /test/UnitTest/Controllers/ValuesControllerIntegarationTest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using Newtonsoft.Json; 4 | using Xunit; 5 | 6 | namespace UnitTest 7 | { 8 | public class ValuesControllerIntegrationTest : BaseIntegrationTest 9 | { 10 | private const string BaseUrl = "/api/values"; 11 | 12 | public ValuesControllerIntegrationTest(BaseTestFixture fixture) : base(fixture) 13 | { 14 | } 15 | 16 | [Fact] 17 | public async Task GetShouldReturnValues() 18 | { 19 | var response = await Client.GetAsync(BaseUrl); 20 | response.EnsureSuccessStatusCode(); 21 | 22 | var dataString = await response.Content.ReadAsStringAsync(); 23 | var data = JsonConvert.DeserializeObject>(dataString); 24 | 25 | Assert.Equal(data.Count, 4); 26 | Assert.Contains(data, x => x == "@rsantosdev"); 27 | Assert.Contains(data, x => x == "@rodrigokono"); 28 | Assert.Contains(data, x => x == "@ricardoserradas"); 29 | Assert.Contains(data, x => x == "@lucasromao"); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /test/UnitTest/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=127.0.0.1;Database=WorkshopAspCore_Test;User Id=sa;Password=Workshop@123;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "IncludeScopes": false, 7 | "LogLevel": { 8 | "Default": "Debug", 9 | "System": "Information", 10 | "Microsoft": "Information" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/UnitTest/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "testRunner": "xunit", 4 | "dependencies": { 5 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 6 | "xunit": "2.2.0-beta4-build3444", 7 | "Microsoft.AspNetCore.TestHost": "1.1.0", 8 | "Microsoft.DotNet.InternalAbstractions": "1.0.0", 9 | "WebAPIApplication": { 10 | "target": "project" 11 | } 12 | }, 13 | "frameworks": { 14 | "netcoreapp1.1": { 15 | "dependencies": { 16 | "Microsoft.NETCore.App": { 17 | "type": "platform", 18 | "version": "1.1.0" 19 | } 20 | } 21 | } 22 | }, 23 | "buildOptions": { 24 | "debugType": "portable", 25 | "copyToOutput": { 26 | "include": [ 27 | "xunit.runner.json", 28 | "appsettings.json" 29 | ] 30 | } 31 | }, 32 | "tooling": { 33 | "defaultNamespace": "UnitTest" 34 | } 35 | } -------------------------------------------------------------------------------- /test/UnitTest/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "diagnosticMessages": false, 3 | "methodDisplay": "classAndMethod", 4 | "parallelizeTestCollections": true 5 | } 6 | --------------------------------------------------------------------------------