Skip to content
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

Solution implemented by Rafał Wiktorek #59

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions BDD/BerlinClockFeatureSteps.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
using System;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using BerlinClock.Converters;

namespace BerlinClock
{
[Binding]
public class TheBerlinClockSteps
{
private ITimeConverter berlinClock = new TimeConverter();
private String theTime;
private readonly ITimeConverter _berlinClock = new TimeConverter();
private string _theTime;


[When(@"the time is ""(.*)""")]
public void WhenTheTimeIs(string time)
{
theTime = time;
_theTime = time;
}

[Then(@"the clock should look like")]
public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput)
{
Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput);
Assert.AreEqual(_berlinClock.ConvertTime(_theTime), theExpectedBerlinClockOutput);
}

}
Expand Down
76 changes: 76 additions & 0 deletions BerlinClock.Tests/BerlinClock.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
<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>{74F9D721-6839-4776-97C9-718145CED3D0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BerlinClock.Tests</RootNamespace>
<AssemblyName>BerlinClock.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Builders\YellowLampRowBuilderTests.cs" />
<Compile Include="Extensions\IntExtensionsTests.cs" />
<Compile Include="Extensions\StringExtensionsTests.cs" />
<Compile Include="Parsers\TimeParserExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderers\BerlinClockRowRendererTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BerlinClock.csproj">
<Project>{0451204d-bf86-43e1-b560-fc9ac830b9a9}</Project>
<Name>BerlinClock</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.16.1\build\net35\NUnit3TestAdapter.props'))" />
</Target>
</Project>
30 changes: 30 additions & 0 deletions BerlinClock.Tests/Builders/YellowLampRowBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using BerlinClock.Builders;
using BerlinClock.Models;
using NUnit.Framework;

namespace BerlinClock.Tests.Builders
{
[TestFixture]
public class YellowLampRowBuilderTests
{
private YellowLampRowBuilder _sut;

[SetUp]
public void SetUp()
{
_sut = new YellowLampRowBuilder();
}

[Test]
public void Build_ShouldReturnDifferentResult_WhenOddAndEvenNumbersAreGiven()
{
var oddValue = 1;
var evenValue = 2;

var resultForOddValue = _sut.Build(new Time(0, 0, oddValue));
var resultForEvenValue = _sut.Build(new Time(0, 0, evenValue));

Assert.That(resultForEvenValue, Is.Not.EqualTo(resultForOddValue));
}
}
}
29 changes: 29 additions & 0 deletions BerlinClock.Tests/Extensions/IntExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using BerlinClock.Extensions;
using NUnit.Framework;

namespace BerlinClock.Tests.Extensions
{
[TestFixture]
public class IntExtensionsTests
{
[Test]
public void IsEven_ShouldReturnTrue_WhenEvenNumberIsGiven()
{
var evenNumber = 2;

var result = evenNumber.IsEven();

Assert.That(result, Is.True);
}

[Test]
public void IsEven_ShouldReturnFalse_WhenOddNumberIsGiven()
{
var oddNumber = 3;

var result = oddNumber.IsEven();

Assert.That(result, Is.False);
}
}
}
52 changes: 52 additions & 0 deletions BerlinClock.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BerlinClock.Extensions;
using NUnit.Framework;

namespace BerlinClock.Tests.Extensions
{
[TestFixture]
public class StringExtensionsTests
{
private string _value;
private char _valueToReplace;
private char _newValue;

[SetUp]
public void SetUp()
{
_value = "OOOOOOO";
_valueToReplace = 'O';
_newValue = 'X';
}

[TestCase(null)]
[TestCase("")]
public void ReplaceEveryNthOccurence_ShouldReturnSameValue_WhenNullOrEmptyStringIsGiven(string value)
{
var result = value.ReplaceEveryNthOccurence(_valueToReplace, _newValue, 1);

Assert.That(result, Is.EqualTo(value));
}

[Test]
public void ReplaceEveryNthOccurence_ShouldNotReplaceAnyValue_WhenNValueIsOutOfRange()
{
var outOfRangeNValue = _value.Length + 1;

var result = _value.ReplaceEveryNthOccurence(_valueToReplace, _newValue, outOfRangeNValue);

Assert.That(result, Is.EqualTo(_value));
}

[Test]
public void ReplaceEveryNthOccurence_ShouldReplaceEvery3thOccurence_WhenValueOccurred()
{
var value = "OOROOOOOO";
var expectedValue = "OOROOXOOX";
var n = 3;

var result = value.ReplaceEveryNthOccurence(_valueToReplace, _newValue, n);

Assert.That(result, Is.EqualTo(expectedValue));
}
}
}
47 changes: 47 additions & 0 deletions BerlinClock.Tests/Parsers/TimeParserExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using BerlinClock.Parsers;
using NUnit.Framework;
using System;

namespace BerlinClock.Tests.Parsers
{
[TestFixture]
public class TimeParserExtensions
{
private TimeParser _sut;

[SetUp]
public void SetUp()
{
_sut = new TimeParser();
}

[Test]
public void Parse_ShouldThrowException_WhenGivenValueIsNull()
{
Assert.Throws<Exception>(() => _sut.Parse(null));
}

[Test]
public void Parse_ShouldThrowException_WhenWrongTimeFormatIsGiven()
{
var wrongTime = "123400";

Assert.Throws<Exception>(() => _sut.Parse(wrongTime));
}

[Test]
public void Parse_ShouldCreateCorrectInstance_WhenCorrectTimeIsGiven()
{
var hour = 12;
var minute = 45;
var second = 30;
var timeValue = $"{hour}:{minute}:{second}";

var result = _sut.Parse(timeValue);

Assert.That(result.Hour, Is.EqualTo(hour));
Assert.That(result.Minute, Is.EqualTo(minute));
Assert.That(result.Second, Is.EqualTo(second));
}
}
}
20 changes: 20 additions & 0 deletions BerlinClock.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("BerlinClock.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BerlinClock.Tests")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("74f9d721-6839-4776-97c9-718145ced3d0")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
79 changes: 79 additions & 0 deletions BerlinClock.Tests/Renderers/BerlinClockRowRendererTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using BerlinClock.Models;
using BerlinClock.Renderers;
using NUnit.Framework;
using System;

namespace BerlinClock.Tests.Renderers
{
[TestFixture]
public class BerlinClockRowRendererTests
{
private BerlinClockRowRenderer _sut;

[SetUp]
public void SetUp()
{
_sut = new BerlinClockRowRenderer();
}

[Test]
public void Render_ShouldNotModifyResult_WhenAdditionalFormattingIsNull()
{
var expectedValue = "XO";
var request = new BerlinClockRendererRequest
{
AdditionalFormatting = null,
TurnedOnLampSign = 'X',
AmountOfTurnedOnLamps = 1,
AmountOfTurnedOffLamps = 1
};

var result = _sut.Render(request);

Assert.That(result, Is.EqualTo(expectedValue));
}

[Test]
public void Render_ShouldModifyResult_WhenAdditionalFormattingIsGiven()
{
var expectedValue = "TEST";
var request = new BerlinClockRendererRequest
{
AdditionalFormatting = (row) => expectedValue,
TurnedOnLampSign = 'X',
AmountOfTurnedOnLamps = 1,
AmountOfTurnedOffLamps = 1
};

var result = _sut.Render(request);

Assert.That(result, Is.EqualTo(expectedValue));
}

[Test]
public void Render_ShouldThrowException_WhenNegativeTurnedOnLampsValueIsGiven()
{
var request = new BerlinClockRendererRequest
{
TurnedOnLampSign = 'X',
AmountOfTurnedOnLamps = -1,
AmountOfTurnedOffLamps = 1
};

Assert.Throws<Exception>(() => _sut.Render(request));
}

[Test]
public void Render_ShouldThrowException_WhenNegativeTurnedOffLampsValueIsGiven()
{
var request = new BerlinClockRendererRequest
{
TurnedOnLampSign = 'X',
AmountOfTurnedOnLamps = 1,
AmountOfTurnedOffLamps = -1
};

Assert.Throws<Exception>(() => _sut.Render(request));
}
}
}
5 changes: 5 additions & 0 deletions BerlinClock.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.12.0" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="3.16.1" targetFramework="net45" developmentDependency="true" />
</packages>
Loading