Skip to content

Commit

Permalink
Adds empty projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Dec 6, 2012
1 parent 3b9d1f2 commit 98fbb91
Show file tree
Hide file tree
Showing 25 changed files with 1,074 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Src/AcceptanceTests/AcceptanceTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{649C13AC-144B-44FF-94CB-E561459FC3D8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Thoughtology.GameOfLife.AcceptanceTests</RootNamespace>
<AssemblyName>Thoughtology.GameOfLife.AcceptanceTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Scenarios\" />
<ProjectReference Include="..\Web\Web.csproj">
<Project>{5723acc3-2b8b-49e7-91fb-e042acc61376}</Project>
<Name>Web</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
26 changes: 26 additions & 0 deletions Src/AcceptanceTests/Hooks/RegisterAutoData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BoDi;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoRhinoMock;
using TechTalk.SpecFlow;

namespace Cerdo.CNA.Lennart.AcceptanceTests.Hooks
{
[Binding]
public class RegisterAutoData
{
private readonly IObjectContainer _container;

public RegisterAutoData(IObjectContainer container)
{
_container = container;
}

[BeforeScenario]
public void RegisterAFixtureInstance()
{
var fixture = new Fixture();
fixture.Customize(new AutoRhinoMockCustomization());
_container.RegisterInstanceAs<IFixture>(fixture);
}
}
}
33 changes: 33 additions & 0 deletions Src/AcceptanceTests/Hooks/RegisterDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Configuration;
using BoDi;
using Cerdo.CNA.Lennart.Common.Infrastructure;
using Cerdo.CNA.Lennart.Web.App_Start;
using TechTalk.SpecFlow;

namespace Cerdo.CNA.Lennart.AcceptanceTests.Hooks
{
[Binding]
public class RegisterDatabase
{
private readonly IObjectContainer _container;

public RegisterDatabase(IObjectContainer container)
{
_container = container;
}

[BeforeScenario("DependsOnDatabase")]
public void RegisterADatabaseInstance()
{
var connString = GetConnectionStringFromConfig();
_container.RegisterInstanceAs<IDatabase>(new OrmDatabase(connString));
}

private static string GetConnectionStringFromConfig()
{
return ConfigurationManager
.ConnectionStrings[WebApiConfig.ConnectionStringName]
.ConnectionString;
}
}
}
34 changes: 34 additions & 0 deletions Src/AcceptanceTests/Hooks/WebServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using CassiniDev;
using TechTalk.SpecFlow;

namespace Cerdo.CNA.Lennart.AcceptanceTests.Hooks
{
[Binding]
public static class WebServer
{
private const string HostName = "localhost";
private const int Port = 8090;
private const string ApplicationPath = @"..\..\..\Cerdo.CNA.Lennart.Web";
private static CassiniDevServer server;

public static Uri RootUri
{
get { return new Uri(string.Format("http://{0}:{1}", HostName, Port)); }
}

[BeforeTestRun]
private static void Start()
{
server = new CassiniDevServer();
server.StartServer(ApplicationPath, Port, "/", HostName);
}

[AfterTestRun]
private static void Stop()
{
server.StopServer();
server.Dispose();
}
}
}
11 changes: 11 additions & 0 deletions Src/AcceptanceTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("GameOfLife.AcceptanceTests")]
[assembly: AssemblyCompany("Thoughtology")]
[assembly: AssemblyProduct("GameOfLife")]
[assembly: AssemblyCopyright("Creative Commons Attribution 3.0 Unported License")]
[assembly: ComVisible(false)]
[assembly: Guid("7c887bb1-816f-4076-9655-4ecca27e5928")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
83 changes: 83 additions & 0 deletions Src/AcceptanceTests/Settings.StyleCop
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="FileMustHaveHeader">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EnumerationItemsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="UseStringEmptyForEmptyStrings">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SplitParametersMustStartOnLineAfterDeclaration">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.MaintainabilityRules">
<Rules>
<Rule Name="AccessModifierMustBeDeclared">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldsMustBePrivate">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="FieldNamesMustNotContainUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>at</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.LayoutRules">
<Rules>
<Rule Name="ClosingCurlyBracketsMustNotBePrecededByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StatementMustNotBeOnSingleLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="CurlyBracketsMustNotBeOmitted">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>
102 changes: 102 additions & 0 deletions Src/AcceptanceTests/Steps/AuthenticateUsers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Net.Http;
using Cerdo.CNA.Lennart.Common.Infrastructure;
using Cerdo.CNA.Lennart.Web.Models.Login;
using NUnit.Framework;
using Ploeh.AutoFixture;
using TechTalk.SpecFlow;

namespace Cerdo.CNA.Lennart.AcceptanceTests.Steps
{
[Binding]
public class AuthenticateUsers
{
private readonly IFixture _autoData;
private readonly dynamic _db;
private readonly Credentials _model;
private HttpResponseMessage _response;

public AuthenticateUsers(IDatabase database, IFixture autoData)
{
_autoData = autoData;
_db = database.Open();
_model = autoData.CreateAnonymous<Credentials>();
}

[Given]
public void Given_a_user_account_exists()
{
_db.Users.Insert(Username: _model.Username, Password: _model.Password);
}

[When]
public void When_I_login_with_valid_credentials()
{
_response = WebClient.PostAsJson("/api/login", _model);
}

[Then]
public void Then_I_should_be_authenticated()
{
GetResponseContentAsString().ShouldContain("\"IsAuthenticated\":true");
}

[Then]
public void Then_it_should_set_the_number_of_failed_authentication_attempts_to_zero()
{
GetFailedLoginAttemptsForUser().ShouldEqual(0);
}

[When]
public void When_I_login_with_invalid_credentials()
{
_response = WebClient.PostAsJson("/api/login", _autoData.CreateAnonymous<Credentials>());
}

[When]
public void When_I_login_with_an_invalid_password()
{
_model.Password = _autoData.CreateAnonymous<string>();
_response = WebClient.PostAsJson("/api/login", _model);
}

[Then]
public void Then_I_should_receive_an_authentication_failed_error()
{
GetResponseContentAsString().ShouldContain("\"IsAuthenticated\":false");
}

[Then]
public void Then_it_should_increment_the_number_of_failed_authentication_attempts()
{
GetFailedLoginAttemptsForUser().ShouldEqual(1);
}

[Given]
public void Given_I_have_made_NUMBER_failed_login_attempts(int number)
{
_db.Users.Insert(Username: _model.Username, Password: _model.Password, FailedLoginAttempts: number);
}

[Then]
public void Then_I_should_receive_an_error_message_saying_that_I_have_NUMBER_login_attempts_left(int number)
{
GetResponseContentAsString().ShouldContain(string.Format("\"AvailableAttempts\":{0}", number));
}

[Then]
public void Then_I_should_receive_an_error_message_saying_that_I_my_account_is_blocked()
{
GetResponseContentAsString().ShouldContain("\"AccountBlocked\":true");
}

private string GetResponseContentAsString()
{
return _response.Content.ReadAsStringAsync().Result;
}

private int GetFailedLoginAttemptsForUser()
{
return (int)_db.Users.FindByUsername(_model.Username).FailedLoginAttempts;
}
}
}
33 changes: 33 additions & 0 deletions Src/AcceptanceTests/Steps/WebClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Net.Http;
using System.Net.Http.Headers;
using Cerdo.CNA.Lennart.AcceptanceTests.Hooks;

namespace Cerdo.CNA.Lennart.AcceptanceTests.Steps
{
public class WebClient
{
private static HttpClient client;

static WebClient()
{
InitializeHttpClient();
}

public static HttpResponseMessage PostAsJson(string uri, object data)
{
return client.PostAsJsonAsync(uri, data).Result;
}

private static void InitializeHttpClient()
{
client = new HttpClient { BaseAddress = WebServer.RootUri };
AddAcceptJsonHeader();
}

private static void AddAcceptJsonHeader()
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
}
}
Loading

0 comments on commit 98fbb91

Please sign in to comment.