Skip to content

Quiz #2 - To be clearer than Ayende #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ java/build
java/.classpath
java/.project
java/.settings
*.class
*.class

dotnet/TestResult.xml
dotnet/src/**/Bin/**
dotnet/src/**/Obj/**
dotnet/lib
dotnet/*.csproj.user
dotnet/src/*.suo
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ Use the language you prefer: Java, C#, Python, what ever you want.
Just provide enough tests in order to make your intents clear.



##Java

### Run the tests

On *nix run

gradle test

On Windows

./gradlew test
## How can I contribute?
Submit a new Quiz.
Or, propose a solution to one of the open Quizzes.
12 changes: 12 additions & 0 deletions dotnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SinglePath.NET
==============

Build
-----
Crack open a terminal and run

```build.cmd```.

The build script will download all the dependencies with NuGet, so an Internet connection is required.

The script will then build the solution and run the NUnit test suite.
1 change: 1 addition & 0 deletions dotnet/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tools\psake\psake.cmd
31 changes: 31 additions & 0 deletions dotnet/default.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Framework "4.0"

Properties {
$build_dir = Split-Path $psake.build_script_file
$build_cfg = "Debug"
}

Task default -Depends Test

Task Deps {
Exec { & "$build_dir\tools\nuget" install NUnit.Runners -Version "2.6.0.12051" -ExcludeVersion -OutputDirectory "$build_dir\tools" }

Get-ChildItem "$build_dir\src\*\packages.config" -Exclude .nuget | ForEach-Object {
Write-Host "Downloading packages defined in $_"
Exec { & "$build_dir\tools\nuget" install $_ -OutputDirectory "$build_dir\lib" }
}
}

Task Compile -Depends Deps {
Exec { msbuild "$build_dir\src\SinglePath.sln" /t:Build /p:Configuration=$build_cfg /v:quiet /nologo }
}

Task Test -Depends Compile {
$TestDlls = Get-ChildItem "$build_dir\src\*\bin\$build_cfg\*.Tests.dll"
Exec { & "$build_dir\tools\NUnit.Runners\tools\nunit-console.exe" /nologo /noresult @TestDlls }
}


Task Clean {
Exec { hg purge --all --repository $build_dir }
}
24 changes: 24 additions & 0 deletions dotnet/src/SinglePath.Tests/FieldsToFetchTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SharpTestsEx;
using SinglePath;

namespace SinglePathTests
{
[TestFixture]
class FieldsToFetchTests
{
[Test]
public void EnsureHasField_should_add_a_field()
{
var sut = new FieldsToFetch();

sut.EnsureHasField("foo");

sut.Fields.Should().Contain("foo");
}
}
}
36 changes: 36 additions & 0 deletions dotnet/src/SinglePath.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SinglePathTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SinglePathTests")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3696614f-4e35-4e66-9e42-33561a860972")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
73 changes: 73 additions & 0 deletions dotnet/src/SinglePath.Tests/SinglePath.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SinglePath.Tests</RootNamespace>
<AssemblyName>SinglePath.Tests</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>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="NSubstitute">
<HintPath>..\..\lib\NSubstitute.1.6.1.0\lib\NET40\NSubstitute.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="SharpTestsEx">
<HintPath>..\..\lib\SharpTestsEx.1.1.1\lib\SharpTestsEx.dll</HintPath>
</Reference>
<Reference Include="SharpTestsEx.Mvc">
<HintPath>..\..\lib\SharpTestsEx.1.1.1\lib\SharpTestsEx.Mvc.dll</HintPath>
</Reference>
<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" />
<Compile Include="FieldsToFetchTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SinglePath\SinglePath.csproj">
<Project>{EE448599-379E-41E5-A1CD-F8433F49A33B}</Project>
<Name>SinglePath</Name>
</ProjectReference>
</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>
6 changes: 6 additions & 0 deletions dotnet/src/SinglePath.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NSubstitute" version="1.6.1.0" targetFramework="net40" />
<package id="NUnit" version="2.6.3" targetFramework="net40" />
<package id="SharpTestsEx" version="1.1.1" targetFramework="net40" />
</packages>
26 changes: 26 additions & 0 deletions dotnet/src/SinglePath.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C# Express 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SinglePath", "SinglePath\SinglePath.csproj", "{EE448599-379E-41E5-A1CD-F8433F49A33B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SinglePath.Tests", "SinglePath.Tests\SinglePath.Tests.csproj", "{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE448599-379E-41E5-A1CD-F8433F49A33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE448599-379E-41E5-A1CD-F8433F49A33B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE448599-379E-41E5-A1CD-F8433F49A33B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE448599-379E-41E5-A1CD-F8433F49A33B}.Release|Any CPU.Build.0 = Release|Any CPU
{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5EBB22A-EC11-40DA-8E7D-C7A05A3D19C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
50 changes: 50 additions & 0 deletions dotnet/src/SinglePath/FieldsToFetch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SinglePath
{
public class FieldsToFetch
{
private HashSet<string> ensuredFieldNames;
private readonly HashSet<string> fieldsToFetch;

public IEnumerable<string> Fields
{
get
{
HashSet<string> fieldsWeMustReturn = ensuredFieldNames == null
? new HashSet<string>()
: new HashSet<string>(ensuredFieldNames);
foreach (var fieldToReturn in GetFieldsToReturn())
{
fieldsWeMustReturn.Remove(fieldToReturn);
yield return fieldToReturn;
}

foreach (var field in fieldsWeMustReturn)
{
yield return field;
}
}
}

private IEnumerable<string> GetFieldsToReturn()
{
if (fieldsToFetch == null)
yield break;
foreach (var field in fieldsToFetch)
{
yield return field;
}
}

public void EnsureHasField(string ensuredFieldName)
{
if (ensuredFieldNames == null)
ensuredFieldNames = new HashSet<string>();
ensuredFieldNames.Add(ensuredFieldName);
}
}
}
36 changes: 36 additions & 0 deletions dotnet/src/SinglePath/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SinglePath")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SinglePath")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("28522ce2-d217-4ed7-8402-8e384e652b64")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
54 changes: 54 additions & 0 deletions dotnet/src/SinglePath/SinglePath.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EE448599-379E-41E5-A1CD-F8433F49A33B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SinglePath</RootNamespace>
<AssemblyName>SinglePath</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>
</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>
</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="FieldsToFetch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>
Loading