├── .gitignore ├── NuGet.Config ├── README.md ├── RestApiTesting.Framework.Cheetah.sln └── RestApiTesting.Framework.Cheetah ├── App.config ├── Constants ├── MimeTypes.cs └── RequestType.cs ├── Features ├── CreatePosts.feature ├── CreatePosts.feature.cs ├── DeletePosts.feature ├── DeletePosts.feature.cs ├── GetPosts.feature ├── GetPosts.feature.cs ├── PatchPosts.feature ├── PatchPosts.feature.cs ├── UpdatePosts.feature └── UpdatePosts.feature.cs ├── Helpers ├── AssertionHelper.cs ├── ClientHelper.cs ├── ConfigurationHelper.cs ├── InitializeHelper.cs └── TransformationHelper.cs ├── RestApiTesting.Framework.Cheetah.csproj ├── StepDefinitions ├── AssertionsSteps.cs ├── ClientSteps.cs └── InputDataSteps.cs ├── config.json └── images ├── JSONPlaceholder.jpg ├── build.png ├── c-sharp.png ├── cheetah.jpg ├── fluentassertions.png ├── netcore.png ├── social-preview.png ├── specflow.png ├── specflowextension.png └── testexplorer.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RestApiTesting.Framework.Cheetah 2 | This is a RESTful API testing Framework using C#, .NET Core, xUnit, Specflow BDD test framework, HttpClient and Fluent Assertions to test JSONPlaceholder REST API. 3 | 4 | ## Specflow 5 | Use SpecFlow to define, manage and automatically execute human-readable acceptance tests in .NET projects. Writing easily understandable tests is a cornerstone of the BDD paradigm and also helps build up a living documentation of your system. https://specflow.org/ 6 | 7 | ## Target framework 8 | .NET Core 2.1 9 | 10 | ## JSONPlaceholder 11 | JSONPlaceholder is a free online REST API that you can use whenever you need some fake data. It's great for tutorials, testing new libraries, sharing code examples. 12 | https://jsonplaceholder.typicode.com/ 13 | 14 | ## Routes Tested 15 | The following HTTP methods are tested: 16 | * GET 17 | * POST 18 | * PUT 19 | * PATCH 20 | * DELETE 21 | 22 | ## HttpClient 23 | HttpClient class provides a base class for sending/receiving the HTTP requests/responses from a URL. It is a supported async feature of .NET framework. HttpClient is able to process multiple concurrent requests. It is a layer over HttpWebRequest and HttpWebResponse. All methods with HttpClient are asynchronous. 24 | https://docs.microsoft.com/en-us/uwp/api/windows.web.http.httpclient 25 | 26 | ## Assertions 27 | Fluent Assertions is used for validation. 28 | https://fluentassertions.com/ 29 | 30 | ## Integrated Development Environment 31 | Microsoft Visual Studio IDE is used to develop this Framework. 32 | 33 | ### Visual Studio Extensions 34 | * Extensions => Manage Extensions => Search and Install SpecFlow for Visual Studio 35 | 36 | 37 | ### Build Solution 38 | * Build => Build Solution 39 | 40 | 41 | ### Run Tests 42 | * Test => Windows => Test Explorer => Run All 43 | 44 | 45 | ### Run Tests with Command Prompt/Windows PowerShell 46 | * Open Folder in File Explorer: ..\RestApiTesting.Framework.Cheetah\bin\Debug\netcoreapp2.1 47 | * Open Command Prompt/Windows PowerShell 48 | * Run "dotnet vstest RestApiTesting.Framework.Cheetah.dll" 49 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2027 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestApiTesting.Framework.Cheetah", "RestApiTesting.Framework.Cheetah\RestApiTesting.Framework.Cheetah.csproj", "{37F34238-D82D-4226-99C0-3C861A9AA9C1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {37F34238-D82D-4226-99C0-3C861A9AA9C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {37F34238-D82D-4226-99C0-3C861A9AA9C1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {37F34238-D82D-4226-99C0-3C861A9AA9C1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {37F34238-D82D-4226-99C0-3C861A9AA9C1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {EA5EEFE2-A7BC-45F8-814A-1380089844AF} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Constants/MimeTypes.cs: -------------------------------------------------------------------------------- 1 | namespace RestApiTesting.Framework.Cheetah.Constants 2 | { 3 | public class MimeTypes 4 | { 5 | public const string ApplicationJson = "application/json"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Constants/RequestType.cs: -------------------------------------------------------------------------------- 1 | namespace RestApiTesting.Framework.Cheetah.Constants 2 | { 3 | public class RequestType 4 | { 5 | public const string Get = nameof(Get); 6 | 7 | public const string Delete = nameof(Delete); 8 | 9 | public const string Post = nameof(Post); 10 | 11 | public const string Put = nameof(Put); 12 | 13 | public const string Patch = nameof(Patch); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/CreatePosts.feature: -------------------------------------------------------------------------------- 1 | Feature: CreatePosts 2 | As a non-authenticated user, 3 | I want the ability to create a post. 4 | 5 | Background: 6 | Given I have a client "client1" 7 | 8 | @AcceptanceCriteria 9 | Scenario: A non-authenticated user successfully creates a post 10 | Given I have a string "title" named "title1" 11 | And I have a string "str body" named "body1" 12 | And I have an int "1" named "userId1" 13 | And I have an int "101" named "id1" 14 | And I have a model "createPostsModel1" with the following values: 15 | | Field | Value | 16 | | userId | userId1 | 17 | | id | id1 | 18 | | title | title1 | 19 | | body | body1 | 20 | When I send a "Post" request to "/posts" with model "createPostsModel1" using client "client1" and get the response "createPostsResponse1" 21 | And I get the content "createPostsResponse1Body" of the response "createPostsResponse1" 22 | Then the response "createPostsResponse1" should have the status code "Created" 23 | And the model "createPostsResponse1Body" should have 4 parameters 24 | And the model "createPostsResponse1Body" should match the following values: 25 | | Field | Value | 26 | | userId | userId1 | 27 | | id | id1 | 28 | | title | title1 | 29 | | body | body1 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/CreatePosts.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace RestApiTesting.Framework.Cheetah.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | public partial class CreatePostsFeature : Xunit.IClassFixture, System.IDisposable 21 | { 22 | 23 | private static TechTalk.SpecFlow.ITestRunner testRunner; 24 | 25 | private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; 26 | 27 | #line 1 "CreatePosts.feature" 28 | #line hidden 29 | 30 | public CreatePostsFeature(CreatePostsFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) 31 | { 32 | this._testOutputHelper = testOutputHelper; 33 | this.TestInitialize(); 34 | } 35 | 36 | public static void FeatureSetup() 37 | { 38 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 39 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "CreatePosts", "As a non-authenticated user,\r\nI want the ability to create a post.", ProgrammingLanguage.CSharp, ((string[])(null))); 40 | testRunner.OnFeatureStart(featureInfo); 41 | } 42 | 43 | public static void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | public virtual void TestInitialize() 50 | { 51 | } 52 | 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | public virtual void FeatureBackground() 75 | { 76 | #line 5 77 | #line 6 78 | testRunner.Given("I have a client \"client1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 79 | #line hidden 80 | } 81 | 82 | void System.IDisposable.Dispose() 83 | { 84 | this.ScenarioTearDown(); 85 | } 86 | 87 | [Xunit.FactAttribute(DisplayName="A non-authenticated user successfully creates a post")] 88 | [Xunit.TraitAttribute("FeatureTitle", "CreatePosts")] 89 | [Xunit.TraitAttribute("Description", "A non-authenticated user successfully creates a post")] 90 | [Xunit.TraitAttribute("Category", "AcceptanceCriteria")] 91 | public virtual void ANon_AuthenticatedUserSuccessfullyCreatesAPost() 92 | { 93 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user successfully creates a post", null, new string[] { 94 | "AcceptanceCriteria"}); 95 | #line 9 96 | this.ScenarioInitialize(scenarioInfo); 97 | this.ScenarioStart(); 98 | #line 5 99 | this.FeatureBackground(); 100 | #line 10 101 | testRunner.Given("I have a string \"title\" named \"title1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 102 | #line 11 103 | testRunner.And("I have a string \"str body\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 104 | #line 12 105 | testRunner.And("I have an int \"1\" named \"userId1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 106 | #line 13 107 | testRunner.And("I have an int \"101\" named \"id1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 108 | #line hidden 109 | TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { 110 | "Field", 111 | "Value"}); 112 | table1.AddRow(new string[] { 113 | "userId", 114 | "userId1"}); 115 | table1.AddRow(new string[] { 116 | "id", 117 | "id1"}); 118 | table1.AddRow(new string[] { 119 | "title", 120 | "title1"}); 121 | table1.AddRow(new string[] { 122 | "body", 123 | "body1"}); 124 | #line 14 125 | testRunner.And("I have a model \"createPostsModel1\" with the following values:", ((string)(null)), table1, "And "); 126 | #line 20 127 | testRunner.When("I send a \"Post\" request to \"/posts\" with model \"createPostsModel1\" using client \"" + 128 | "client1\" and get the response \"createPostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 129 | #line 21 130 | testRunner.And("I get the content \"createPostsResponse1Body\" of the response \"createPostsResponse" + 131 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 132 | #line 22 133 | testRunner.Then("the response \"createPostsResponse1\" should have the status code \"Created\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 134 | #line 23 135 | testRunner.And("the model \"createPostsResponse1Body\" should have 4 parameters", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 136 | #line hidden 137 | TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { 138 | "Field", 139 | "Value"}); 140 | table2.AddRow(new string[] { 141 | "userId", 142 | "userId1"}); 143 | table2.AddRow(new string[] { 144 | "id", 145 | "id1"}); 146 | table2.AddRow(new string[] { 147 | "title", 148 | "title1"}); 149 | table2.AddRow(new string[] { 150 | "body", 151 | "body1"}); 152 | #line 24 153 | testRunner.And("the model \"createPostsResponse1Body\" should match the following values:", ((string)(null)), table2, "And "); 154 | #line hidden 155 | this.ScenarioCleanup(); 156 | } 157 | 158 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 159 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 160 | public class FixtureData : System.IDisposable 161 | { 162 | 163 | public FixtureData() 164 | { 165 | CreatePostsFeature.FeatureSetup(); 166 | } 167 | 168 | void System.IDisposable.Dispose() 169 | { 170 | CreatePostsFeature.FeatureTearDown(); 171 | } 172 | } 173 | } 174 | } 175 | #pragma warning restore 176 | #endregion 177 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/DeletePosts.feature: -------------------------------------------------------------------------------- 1 | Feature: DeletePosts 2 | As a non-authenticated user, 3 | I want the ability to delete a post. 4 | 5 | Background: 6 | Given I have a client "client1" 7 | 8 | @AcceptanceCriteria 9 | Scenario: A non-authenticated user successfully deletes a post 10 | When I send a "Delete" request to "/posts/1" using client "client1" and get the response "deletePostsResponse1" 11 | And I get the content "deletePostsResponse1Body" of the response "deletePostsResponse1" 12 | Then the response "deletePostsResponse1" should have the status code "OK" 13 | And the model "deletePostsResponse1Body" should match the following values: 14 | | Field | Value | 15 | 16 | @NegativePath 17 | Scenario: A non-authenticated user attempts to delete a post with nonexistent id 18 | When I send a "Delete" request to "/posts/101" using client "client1" and get the response "deletePostsResponse1" 19 | And I get the content "deletePostsResponse1Body" of the response "deletePostsResponse1" 20 | Then the response "deletePostsResponse1" should have the status code "OK" 21 | And the model "deletePostsResponse1Body" should match the following values: 22 | | Field | Value | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/DeletePosts.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace RestApiTesting.Framework.Cheetah.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | public partial class DeletePostsFeature : Xunit.IClassFixture, System.IDisposable 21 | { 22 | 23 | private static TechTalk.SpecFlow.ITestRunner testRunner; 24 | 25 | private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; 26 | 27 | #line 1 "DeletePosts.feature" 28 | #line hidden 29 | 30 | public DeletePostsFeature(DeletePostsFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) 31 | { 32 | this._testOutputHelper = testOutputHelper; 33 | this.TestInitialize(); 34 | } 35 | 36 | public static void FeatureSetup() 37 | { 38 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 39 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "DeletePosts", "As a non-authenticated user,\r\nI want the ability to delete a post.", ProgrammingLanguage.CSharp, ((string[])(null))); 40 | testRunner.OnFeatureStart(featureInfo); 41 | } 42 | 43 | public static void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | public virtual void TestInitialize() 50 | { 51 | } 52 | 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | public virtual void FeatureBackground() 75 | { 76 | #line 5 77 | #line 6 78 | testRunner.Given("I have a client \"client1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 79 | #line hidden 80 | } 81 | 82 | void System.IDisposable.Dispose() 83 | { 84 | this.ScenarioTearDown(); 85 | } 86 | 87 | [Xunit.FactAttribute(DisplayName="A non-authenticated user successfully deletes a post")] 88 | [Xunit.TraitAttribute("FeatureTitle", "DeletePosts")] 89 | [Xunit.TraitAttribute("Description", "A non-authenticated user successfully deletes a post")] 90 | [Xunit.TraitAttribute("Category", "AcceptanceCriteria")] 91 | public virtual void ANon_AuthenticatedUserSuccessfullyDeletesAPost() 92 | { 93 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user successfully deletes a post", null, new string[] { 94 | "AcceptanceCriteria"}); 95 | #line 9 96 | this.ScenarioInitialize(scenarioInfo); 97 | this.ScenarioStart(); 98 | #line 5 99 | this.FeatureBackground(); 100 | #line 10 101 | testRunner.When("I send a \"Delete\" request to \"/posts/1\" using client \"client1\" and get the respon" + 102 | "se \"deletePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 103 | #line 11 104 | testRunner.And("I get the content \"deletePostsResponse1Body\" of the response \"deletePostsResponse" + 105 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 106 | #line 12 107 | testRunner.Then("the response \"deletePostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 108 | #line hidden 109 | TechTalk.SpecFlow.Table table3 = new TechTalk.SpecFlow.Table(new string[] { 110 | "Field", 111 | "Value"}); 112 | #line 13 113 | testRunner.And("the model \"deletePostsResponse1Body\" should match the following values:", ((string)(null)), table3, "And "); 114 | #line hidden 115 | this.ScenarioCleanup(); 116 | } 117 | 118 | [Xunit.FactAttribute(DisplayName="A non-authenticated user attempts to delete a post with nonexistent id")] 119 | [Xunit.TraitAttribute("FeatureTitle", "DeletePosts")] 120 | [Xunit.TraitAttribute("Description", "A non-authenticated user attempts to delete a post with nonexistent id")] 121 | [Xunit.TraitAttribute("Category", "NegativePath")] 122 | public virtual void ANon_AuthenticatedUserAttemptsToDeleteAPostWithNonexistentId() 123 | { 124 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user attempts to delete a post with nonexistent id", null, new string[] { 125 | "NegativePath"}); 126 | #line 17 127 | this.ScenarioInitialize(scenarioInfo); 128 | this.ScenarioStart(); 129 | #line 5 130 | this.FeatureBackground(); 131 | #line 18 132 | testRunner.When("I send a \"Delete\" request to \"/posts/101\" using client \"client1\" and get the resp" + 133 | "onse \"deletePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 134 | #line 19 135 | testRunner.And("I get the content \"deletePostsResponse1Body\" of the response \"deletePostsResponse" + 136 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 137 | #line 20 138 | testRunner.Then("the response \"deletePostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 139 | #line hidden 140 | TechTalk.SpecFlow.Table table4 = new TechTalk.SpecFlow.Table(new string[] { 141 | "Field", 142 | "Value"}); 143 | #line 21 144 | testRunner.And("the model \"deletePostsResponse1Body\" should match the following values:", ((string)(null)), table4, "And "); 145 | #line hidden 146 | this.ScenarioCleanup(); 147 | } 148 | 149 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 150 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 151 | public class FixtureData : System.IDisposable 152 | { 153 | 154 | public FixtureData() 155 | { 156 | DeletePostsFeature.FeatureSetup(); 157 | } 158 | 159 | void System.IDisposable.Dispose() 160 | { 161 | DeletePostsFeature.FeatureTearDown(); 162 | } 163 | } 164 | } 165 | } 166 | #pragma warning restore 167 | #endregion 168 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/GetPosts.feature: -------------------------------------------------------------------------------- 1 | Feature: GetPosts 2 | As a non-authenticated user, 3 | I want the ability to get a post. 4 | 5 | Background: 6 | Given I have a client "client1" 7 | 8 | @AcceptanceCriteria 9 | Scenario: A non-authenticated user successfully gets a post 10 | Given I have a string "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" named "title1" 11 | And I have a string "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto" named "body1" 12 | And I have an int "1" named "one" 13 | When I send a "Get" request to "/posts/1" using client "client1" and get the response "deletePostsResponse1" 14 | And I get the content "deletePostsResponse1Body" of the response "deletePostsResponse1" 15 | Then the response "deletePostsResponse1" should have the status code "OK" 16 | And the "userId" of "deletePostsResponse1Body" should be "one" 17 | And the "id" of "deletePostsResponse1Body" should be "one" 18 | And the "title" of "deletePostsResponse1Body" should be "title1" 19 | And I compare "body" of "deletePostsResponse1Body" with "body1" 20 | And the modified "body" of "deletePostsResponse1Body" should be modified "body1" 21 | 22 | @NegativePath 23 | Scenario: A non-authenticated user attempts to get a post with nonexistent id 24 | When I send a "Get" request to "/posts/101" using client "client1" and get the response "deletePostsResponse1" 25 | And I get the content "deletePostsResponse1Body" of the response "deletePostsResponse1" 26 | Then the response "deletePostsResponse1" should have the status code "Not Found" -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/GetPosts.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace RestApiTesting.Framework.Cheetah.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | public partial class GetPostsFeature : Xunit.IClassFixture, System.IDisposable 21 | { 22 | 23 | private static TechTalk.SpecFlow.ITestRunner testRunner; 24 | 25 | private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; 26 | 27 | #line 1 "GetPosts.feature" 28 | #line hidden 29 | 30 | public GetPostsFeature(GetPostsFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) 31 | { 32 | this._testOutputHelper = testOutputHelper; 33 | this.TestInitialize(); 34 | } 35 | 36 | public static void FeatureSetup() 37 | { 38 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 39 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "GetPosts", "As a non-authenticated user,\r\nI want the ability to get a post.", ProgrammingLanguage.CSharp, ((string[])(null))); 40 | testRunner.OnFeatureStart(featureInfo); 41 | } 42 | 43 | public static void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | public virtual void TestInitialize() 50 | { 51 | } 52 | 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | public virtual void FeatureBackground() 75 | { 76 | #line 5 77 | #line 6 78 | testRunner.Given("I have a client \"client1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 79 | #line hidden 80 | } 81 | 82 | void System.IDisposable.Dispose() 83 | { 84 | this.ScenarioTearDown(); 85 | } 86 | 87 | [Xunit.FactAttribute(DisplayName="A non-authenticated user successfully gets a post")] 88 | [Xunit.TraitAttribute("FeatureTitle", "GetPosts")] 89 | [Xunit.TraitAttribute("Description", "A non-authenticated user successfully gets a post")] 90 | [Xunit.TraitAttribute("Category", "AcceptanceCriteria")] 91 | public virtual void ANon_AuthenticatedUserSuccessfullyGetsAPost() 92 | { 93 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user successfully gets a post", null, new string[] { 94 | "AcceptanceCriteria"}); 95 | #line 9 96 | this.ScenarioInitialize(scenarioInfo); 97 | this.ScenarioStart(); 98 | #line 5 99 | this.FeatureBackground(); 100 | #line 10 101 | testRunner.Given("I have a string \"sunt aut facere repellat provident occaecati excepturi optio rep" + 102 | "rehenderit\" named \"title1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 103 | #line 11 104 | testRunner.And("I have a string \"quia et suscipit suscipit recusandae consequuntur expedita et cu" + 105 | "m reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem even" + 106 | "iet architecto\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 107 | #line 12 108 | testRunner.And("I have an int \"1\" named \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 109 | #line 13 110 | testRunner.When("I send a \"Get\" request to \"/posts/1\" using client \"client1\" and get the response " + 111 | "\"deletePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 112 | #line 14 113 | testRunner.And("I get the content \"deletePostsResponse1Body\" of the response \"deletePostsResponse" + 114 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 115 | #line 15 116 | testRunner.Then("the response \"deletePostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 117 | #line 16 118 | testRunner.And("the \"userId\" of \"deletePostsResponse1Body\" should be \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 119 | #line 17 120 | testRunner.And("the \"id\" of \"deletePostsResponse1Body\" should be \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 121 | #line 18 122 | testRunner.And("the \"title\" of \"deletePostsResponse1Body\" should be \"title1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 123 | #line 19 124 | testRunner.And("I compare \"body\" of \"deletePostsResponse1Body\" with \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 125 | #line 20 126 | testRunner.And("the modified \"body\" of \"deletePostsResponse1Body\" should be modified \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 127 | #line hidden 128 | this.ScenarioCleanup(); 129 | } 130 | 131 | [Xunit.FactAttribute(DisplayName="A non-authenticated user attempts to get a post with nonexistent id")] 132 | [Xunit.TraitAttribute("FeatureTitle", "GetPosts")] 133 | [Xunit.TraitAttribute("Description", "A non-authenticated user attempts to get a post with nonexistent id")] 134 | [Xunit.TraitAttribute("Category", "NegativePath")] 135 | public virtual void ANon_AuthenticatedUserAttemptsToGetAPostWithNonexistentId() 136 | { 137 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user attempts to get a post with nonexistent id", null, new string[] { 138 | "NegativePath"}); 139 | #line 23 140 | this.ScenarioInitialize(scenarioInfo); 141 | this.ScenarioStart(); 142 | #line 5 143 | this.FeatureBackground(); 144 | #line 24 145 | testRunner.When("I send a \"Get\" request to \"/posts/101\" using client \"client1\" and get the respons" + 146 | "e \"deletePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 147 | #line 25 148 | testRunner.And("I get the content \"deletePostsResponse1Body\" of the response \"deletePostsResponse" + 149 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 150 | #line 26 151 | testRunner.Then("the response \"deletePostsResponse1\" should have the status code \"Not Found\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 152 | #line hidden 153 | this.ScenarioCleanup(); 154 | } 155 | 156 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 157 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 158 | public class FixtureData : System.IDisposable 159 | { 160 | 161 | public FixtureData() 162 | { 163 | GetPostsFeature.FeatureSetup(); 164 | } 165 | 166 | void System.IDisposable.Dispose() 167 | { 168 | GetPostsFeature.FeatureTearDown(); 169 | } 170 | } 171 | } 172 | } 173 | #pragma warning restore 174 | #endregion 175 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/PatchPosts.feature: -------------------------------------------------------------------------------- 1 | Feature: PatchPosts 2 | As a non-authenticated user, 3 | I want the ability to patch a post. 4 | 5 | Background: 6 | Given I have a client "client1" 7 | 8 | @AcceptanceCriteria 9 | Scenario: A non-authenticated user successfully patchs a post 10 | Given I have a string "patched body" named "body1" 11 | And I have a model "patchPostsModel1" with the following values: 12 | | Field | Value | 13 | | body | body1 | 14 | And I have an int "1" named "one" 15 | And I have a string "sunt aut facere repellat provident occaecati excepturi optio reprehenderit" named "titleActual" 16 | When I send a "Patch" request to "/posts/1" with model "patchPostsModel1" using client "client1" and get the response "patchPostsResponse1" 17 | And I get the content "patchPostsResponse1Body" of the response "patchPostsResponse1" 18 | Then the response "patchPostsResponse1" should have the status code "OK" 19 | And the model "patchPostsResponse1Body" should match the following values: 20 | | Field | Value | 21 | | userId | one | 22 | | id | one | 23 | | title | titleActual | 24 | | body | body1 | 25 | 26 | @NegativePath 27 | Scenario: A non-authenticated user attempts to patch a post with nonexistent id 28 | Given I have a string "patched body" named "body1" 29 | And I have a model "patchPostsModel1" with the following values: 30 | | Field | Value | 31 | | body | body1 | 32 | When I send a "Patch" request to "/posts/101" with model "patchPostsModel1" using client "client1" and get the response "patchPostsResponse1" 33 | And I get the content "patchPostsResponse1Body" of the response "patchPostsResponse1" 34 | Then the response "patchPostsResponse1" should have the status code "OK" 35 | And the model "patchPostsResponse1Body" should match the following values: 36 | | Field | Value | 37 | | body | body1 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/PatchPosts.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace RestApiTesting.Framework.Cheetah.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | public partial class PatchPostsFeature : Xunit.IClassFixture, System.IDisposable 21 | { 22 | 23 | private static TechTalk.SpecFlow.ITestRunner testRunner; 24 | 25 | private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; 26 | 27 | #line 1 "PatchPosts.feature" 28 | #line hidden 29 | 30 | public PatchPostsFeature(PatchPostsFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) 31 | { 32 | this._testOutputHelper = testOutputHelper; 33 | this.TestInitialize(); 34 | } 35 | 36 | public static void FeatureSetup() 37 | { 38 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 39 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "PatchPosts", "As a non-authenticated user,\r\nI want the ability to patch a post.", ProgrammingLanguage.CSharp, ((string[])(null))); 40 | testRunner.OnFeatureStart(featureInfo); 41 | } 42 | 43 | public static void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | public virtual void TestInitialize() 50 | { 51 | } 52 | 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | public virtual void FeatureBackground() 75 | { 76 | #line 5 77 | #line 6 78 | testRunner.Given("I have a client \"client1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 79 | #line hidden 80 | } 81 | 82 | void System.IDisposable.Dispose() 83 | { 84 | this.ScenarioTearDown(); 85 | } 86 | 87 | [Xunit.FactAttribute(DisplayName="A non-authenticated user successfully patchs a post")] 88 | [Xunit.TraitAttribute("FeatureTitle", "PatchPosts")] 89 | [Xunit.TraitAttribute("Description", "A non-authenticated user successfully patchs a post")] 90 | [Xunit.TraitAttribute("Category", "AcceptanceCriteria")] 91 | public virtual void ANon_AuthenticatedUserSuccessfullyPatchsAPost() 92 | { 93 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user successfully patchs a post", null, new string[] { 94 | "AcceptanceCriteria"}); 95 | #line 9 96 | this.ScenarioInitialize(scenarioInfo); 97 | this.ScenarioStart(); 98 | #line 5 99 | this.FeatureBackground(); 100 | #line 10 101 | testRunner.Given("I have a string \"patched body\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 102 | #line hidden 103 | TechTalk.SpecFlow.Table table5 = new TechTalk.SpecFlow.Table(new string[] { 104 | "Field", 105 | "Value"}); 106 | table5.AddRow(new string[] { 107 | "body", 108 | "body1"}); 109 | #line 11 110 | testRunner.And("I have a model \"patchPostsModel1\" with the following values:", ((string)(null)), table5, "And "); 111 | #line 14 112 | testRunner.And("I have an int \"1\" named \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 113 | #line 15 114 | testRunner.And("I have a string \"sunt aut facere repellat provident occaecati excepturi optio rep" + 115 | "rehenderit\" named \"titleActual\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 116 | #line 16 117 | testRunner.When("I send a \"Patch\" request to \"/posts/1\" with model \"patchPostsModel1\" using client" + 118 | " \"client1\" and get the response \"patchPostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 119 | #line 17 120 | testRunner.And("I get the content \"patchPostsResponse1Body\" of the response \"patchPostsResponse1\"" + 121 | "", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 122 | #line 18 123 | testRunner.Then("the response \"patchPostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 124 | #line hidden 125 | TechTalk.SpecFlow.Table table6 = new TechTalk.SpecFlow.Table(new string[] { 126 | "Field", 127 | "Value"}); 128 | table6.AddRow(new string[] { 129 | "userId", 130 | "one"}); 131 | table6.AddRow(new string[] { 132 | "id", 133 | "one"}); 134 | table6.AddRow(new string[] { 135 | "title", 136 | "titleActual"}); 137 | table6.AddRow(new string[] { 138 | "body", 139 | "body1"}); 140 | #line 19 141 | testRunner.And("the model \"patchPostsResponse1Body\" should match the following values:", ((string)(null)), table6, "And "); 142 | #line hidden 143 | this.ScenarioCleanup(); 144 | } 145 | 146 | [Xunit.FactAttribute(DisplayName="A non-authenticated user attempts to patch a post with nonexistent id")] 147 | [Xunit.TraitAttribute("FeatureTitle", "PatchPosts")] 148 | [Xunit.TraitAttribute("Description", "A non-authenticated user attempts to patch a post with nonexistent id")] 149 | [Xunit.TraitAttribute("Category", "NegativePath")] 150 | public virtual void ANon_AuthenticatedUserAttemptsToPatchAPostWithNonexistentId() 151 | { 152 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user attempts to patch a post with nonexistent id", null, new string[] { 153 | "NegativePath"}); 154 | #line 27 155 | this.ScenarioInitialize(scenarioInfo); 156 | this.ScenarioStart(); 157 | #line 5 158 | this.FeatureBackground(); 159 | #line 28 160 | testRunner.Given("I have a string \"patched body\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 161 | #line hidden 162 | TechTalk.SpecFlow.Table table7 = new TechTalk.SpecFlow.Table(new string[] { 163 | "Field", 164 | "Value"}); 165 | table7.AddRow(new string[] { 166 | "body", 167 | "body1"}); 168 | #line 29 169 | testRunner.And("I have a model \"patchPostsModel1\" with the following values:", ((string)(null)), table7, "And "); 170 | #line 32 171 | testRunner.When("I send a \"Patch\" request to \"/posts/101\" with model \"patchPostsModel1\" using clie" + 172 | "nt \"client1\" and get the response \"patchPostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 173 | #line 33 174 | testRunner.And("I get the content \"patchPostsResponse1Body\" of the response \"patchPostsResponse1\"" + 175 | "", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 176 | #line 34 177 | testRunner.Then("the response \"patchPostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 178 | #line hidden 179 | TechTalk.SpecFlow.Table table8 = new TechTalk.SpecFlow.Table(new string[] { 180 | "Field", 181 | "Value"}); 182 | table8.AddRow(new string[] { 183 | "body", 184 | "body1"}); 185 | #line 35 186 | testRunner.And("the model \"patchPostsResponse1Body\" should match the following values:", ((string)(null)), table8, "And "); 187 | #line hidden 188 | this.ScenarioCleanup(); 189 | } 190 | 191 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 192 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 193 | public class FixtureData : System.IDisposable 194 | { 195 | 196 | public FixtureData() 197 | { 198 | PatchPostsFeature.FeatureSetup(); 199 | } 200 | 201 | void System.IDisposable.Dispose() 202 | { 203 | PatchPostsFeature.FeatureTearDown(); 204 | } 205 | } 206 | } 207 | } 208 | #pragma warning restore 209 | #endregion 210 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/UpdatePosts.feature: -------------------------------------------------------------------------------- 1 | Feature: UpdatePosts 2 | As a non-authenticated user, 3 | I want the ability to update a post. 4 | 5 | Background: 6 | Given I have a client "client1" 7 | 8 | @AcceptanceCriteria 9 | Scenario: A non-authenticated user successfully updates a post 10 | Given I have a string "updated title" named "title1" 11 | And I have a string "updated body" named "body1" 12 | And I have an int "1" named "one" 13 | And I have a model "updatePostsModel1" with the following values: 14 | | Field | Value | 15 | | userId | one | 16 | | title | title1 | 17 | | body | body1 | 18 | When I send a "Put" request to "/posts/1" with model "updatePostsModel1" using client "client1" and get the response "updatePostsResponse1" 19 | And I get the content "updatePostsResponse1Body" of the response "updatePostsResponse1" 20 | Then the response "updatePostsResponse1" should have the status code "OK" 21 | And the model "updatePostsResponse1Body" should match the following values: 22 | | Field | Value | 23 | | userId | one | 24 | | id | one | 25 | | title | title1 | 26 | | body | body1 | 27 | 28 | @NegativePath 29 | Scenario: A non-authenticated user attempts to update a post with nonexistent id 30 | Given I have a string "updated title" named "title1" 31 | And I have a string "updated body" named "body1" 32 | And I have an int "1" named "one" 33 | And I have a model "updatePostsModel1" with the following values: 34 | | Field | Value | 35 | | userId | one | 36 | | title | title1 | 37 | | body | body1 | 38 | When I send a "Put" request to "/posts/101" with model "updatePostsModel1" using client "client1" and get the response "updatePostsResponse1" 39 | Then the response "updatePostsResponse1" should have the status code "Internal Server Error" -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Features/UpdatePosts.feature.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by SpecFlow (http://www.specflow.org/). 4 | // SpecFlow Version:3.0.0.0 5 | // SpecFlow Generator Version:3.0.0.0 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | #region Designer generated code 12 | #pragma warning disable 13 | namespace RestApiTesting.Framework.Cheetah.Features 14 | { 15 | using TechTalk.SpecFlow; 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 20 | public partial class UpdatePostsFeature : Xunit.IClassFixture, System.IDisposable 21 | { 22 | 23 | private static TechTalk.SpecFlow.ITestRunner testRunner; 24 | 25 | private Xunit.Abstractions.ITestOutputHelper _testOutputHelper; 26 | 27 | #line 1 "UpdatePosts.feature" 28 | #line hidden 29 | 30 | public UpdatePostsFeature(UpdatePostsFeature.FixtureData fixtureData, Xunit.Abstractions.ITestOutputHelper testOutputHelper) 31 | { 32 | this._testOutputHelper = testOutputHelper; 33 | this.TestInitialize(); 34 | } 35 | 36 | public static void FeatureSetup() 37 | { 38 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); 39 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "UpdatePosts", "As a non-authenticated user,\r\nI want the ability to update a post.", ProgrammingLanguage.CSharp, ((string[])(null))); 40 | testRunner.OnFeatureStart(featureInfo); 41 | } 42 | 43 | public static void FeatureTearDown() 44 | { 45 | testRunner.OnFeatureEnd(); 46 | testRunner = null; 47 | } 48 | 49 | public virtual void TestInitialize() 50 | { 51 | } 52 | 53 | public virtual void ScenarioTearDown() 54 | { 55 | testRunner.OnScenarioEnd(); 56 | } 57 | 58 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) 59 | { 60 | testRunner.OnScenarioInitialize(scenarioInfo); 61 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testOutputHelper); 62 | } 63 | 64 | public virtual void ScenarioStart() 65 | { 66 | testRunner.OnScenarioStart(); 67 | } 68 | 69 | public virtual void ScenarioCleanup() 70 | { 71 | testRunner.CollectScenarioErrors(); 72 | } 73 | 74 | public virtual void FeatureBackground() 75 | { 76 | #line 5 77 | #line 6 78 | testRunner.Given("I have a client \"client1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 79 | #line hidden 80 | } 81 | 82 | void System.IDisposable.Dispose() 83 | { 84 | this.ScenarioTearDown(); 85 | } 86 | 87 | [Xunit.FactAttribute(DisplayName="A non-authenticated user successfully updates a post")] 88 | [Xunit.TraitAttribute("FeatureTitle", "UpdatePosts")] 89 | [Xunit.TraitAttribute("Description", "A non-authenticated user successfully updates a post")] 90 | [Xunit.TraitAttribute("Category", "AcceptanceCriteria")] 91 | public virtual void ANon_AuthenticatedUserSuccessfullyUpdatesAPost() 92 | { 93 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user successfully updates a post", null, new string[] { 94 | "AcceptanceCriteria"}); 95 | #line 9 96 | this.ScenarioInitialize(scenarioInfo); 97 | this.ScenarioStart(); 98 | #line 5 99 | this.FeatureBackground(); 100 | #line 10 101 | testRunner.Given("I have a string \"updated title\" named \"title1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 102 | #line 11 103 | testRunner.And("I have a string \"updated body\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 104 | #line 12 105 | testRunner.And("I have an int \"1\" named \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 106 | #line hidden 107 | TechTalk.SpecFlow.Table table9 = new TechTalk.SpecFlow.Table(new string[] { 108 | "Field", 109 | "Value"}); 110 | table9.AddRow(new string[] { 111 | "userId", 112 | "one"}); 113 | table9.AddRow(new string[] { 114 | "title", 115 | "title1"}); 116 | table9.AddRow(new string[] { 117 | "body", 118 | "body1"}); 119 | #line 13 120 | testRunner.And("I have a model \"updatePostsModel1\" with the following values:", ((string)(null)), table9, "And "); 121 | #line 18 122 | testRunner.When("I send a \"Put\" request to \"/posts/1\" with model \"updatePostsModel1\" using client " + 123 | "\"client1\" and get the response \"updatePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 124 | #line 19 125 | testRunner.And("I get the content \"updatePostsResponse1Body\" of the response \"updatePostsResponse" + 126 | "1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 127 | #line 20 128 | testRunner.Then("the response \"updatePostsResponse1\" should have the status code \"OK\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 129 | #line hidden 130 | TechTalk.SpecFlow.Table table10 = new TechTalk.SpecFlow.Table(new string[] { 131 | "Field", 132 | "Value"}); 133 | table10.AddRow(new string[] { 134 | "userId", 135 | "one"}); 136 | table10.AddRow(new string[] { 137 | "id", 138 | "one"}); 139 | table10.AddRow(new string[] { 140 | "title", 141 | "title1"}); 142 | table10.AddRow(new string[] { 143 | "body", 144 | "body1"}); 145 | #line 21 146 | testRunner.And("the model \"updatePostsResponse1Body\" should match the following values:", ((string)(null)), table10, "And "); 147 | #line hidden 148 | this.ScenarioCleanup(); 149 | } 150 | 151 | [Xunit.FactAttribute(DisplayName="A non-authenticated user attempts to update a post with nonexistent id")] 152 | [Xunit.TraitAttribute("FeatureTitle", "UpdatePosts")] 153 | [Xunit.TraitAttribute("Description", "A non-authenticated user attempts to update a post with nonexistent id")] 154 | [Xunit.TraitAttribute("Category", "NegativePath")] 155 | public virtual void ANon_AuthenticatedUserAttemptsToUpdateAPostWithNonexistentId() 156 | { 157 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("A non-authenticated user attempts to update a post with nonexistent id", null, new string[] { 158 | "NegativePath"}); 159 | #line 29 160 | this.ScenarioInitialize(scenarioInfo); 161 | this.ScenarioStart(); 162 | #line 5 163 | this.FeatureBackground(); 164 | #line 30 165 | testRunner.Given("I have a string \"updated title\" named \"title1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); 166 | #line 31 167 | testRunner.And("I have a string \"updated body\" named \"body1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 168 | #line 32 169 | testRunner.And("I have an int \"1\" named \"one\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); 170 | #line hidden 171 | TechTalk.SpecFlow.Table table11 = new TechTalk.SpecFlow.Table(new string[] { 172 | "Field", 173 | "Value"}); 174 | table11.AddRow(new string[] { 175 | "userId", 176 | "one"}); 177 | table11.AddRow(new string[] { 178 | "title", 179 | "title1"}); 180 | table11.AddRow(new string[] { 181 | "body", 182 | "body1"}); 183 | #line 33 184 | testRunner.And("I have a model \"updatePostsModel1\" with the following values:", ((string)(null)), table11, "And "); 185 | #line 38 186 | testRunner.When("I send a \"Put\" request to \"/posts/101\" with model \"updatePostsModel1\" using clien" + 187 | "t \"client1\" and get the response \"updatePostsResponse1\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); 188 | #line 39 189 | testRunner.Then("the response \"updatePostsResponse1\" should have the status code \"Internal Server " + 190 | "Error\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); 191 | #line hidden 192 | this.ScenarioCleanup(); 193 | } 194 | 195 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] 196 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 197 | public class FixtureData : System.IDisposable 198 | { 199 | 200 | public FixtureData() 201 | { 202 | UpdatePostsFeature.FeatureSetup(); 203 | } 204 | 205 | void System.IDisposable.Dispose() 206 | { 207 | UpdatePostsFeature.FeatureTearDown(); 208 | } 209 | } 210 | } 211 | } 212 | #pragma warning restore 213 | #endregion 214 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Helpers/AssertionHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Dynamic; 2 | using FluentAssertions; 3 | using TechTalk.SpecFlow; 4 | 5 | namespace RestApiTesting.Framework.Cheetah.Helpers 6 | { 7 | public class AssertionHelper 8 | { 9 | public static void AssertModelMatchTable(ExpandoObject actualModel, ExpandoObject expectedModel) 10 | { 11 | actualModel.Should().BeEquivalentTo(expectedModel); 12 | } 13 | 14 | public static void AssertNoOfModelParameters(ScenarioContext scenarioContext, string responseBodyKey, int numExpectedParameters) 15 | { 16 | var responseBody = scenarioContext.Get(responseBodyKey); 17 | responseBody.Should().HaveCount(numExpectedParameters); 18 | } 19 | 20 | public static void AssertStrings(string actual, string expected) 21 | { 22 | actual.Should().Be(expected); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Helpers/ClientHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | using System.Net.Http; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | using RestApiTesting.Framework.Cheetah.Constants; 7 | 8 | namespace RestApiTesting.Framework.Cheetah.Helpers 9 | { 10 | public class ClientHelper 11 | { 12 | public static HttpClient GetClient(Uri uri) 13 | { 14 | var httpClientHandler = new HttpClientHandler(); 15 | 16 | var proxy = new HttpClient(httpClientHandler) 17 | { 18 | BaseAddress = uri 19 | }; 20 | 21 | return proxy; 22 | } 23 | 24 | public static Task GetResponse(string uri, string requestType, HttpClient client, ExpandoObject model) 25 | { 26 | HttpRequestMessage request; 27 | 28 | switch (requestType) 29 | { 30 | case RequestType.Get: 31 | request = new HttpRequestMessage(HttpMethod.Get, uri); 32 | break; 33 | case RequestType.Delete: 34 | request = new HttpRequestMessage(HttpMethod.Delete, uri); 35 | break; 36 | case RequestType.Post: 37 | request = new HttpRequestMessage(HttpMethod.Post, uri); 38 | break; 39 | case RequestType.Put: 40 | request = new HttpRequestMessage(HttpMethod.Put, uri); 41 | break; 42 | case RequestType.Patch: 43 | request = new HttpRequestMessage(new HttpMethod("PATCH"), uri); 44 | break; 45 | default: 46 | throw new NotImplementedException($"Request type: {requestType} is not implemented."); 47 | } 48 | 49 | if (model != null) 50 | { 51 | request.Content = new StringContent(JsonConvert.SerializeObject(model), System.Text.Encoding.UTF8, MimeTypes.ApplicationJson); 52 | } 53 | 54 | return client.SendAsync(request); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Helpers/ConfigurationHelper.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.Extensions.Configuration; 3 | 4 | namespace RestApiTesting.Framework.Cheetah.Helpers 5 | { 6 | public class ConfigurationHelper 7 | { 8 | public static string TestApiUrl => ConfigurationRoot[nameof(TestApiUrl)]; 9 | 10 | public static IConfigurationRoot ConfigurationRoot { get; private set; } 11 | 12 | public static void BuildConfiguration() 13 | { 14 | if (ConfigurationRoot != null) 15 | { 16 | return; 17 | } 18 | 19 | IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("config.json", false).AddEnvironmentVariables(); 20 | ConfigurationRoot = builder.Build(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Helpers/InitializeHelper.cs: -------------------------------------------------------------------------------- 1 | using TechTalk.SpecFlow; 2 | 3 | namespace RestApiTesting.Framework.Cheetah.Helpers 4 | { 5 | [Binding] 6 | public sealed class InitializeHelper 7 | { 8 | public ScenarioContext ScenarioContext; 9 | 10 | public InitializeHelper(ScenarioContext scenarioContext) 11 | { 12 | ScenarioContext = scenarioContext; 13 | } 14 | 15 | [BeforeTestRun] 16 | public static void BeforeTestRun() 17 | { 18 | ConfigurationHelper.BuildConfiguration(); 19 | } 20 | 21 | [BeforeScenario] 22 | public void BeforeScenario() 23 | { 24 | ScenarioContext.Add(nameof(ConfigurationHelper.TestApiUrl), ConfigurationHelper.TestApiUrl); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/Helpers/TransformationHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Dynamic; 4 | using System.Net.Http; 5 | using TechTalk.SpecFlow; 6 | 7 | namespace RestApiTesting.Framework.Cheetah.Helpers 8 | { 9 | [Binding] 10 | public sealed class TransformerHelper 11 | { 12 | private readonly ScenarioContext m_scenarioContext; 13 | 14 | public TransformerHelper(ScenarioContext scenarioContext) 15 | { 16 | m_scenarioContext = scenarioContext; 17 | } 18 | 19 | [StepArgumentTransformation] 20 | public ExpandoObject GetExpandoObject(object input) 21 | { 22 | dynamic model = new ExpandoObject(); 23 | switch (input) 24 | { 25 | case Table inputTable: 26 | foreach (TableRow row in inputTable.Rows) 27 | { 28 | ((IDictionary)model).Add(row["Field"], m_scenarioContext.Get(row["Value"])); 29 | } 30 | 31 | break; 32 | case string inputString: 33 | model = m_scenarioContext.Get(inputString); 34 | break; 35 | default: 36 | throw new ArgumentException($"No StepArgumentTransformation exists from type {input.GetType()} to type ExpandoObject"); 37 | } 38 | 39 | return model; 40 | } 41 | 42 | [StepArgumentTransformation] 43 | public HttpClient GetHttpClient(string clientKey) 44 | { 45 | return m_scenarioContext.Get(clientKey); 46 | } 47 | 48 | [StepArgumentTransformation] 49 | public HttpResponseMessage GetResponseMessage(string responseKey) 50 | { 51 | return m_scenarioContext.Get(responseKey); 52 | } 53 | 54 | public static object GetActualValue(ScenarioContext scenarioContext, string field, string objectKey) 55 | { 56 | var content = scenarioContext.Get(objectKey); 57 | IDictionary contentDict = content; 58 | contentDict.TryGetValue(field, out object actualValue); 59 | return actualValue; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/RestApiTesting.Framework.Cheetah.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netcoreapp2.1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | all 18 | runtime; build; native; contentfiles; analyzers 19 | 20 | 21 | 22 | 23 | 24 | True 25 | True 26 | CreatePosts.feature 27 | 28 | 29 | True 30 | True 31 | GetPosts.feature 32 | 33 | 34 | True 35 | True 36 | DeletePosts.feature 37 | 38 | 39 | True 40 | True 41 | PatchPosts.feature 42 | 43 | 44 | True 45 | True 46 | UpdatePosts.feature 47 | 48 | 49 | Code 50 | 51 | 52 | Code 53 | 54 | 55 | Code 56 | 57 | 58 | Code 59 | 60 | 61 | Code 62 | 63 | 64 | 65 | 66 | 67 | Always 68 | 69 | 70 | PreserveNewest 71 | 72 | 73 | Always 74 | 75 | 76 | Always 77 | 78 | 79 | Always 80 | 81 | 82 | Always 83 | 84 | 85 | 86 | 87 | 88 | SpecFlowSingleFileGenerator 89 | GetPosts.feature.cs 90 | 91 | 92 | SpecFlowSingleFileGenerator 93 | DeletePosts.feature.cs 94 | 95 | 96 | SpecFlowSingleFileGenerator 97 | CreatePosts.feature.cs 98 | 99 | 100 | SpecFlowSingleFileGenerator 101 | PatchPosts.feature.cs 102 | 103 | 104 | SpecFlowSingleFileGenerator 105 | UpdatePosts.feature.cs 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/StepDefinitions/AssertionsSteps.cs: -------------------------------------------------------------------------------- 1 | using System.Dynamic; 2 | using System.Net.Http; 3 | using System.Text.RegularExpressions; 4 | using RestApiTesting.Framework.Cheetah.Helpers; 5 | using TechTalk.SpecFlow; 6 | 7 | namespace RestApiTesting.Framework.Cheetah.StepDefinitions 8 | { 9 | [Binding] 10 | public sealed class ResponseAssertionsSteps : Steps 11 | { 12 | private readonly ScenarioContext m_scenarioContext; 13 | 14 | public ResponseAssertionsSteps(ScenarioContext scenarioContext) 15 | { 16 | m_scenarioContext = scenarioContext; 17 | } 18 | 19 | [Then(@"the model ""(.*)"" should have (.*) parameters")] 20 | public void AndTheModelShouldHaveParameters(string responseBodyKey, int numExpectedParameters) 21 | { 22 | AssertionHelper.AssertNoOfModelParameters(m_scenarioContext, responseBodyKey, numExpectedParameters); 23 | } 24 | 25 | [Then(@"the model ""(.*)"" should match the following values:")] 26 | public void ThenTheModelShouldMatchTheFollowingValues(string actualModelKey, ExpandoObject expectedModel) 27 | { 28 | var actualModel = m_scenarioContext.Get(actualModelKey); 29 | AssertionHelper.AssertModelMatchTable(actualModel, expectedModel); 30 | } 31 | 32 | [Then(@"the response ""(.*)"" should have the status code ""(.*)""")] 33 | public void ThenTheResponseShouldHaveTheStatusCode(HttpResponseMessage response, string expectedStatusCode) 34 | { 35 | AssertionHelper.AssertStrings(response.ReasonPhrase, expectedStatusCode); 36 | } 37 | 38 | [Then(@"I compare ""(.*)"" of ""(.*)"" with ""(.*)""")] 39 | public void ThenICompareOfWith(string field, string objectKey, string expectedValueKey) 40 | { 41 | var expectedValue = m_scenarioContext.Get(expectedValueKey); 42 | object actualValue = TransformerHelper.GetActualValue(m_scenarioContext, field, objectKey); 43 | 44 | string expectedValueFixed = Regex.Replace(expectedValue.ToString(), @"\s+", string.Empty); 45 | string actualValueFixed = Regex.Replace(actualValue.ToString(), @"\s+", string.Empty); 46 | AssertionHelper.AssertStrings(actualValueFixed, expectedValueFixed); 47 | } 48 | 49 | [Then(@"the modified ""(.*)"" of ""(.*)"" should be modified ""(.*)""")] 50 | public void ThenTheModifiedOfShouldBeModified(string field, string objectKey, string expectedValueKey) 51 | { 52 | var expectedValue = m_scenarioContext.Get(expectedValueKey); 53 | object actualValue = TransformerHelper.GetActualValue(m_scenarioContext, field, objectKey); 54 | 55 | string expectedValueFixed = Regex.Replace(expectedValue.ToString(), @"\s+", string.Empty); 56 | string actualValueFixed = Regex.Replace(actualValue.ToString(), @"\s+", string.Empty); 57 | AssertionHelper.AssertStrings(actualValueFixed, expectedValueFixed); 58 | } 59 | 60 | [Then(@"the ""(.*)"" of ""(.*)"" should be ""(.*)""")] 61 | public void ThenTheOfShouldBe(string field, string objectKey, string expectedValueKey) 62 | { 63 | var expectedValue = m_scenarioContext.Get(expectedValueKey); 64 | object actualValue = TransformerHelper.GetActualValue(m_scenarioContext, field, objectKey); 65 | AssertionHelper.AssertStrings(actualValue.ToString(), expectedValue.ToString()); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/StepDefinitions/ClientSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | using System.Net.Http; 4 | using System.Threading.Tasks; 5 | using TechTalk.SpecFlow; 6 | using RestApiTesting.Framework.Cheetah.Helpers; 7 | 8 | namespace RestApiTesting.Framework.Cheetah.StepDefinitions 9 | { 10 | [Binding] 11 | public sealed class ClientSteps : Steps 12 | { 13 | private readonly ScenarioContext m_scenarioContext; 14 | 15 | public ClientSteps(ScenarioContext scenarioContext) 16 | { 17 | m_scenarioContext = scenarioContext; 18 | } 19 | 20 | [When(@"I send a ""([^""]*)"" request to ""([^""]*)"" using client ""([^""]*)"" and get the response ""([^""]*)""")] 21 | public async Task WhenISendARequestToUsingClientAndGetTheResponse(string apiRequestType, string uri, HttpClient client, string responseKey) 22 | { 23 | HttpResponseMessage response = await ClientHelper.GetResponse(uri, apiRequestType, client, null); 24 | m_scenarioContext.Add(responseKey, response); 25 | } 26 | 27 | [When(@"I send a ""([^""]*)"" request to ""([^""]*)"" with model ""([^""]*)"" using client ""([^""]*)"" and get the response ""([^""]*)""")] 28 | public async Task WhenISendARequestToWithModelUsingClientAndGetTheResponse(string apiRequestType, string uri, string modelKey, string clientKey, string responseKey) 29 | { 30 | var model = m_scenarioContext.Get(modelKey); 31 | var client = m_scenarioContext.Get(clientKey); 32 | HttpResponseMessage response = await ClientHelper.GetResponse(uri, apiRequestType, client, model); 33 | m_scenarioContext.Add(responseKey, response); 34 | 35 | } 36 | 37 | [Given(@"I have a client ""(.*)""")] 38 | public void GivenIHaveAClient(string httpClientKey) 39 | { 40 | var uri = new Uri(ConfigurationHelper.TestApiUrl); 41 | HttpClient client = ClientHelper.GetClient(uri); 42 | m_scenarioContext.Add(httpClientKey, client); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/StepDefinitions/InputDataSteps.cs: -------------------------------------------------------------------------------- 1 | using System.Dynamic; 2 | using System.Net.Http; 3 | using TechTalk.SpecFlow; 4 | 5 | namespace RestApiTesting.Framework.Cheetah.StepDefinitions 6 | { 7 | [Binding] 8 | public sealed class InputDataSteps : Steps 9 | { 10 | private readonly ScenarioContext m_scenarioContext; 11 | 12 | public InputDataSteps(ScenarioContext scenarioContext) 13 | { 14 | m_scenarioContext = scenarioContext; 15 | } 16 | 17 | [When(@"I get the content ""(.*)"" of the response ""(.*)""")] 18 | public void WhenIGetTheContentOfTheResponse(string key, string responseMessageKey) 19 | { 20 | var responseMessage = m_scenarioContext.Get(responseMessageKey); 21 | ExpandoObject contentObject = responseMessage.Content.ReadAsAsync().GetAwaiter().GetResult(); 22 | ScenarioContext.Add(key, contentObject); 23 | } 24 | 25 | [Given(@"I have a model ""(.[a-zA-Z0-9]+)"" with the following values:")] 26 | public void GivenIHaveAModelWithTheFollowingValues(string key, ExpandoObject model) 27 | { 28 | ScenarioContext.Add(key, model); 29 | } 30 | 31 | [Given(@"I have a string ""(.*)"" named ""(.*)""")] 32 | public void GivenIHaveAStringNamed(string value, string key) 33 | { 34 | ScenarioContext.Add(key, value); 35 | } 36 | 37 | [Given(@"I have an int ""(.*)"" named ""(.*)""")] 38 | public void GivenIHaveAIntNamed(int value, string key) 39 | { 40 | ScenarioContext.Add(key, value); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "TestApiUrl": "https://jsonplaceholder.typicode.com" 3 | } -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/JSONPlaceholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/JSONPlaceholder.jpg -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/build.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/c-sharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/c-sharp.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/cheetah.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/cheetah.jpg -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/fluentassertions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/fluentassertions.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/netcore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/netcore.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/social-preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/social-preview.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/specflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/specflow.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/specflowextension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/specflowextension.png -------------------------------------------------------------------------------- /RestApiTesting.Framework.Cheetah/images/testexplorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programmingwithbangal/RestApiTesting.Framework.Cheetah/3da93d6e8114b070ea28e4979c1d723675293ac2/RestApiTesting.Framework.Cheetah/images/testexplorer.png --------------------------------------------------------------------------------