Skip to content

Commit

Permalink
Add project baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Jun 14, 2021
1 parent 954c3ee commit c8480b3
Show file tree
Hide file tree
Showing 174 changed files with 27,216 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"specflow.plus.livingdoc.cli": {
"version": "3.7.141",
"commands": [
"livingdoc"
]
}
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
documentation/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down Expand Up @@ -258,4 +259,6 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
*.feature.cs
LivingDoc.html
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013-2021 Spec Solutions and Gaspar Nagy, https://www.specsolutions.eu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Spec Overflow - Sample application for the SpecFlow Masterclass

A simple Q&A site where people can ask questions and post answers.

**Features:**

* User management & Home page
* Questions
* List & Details
* Ask & Answer
* Vote questions & answers

**Technology:**

* ASP.NET MVC
* Backend with REST API
* Simple web frontend accessing the backend using basic jQuery

**Open-source:** Explore, fork, play, contribute!


## See Also

* [SpecFlow Masterclass page at specflow.org](https://specflow.org/community/webinars/masterclass/)
* [BDD & SpecFlow training services by Gaspar Nagy](https://www.specsolutions.eu/courses/)

## License

The Spec Overflow sample application is licensed under the [MIT license](LICENSE).

Copyright (c) 2013-2021 Spec Solutions and Gaspar Nagy, https://www.specsolutions.eu
37 changes: 37 additions & 0 deletions SpecFlowMasterClass.SpecOverflow.ControllerAutomation.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlowMasterClass.SpecOverflow.Web", "SpecFlowMasterClass.SpecOverflow.Web\SpecFlowMasterClass.SpecOverflow.Web.csproj", "{BCC4E7F9-9CD9-4E71-8F74-ABA87623FF34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlowMasterClass.SpecOverflow.Specs.Controller", "SpecFlowMasterClass.SpecOverflow.Specs.Controller\SpecFlowMasterClass.SpecOverflow.Specs.Controller.csproj", "{4472FA94-91CF-481F-8527-1CF44A7D0D9F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlowMasterClass.SpecOverflow.Tests", "SpecFlowMasterClass.SpecOverflow.Tests\SpecFlowMasterClass.SpecOverflow.Tests.csproj", "{BEACB170-C8E2-4AFE-86CE-F2723B496DBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BCC4E7F9-9CD9-4E71-8F74-ABA87623FF34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCC4E7F9-9CD9-4E71-8F74-ABA87623FF34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCC4E7F9-9CD9-4E71-8F74-ABA87623FF34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCC4E7F9-9CD9-4E71-8F74-ABA87623FF34}.Release|Any CPU.Build.0 = Release|Any CPU
{4472FA94-91CF-481F-8527-1CF44A7D0D9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4472FA94-91CF-481F-8527-1CF44A7D0D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4472FA94-91CF-481F-8527-1CF44A7D0D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4472FA94-91CF-481F-8527-1CF44A7D0D9F}.Release|Any CPU.Build.0 = Release|Any CPU
{BEACB170-C8E2-4AFE-86CE-F2723B496DBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEACB170-C8E2-4AFE-86CE-F2723B496DBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEACB170-C8E2-4AFE-86CE-F2723B496DBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEACB170-C8E2-4AFE-86CE-F2723B496DBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {02C8B3DB-D290-40F6-88DF-38EABFF39937}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Net;
using FluentAssertions;
using SpecFlowMasterClass.SpecOverflow.Specs.API.Support;
using SpecFlowMasterClass.SpecOverflow.Web.Models;
using SpecFlowMasterClass.SpecOverflow.Specs.Support;
using SpecFlowMasterClass.SpecOverflow.Web.Utils;

namespace SpecFlowMasterClass.SpecOverflow.Specs.API.Drivers
{
public class AuthApiDriver
{
public class LoginDriver : ActionAttempt<LoginInputModel, string>
{
private readonly WebApiContext _webApiContext;

public LoginDriver(WebApiContext webApiContext)
{
_webApiContext = webApiContext;
}

public event Action<LoginInputModel, string> OnAuthenticated;

protected override string DoAction(LoginInputModel loginInput)
{
var response = _webApiContext.ExecutePost<string>("api/auth", loginInput);
response.StatusCode.Should().Be(HttpStatusCode.OK);
var authToken = response.ResponseData;
OnAuthenticated?.Invoke(loginInput, authToken);
return authToken;
}
}

private readonly WebApiContext _webApiContext;

public LoginDriver Login { get; }

public AuthApiDriver(WebApiContext webApiContext, LoginDriver login)
{
_webApiContext = webApiContext;
Login = login;
}

public UserReferenceModel GetCurrentUser()
{
try
{
return _webApiContext.ExecuteGet<UserReferenceModel>("/api/auth");
}
catch (HttpResponseException e) when (e.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using SpecFlowMasterClass.SpecOverflow.Specs.API.Support;
using SpecFlowMasterClass.SpecOverflow.Web.Models;

namespace SpecFlowMasterClass.SpecOverflow.Specs.API.Drivers
{
public class HomeApiDriver
{
private readonly WebApiContext _webApiContext;

public HomeApiDriver(WebApiContext webApiContext)
{
_webApiContext = webApiContext;
}

public HomePageModel GetHomePageModel()
{
return _webApiContext.ExecuteGet<HomePageModel>("/api/home");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using SpecFlowMasterClass.SpecOverflow.Specs.API.Support;
using SpecFlowMasterClass.SpecOverflow.Specs.Support;
using SpecFlowMasterClass.SpecOverflow.Web.Models;

namespace SpecFlowMasterClass.SpecOverflow.Specs.API.Drivers
{
public class QuestionApiDriver
{
private readonly WebApiContext _webApiContext;
public ActionAttempt<AskInputModel, QuestionSummaryModel> AskQuestion { get; }

public QuestionApiDriver(WebApiContext webApiContext, ActionAttemptFactory actionAttemptFactory)
{
_webApiContext = webApiContext;
AskQuestion = actionAttemptFactory.CreateWithStatusCheck<AskInputModel, QuestionSummaryModel>(
nameof(AskQuestion),
askInput => webApiContext.ExecutePost<QuestionSummaryModel>("/api/question", askInput));
}

public QuestionDetailModel GetQuestionDetails(Guid questionId)
{
return _webApiContext.ExecuteGet<QuestionDetailModel>($"/api/question/{questionId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using SpecFlowMasterClass.SpecOverflow.Specs.API.Support;
using SpecFlowMasterClass.SpecOverflow.Specs.Support;
using SpecFlowMasterClass.SpecOverflow.Web.Models;

namespace SpecFlowMasterClass.SpecOverflow.Specs.API.Drivers
{
public class UserApiDriver
{
public ActionAttempt<RegisterInputModel, UserReferenceModel> Register { get; }

public UserApiDriver(WebApiContext webApiContext, ActionAttemptFactory actionAttemptFactory)
{
Register = actionAttemptFactory.CreateWithStatusCheck<RegisterInputModel, UserReferenceModel>(
nameof(Register),
registerInput => webApiContext.ExecutePost<UserReferenceModel>("/api/user", registerInput));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@webapi
Feature: Authentication

Rule: Successful login authorizes for member-only services

Scenario: User logs in with valid credentials
Given there is a user registered with user name "Trillian" and password "139139"
When the user attempts to log in with user name "Trillian" and password "139139"
Then the login attempt should be successful
And the user should be authenticated
29 changes: 29 additions & 0 deletions SpecFlowMasterClass.SpecOverflow.Specs.API/Features/Home.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@webapi
Feature: Home

Rule: A positive message should be shown on the home page

Scenario: Welcome message is shown on home page
When the user checks the home page
Then the home page main message should be: "Welcome to Spec Overflow!"

Rule: The user name should be shown on the home page if logged in

Scenario: The logged-in user name is shown on home page
Given the user is authenticated
When the user checks the home page
Then the user name of the user should be on the home page

Rule: The latest 10 question should be shown on the home page

Scenario: The latest question is shown on home page with details
Given there is a question just asked as
| title | votes | answers | views | asked by |
| How to write better BDD scenarios? | 0 | 0 | 1 | Ford |
When the user checks the home page
Then the question should be listed among the latest questions as above

Scenario: The latest 10 questions are shown on home page
Given there are 12 questions asked
When the user checks the home page
Then the home page should contain the 10 latest questions ordered
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@webapi
Feature: Asking questions

Rule: Should be able to ask a question

Scenario: The question is posted
Given user Marvin is authenticated
When the user asks a question as
| title | body | tags |
| How to write better BDD scenarios? | I need help | Gherkin,BDD |
Then the question should be posted as above
And the question meta data should be
| votes | asked at | asked by |
| 0 | now | Marvin |

Rule: Only authenticated users can ask questions

Scenario: Anonymous user cannot answer questions
Given the user is not authenticated
When the user attempts to ask a question
Then the ask attempt should fail with error "not-logged-in"

Rule: The question title and body are mandatory

Scenario Outline: Cannot post an answer with empty content
Given user Marvin is authenticated
When the user attempts to ask a question as
| title | body |
| <title> | <body> |
Then the ask attempt should fail with error "Title and Body cannot be empty"
Examples:
| description | title | body |
| no title | | I need help |
| no body | How to write better BDD scenarios? | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@webapi
Feature: Registration

Describes the behavior of the registration process.

There are many rules involved (e.g. related to user name and password validity
or password and re-entered password match). For the sake of the sample we only
work with a single rule: Should be able to register with user name and password.

Rule: Should be able to register with user name and password

Scenario: User registers successfully
When the user attempts to register with user name "Trillian" and password "139139"
Then the registration should be successful


Loading

0 comments on commit c8480b3

Please sign in to comment.