From 62fa51d8b5ec52f54bfcf76d5fd63402d42b733d Mon Sep 17 00:00:00 2001 From: konradgadecki Date: Sun, 11 Nov 2018 18:50:47 +0100 Subject: [PATCH] Added unit tests --- .gitignore | 335 ++++++++++++++++++ TestNinja/.DS_Store | Bin 0 -> 6148 bytes .../Properties/AssemblyInfo.cs | 20 ++ .../TestNinja.UnitTests.csproj | 76 ++++ .../UnitTests/CustomerControllerTests.cs | 27 ++ .../UnitTests/DemeritPointsCalculatorTests.cs | 55 +++ .../UnitTests/ErrorLoggerTests.cs | 44 +++ .../UnitTests/FizzBuzzTests.cs | 44 +++ .../UnitTests/HtmlFormatterTests.cs | 32 ++ .../UnitTests/MathTests.cs | 74 ++++ .../UnitTests/ReservationTests.cs | 65 ++++ .../UnitTests/StackTests.cs | 85 +++++ TestNinja/TestNinja.UnitTests/packages.config | 4 + TestNinja/TestNinja.sln | 22 ++ TestNinja/TestNinja/.DS_Store | Bin 0 -> 6148 bytes TestNinja/TestNinja/App.config | 6 + .../Fundamentals/CustomerController.cs | 19 + .../TestNinja/Fundamentals/DateHelper.cs | 12 + .../Fundamentals/DemeritPointsCalculator.cs | 23 ++ .../TestNinja/Fundamentals/ErrorLogger.cs | 25 ++ TestNinja/TestNinja/Fundamentals/FizzBuzz.cs | 19 + .../TestNinja/Fundamentals/HtmlFormatter.cs | 10 + TestNinja/TestNinja/Fundamentals/Math.cs | 24 ++ .../TestNinja/Fundamentals/PhoneNumber.cs | 38 ++ TestNinja/TestNinja/Fundamentals/PowersOf2.cs | 29 ++ .../TestNinja/Fundamentals/Reservation.cs | 18 + TestNinja/TestNinja/Fundamentals/Stack.cs | 40 +++ TestNinja/TestNinja/Mocking/.DS_Store | Bin 0 -> 6148 bytes TestNinja/TestNinja/Mocking/BookingHelper.cs | 48 +++ .../TestNinja/Mocking/EmployeeController.cs | 44 +++ .../TestNinja/Mocking/HousekeeperHelper.cs | 165 +++++++++ .../TestNinja/Mocking/InstallerHelper.cs | 28 ++ TestNinja/TestNinja/Mocking/OrderService.cs | 30 ++ TestNinja/TestNinja/Mocking/Product.cs | 20 ++ TestNinja/TestNinja/Mocking/VideoService.cs | 51 +++ .../TestNinja/Properties/AssemblyInfo.cs | 36 ++ TestNinja/TestNinja/TestNinja.csproj | 97 +++++ TestNinja/TestNinja/packages.config | 7 + csharp.UnitTests/Properties/AssemblyInfo.cs | 20 ++ csharp.UnitTests/Tests/ApprovalTest.cs | 30 ++ csharp.UnitTests/Tests/GildedRoseTest.cs | 187 ++++++++++ csharp.UnitTests/csharp.UnitTests.csproj | 70 ++++ csharp.UnitTests/packages.config | 4 + csharp/GildedRose.cs | 57 +-- csharp/Item.cs | 2 +- csharp/Program.cs | 38 +- csharp/csharp.csproj | 8 +- csharp/csharp.sln | 25 +- csharp/packages.config | 1 + 49 files changed, 2065 insertions(+), 49 deletions(-) create mode 100644 TestNinja/.DS_Store create mode 100644 TestNinja/TestNinja.UnitTests/Properties/AssemblyInfo.cs create mode 100644 TestNinja/TestNinja.UnitTests/TestNinja.UnitTests.csproj create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/CustomerControllerTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/DemeritPointsCalculatorTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/ErrorLoggerTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/FizzBuzzTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/HtmlFormatterTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/MathTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/ReservationTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/UnitTests/StackTests.cs create mode 100644 TestNinja/TestNinja.UnitTests/packages.config create mode 100644 TestNinja/TestNinja.sln create mode 100644 TestNinja/TestNinja/.DS_Store create mode 100644 TestNinja/TestNinja/App.config create mode 100644 TestNinja/TestNinja/Fundamentals/CustomerController.cs create mode 100644 TestNinja/TestNinja/Fundamentals/DateHelper.cs create mode 100644 TestNinja/TestNinja/Fundamentals/DemeritPointsCalculator.cs create mode 100644 TestNinja/TestNinja/Fundamentals/ErrorLogger.cs create mode 100644 TestNinja/TestNinja/Fundamentals/FizzBuzz.cs create mode 100644 TestNinja/TestNinja/Fundamentals/HtmlFormatter.cs create mode 100644 TestNinja/TestNinja/Fundamentals/Math.cs create mode 100644 TestNinja/TestNinja/Fundamentals/PhoneNumber.cs create mode 100644 TestNinja/TestNinja/Fundamentals/PowersOf2.cs create mode 100644 TestNinja/TestNinja/Fundamentals/Reservation.cs create mode 100644 TestNinja/TestNinja/Fundamentals/Stack.cs create mode 100644 TestNinja/TestNinja/Mocking/.DS_Store create mode 100644 TestNinja/TestNinja/Mocking/BookingHelper.cs create mode 100644 TestNinja/TestNinja/Mocking/EmployeeController.cs create mode 100644 TestNinja/TestNinja/Mocking/HousekeeperHelper.cs create mode 100644 TestNinja/TestNinja/Mocking/InstallerHelper.cs create mode 100644 TestNinja/TestNinja/Mocking/OrderService.cs create mode 100644 TestNinja/TestNinja/Mocking/Product.cs create mode 100644 TestNinja/TestNinja/Mocking/VideoService.cs create mode 100644 TestNinja/TestNinja/Properties/AssemblyInfo.cs create mode 100644 TestNinja/TestNinja/TestNinja.csproj create mode 100644 TestNinja/TestNinja/packages.config create mode 100644 csharp.UnitTests/Properties/AssemblyInfo.cs create mode 100644 csharp.UnitTests/Tests/ApprovalTest.cs create mode 100644 csharp.UnitTests/Tests/GildedRoseTest.cs create mode 100644 csharp.UnitTests/csharp.UnitTests.csproj create mode 100644 csharp.UnitTests/packages.config diff --git a/.gitignore b/.gitignore index 1ef5319f..99cec7a6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,338 @@ python/.cache python/.coverage **/.idea + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ \ No newline at end of file diff --git a/TestNinja/.DS_Store b/TestNinja/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0ca46f20c2ada3b3ec59bec54ab30e617193cfd2 GIT binary patch literal 6148 zcmeHKyG{c^3>-s>Aexkv`wRTRDhe%4_yCX+MM3D0c-2?&U3?njhY-<)28jlZC3|+g zo;}?Z=Q99XzHTmo1%Nr-5$_(R=I8DcJE@Ej>Ad3_dknb8-P?LneLUgZGu&W{XS{sp zKMfC$!!B<=PE}S4NC7Dz1*Cu!_=N)Aduj9YL`5ke1*E{20{(qybjMyeCdQ|OAw~e= zjOj40W0oK`PY`?In8*yxl1faf)ret9XTDWkFB}t-4y)nA>d96UipA4;e~WThPgIlw zQs7X5)7&n+|6kF6nEww++DQQ^@UIlG*=oI7@|CK$PF~J?ZKL1Pz2<}N#&u8_q8$^X i9dqOD_#%q3uKAkhy>LtnI`cs%>Sw@pkx7BSR^SuvAr(3R literal 0 HcmV?d00001 diff --git a/TestNinja/TestNinja.UnitTests/Properties/AssemblyInfo.cs b/TestNinja/TestNinja.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..57c9c3f5 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("TestNinja.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestNinja.UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("d077ad2c-59bc-41b1-8dba-99113b1ff8a9")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestNinja/TestNinja.UnitTests/TestNinja.UnitTests.csproj b/TestNinja/TestNinja.UnitTests/TestNinja.UnitTests.csproj new file mode 100644 index 00000000..bd096760 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/TestNinja.UnitTests.csproj @@ -0,0 +1,76 @@ + + + + + + Debug + AnyCPU + {D077AD2C-59BC-41B1-8DBA-99113B1FF8A9} + Library + Properties + TestNinja.UnitTests + TestNinja.UnitTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\GildedRose-Refactoring-Kata\csharp\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll + + + + + + + + + + + + + + + + + + {7328740E-4B78-464F-8352-65D887F2145F} + TestNinja + + + + + + + + + + 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}. + + + + \ No newline at end of file diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/CustomerControllerTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/CustomerControllerTests.cs new file mode 100644 index 00000000..ccba1fce --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/CustomerControllerTests.cs @@ -0,0 +1,27 @@ +using System.Security.Cryptography.X509Certificates; +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class CustomerControllerTests + { + private CustomerController _customerController; + + [SetUp] + public void SetUp() + { + _customerController = new CustomerController(); + } + + [Test] + public void GetCustomer_IfIdIsGreaterThenZero_ReturnOk() + { + var result = _customerController.GetCustomer(4); + Assert.That(result, Is.InstanceOf()); + Assert.That(result, Is.TypeOf()); + + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/DemeritPointsCalculatorTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/DemeritPointsCalculatorTests.cs new file mode 100644 index 00000000..c6d95daa --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/DemeritPointsCalculatorTests.cs @@ -0,0 +1,55 @@ +using System; +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class DemeritPointsCalculatorTests + { + private DemeritPointsCalculator _demeritPointsCalculator; + + [SetUp] + public void SetUp() + { + _demeritPointsCalculator = new DemeritPointsCalculator(); + } + + [Test] + public void CalculateDemeritPoints_SpeedIsNegative_ThrowArgumentOutOfRangeException() + { + Assert.That(() => _demeritPointsCalculator.CalculateDemeritPoints(-9), + Throws.Exception.TypeOf()); + } + + [Test] + public void CalculateDemeritPoints_SpeedIsGreaterThenMaxSpeed_ThrowArgumentOutOfRangeException() + { + Assert.That(() => _demeritPointsCalculator.CalculateDemeritPoints(350), + Throws.Exception.TypeOf()); + } + + [Test] + [TestCase(2)] + [TestCase(30)] + [TestCase(64)] + [TestCase(65)] + public void CalculateDemeritPoints_SpeedIsLessOrEqualSpeedLimit_ReturnZero(int speed) + { + var result = _demeritPointsCalculator.CalculateDemeritPoints(speed); + Assert.That(result, Is.EqualTo(0)); + } + + [Test] + [TestCase(66, 0)] + [TestCase(70, 1)] + [TestCase(80, 3)] + public void CalculateDemeritPoints_SpeedIsOverSpeedLimit_ReturnDemeritPoints(int speed, int expectedResult) + { + var result = _demeritPointsCalculator.CalculateDemeritPoints(speed); + Assert.That(result, Is.EqualTo(expectedResult)); + } + + + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/ErrorLoggerTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/ErrorLoggerTests.cs new file mode 100644 index 00000000..8e33dafc --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/ErrorLoggerTests.cs @@ -0,0 +1,44 @@ +using System; +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class ErrorLoggerTests + { + [Test] + public void Log_WhenCalled_SetTheLastErrorProperty() + { + var errorLogger = new ErrorLogger(); + + errorLogger.Log("some error"); + + Assert.That(errorLogger.LastError, Is.EqualTo("some error")); + } + + [Test] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void Log_InvalidError_ThrowArgumentNullException(string error) + { + var logger = new ErrorLogger(); + Assert.That(() => logger.Log(error), Throws.ArgumentNullException); + } + + [Test] + public void Log_ValidError_RaiseErrorLoggedEvent() + { + var logger = new ErrorLogger(); + + var id = Guid.Empty; + logger.ErrorLogged += (sender, args) => { id = args; }; + + logger.Log("a"); + + Assert.That(id, Is.Not.EqualTo(Guid.Empty)); + + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/FizzBuzzTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/FizzBuzzTests.cs new file mode 100644 index 00000000..99d628e2 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/FizzBuzzTests.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class FizzBuzzTests + { + + [Test] + public void GetOutput_DivisibleBy5And3_ReturnFizzBuzzString() + { + var result = FizzBuzz.GetOutput(15); + + Assert.That(result, Is.EqualTo("FizzBuzz")); + } + + [Test] + public void GetOutput_DivisibleBy3Only_ReturnFizzString() + { + var result = FizzBuzz.GetOutput(3); + + Assert.That(result, Is.EqualTo("Fizz")); + } + + [Test] + public void GetOutput_DivisibleBy5Only_ReturnBuzzString() + { + var result = FizzBuzz.GetOutput(5); + + Assert.That(result, Is.EqualTo("Buzz")); + } + + [Test] + public void GetOutput_NotDivisibleBy5And3_ReturnNumberAsString() + { + var result = FizzBuzz.GetOutput(4); + + Assert.That(result, Is.EqualTo("4")); + } + + + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/HtmlFormatterTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/HtmlFormatterTests.cs new file mode 100644 index 00000000..e54dcc88 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/HtmlFormatterTests.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using NUnit.Framework.Internal; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class HtmlFormatterTests + { + [Test] + public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement() + { + var formatter = new HtmlFormatter(); + + var result = formatter.FormatAsBold("abc"); + + //specific assertion + Assert.That(result, Is.EqualTo("abc").IgnoreCase); + + //more general + Assert.That(result, Does.StartWith("")); + Assert.That(result, Does.EndWith("")); + Assert.That(result, Does.Contain("abc")); + + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/MathTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/MathTests.cs new file mode 100644 index 00000000..a4cf1f8e --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/MathTests.cs @@ -0,0 +1,74 @@ +using System.Linq; +using System.Runtime.ExceptionServices; +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class MathTests + { + private Math _math; + + // SetUp - before tests + [SetUp] + public void SetUp() + { + _math = new Math(); + } + // TearDown - after tests + + + [Test] + [TestCase(1,2,3)] + [TestCase(0, 0, 0)] + [TestCase(10,20,30)] + public void Add_WhenCalled_ReturnTheSUmOfArguments(int first, int second, int expectedResult) + { + var result = _math.Add(first, second); + + Assert.That(result, Is.EqualTo(expectedResult)); + } + + [Test] + [Ignore("Because I wanted to!")] + public void Max_FirstArgumentIsGreater_ReturnTheFirstArgument() + { + var result = _math.Max(5, 2); + Assert.That(result, Is.EqualTo(5)); + } + + [Test] + public void Max_SecondArgumentIsGreater_ReturnTheSecondArgument() + { + var result = _math.Max(5, 15); + Assert.That(result, Is.EqualTo(15)); + } + + [Test] + public void Max_ArgumentsAreEqual_ReturnTheSameArgumentArgument() + { + var result = _math.Max(10, 10); + Assert.That(result, Is.EqualTo(10)); + } + + [Test] + public void GetOddNumbers_limitIsGreaterThanZero_ReturnOddNumbersUpToLimit() + { + var result = _math.GetOddNumbers(5); + + Assert.That(result, Is.Not.Empty); + Assert.That(result.Count(), Is.EqualTo(3)); + Assert.That(result, Does.Contain(1)); + Assert.That(result, Does.Contain(3)); + Assert.That(result, Does.Contain(5)); + + Assert.That(result, Is.EquivalentTo(new [] {1, 3, 5})); + + Assert.That(result, Is.Ordered); + Assert.That(result, Is.Unique); + + + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/ReservationTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/ReservationTests.cs new file mode 100644 index 00000000..cac523d0 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/ReservationTests.cs @@ -0,0 +1,65 @@ +using NUnit.Framework; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + public class ReservationTests + { + [Test] + public void CanBeCancelledBy_AdminCancelling_ReturnsTrue() + { + //Arrange + var reservation = new Reservation(); + + //Act + var result = reservation.CanBeCancelledBy(new User { IsAdmin = true }); + + //Assert + Assert.That(result, Is.True); + } + + [Test] + public void CanBeCancelledBy_AdminCancelling_ReturnsFalse() + { + //Arrange + var reservation = new Reservation(); + + //Act + var result = reservation.CanBeCancelledBy( + new User { IsAdmin = false }); + + //Assert + Assert.IsFalse(result); + Assert.That(result, Is.False); + } + + [Test] + public void CanBeCancelledBy_SameUserCancellingTheReservation_ReturnTrue() + { + var user = new User(); + var reservation = new Reservation + { + MadeBy = user + }; + + var result = reservation.CanBeCancelledBy(user); + + Assert.IsTrue(result); + } + + [Test] + public void CanBeCancelledBy_AnotherUserCancellingTheReservation_ReturnFalse() + { + var user = new User(); + var reservation = new Reservation + { + MadeBy = user + }; + + var result = reservation.CanBeCancelledBy(new User()); + + Assert.IsFalse(result); + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/UnitTests/StackTests.cs b/TestNinja/TestNinja.UnitTests/UnitTests/StackTests.cs new file mode 100644 index 00000000..e737893e --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/UnitTests/StackTests.cs @@ -0,0 +1,85 @@ +using System; +using NUnit.Framework; +using NUnit.Framework.Internal; +using TestNinja.Fundamentals; + +namespace TestNinja.UnitTests.UnitTests +{ + [TestFixture] + class StackTests + { + [Test] + public void Push_PassNull_ThrowArgumentNullException() + { + var stack = new Stack(); + Assert.That(() => stack.Push(null), Throws.ArgumentNullException); + } + + [Test] + public void Push_PassObject_StackIsNotEmpty() + { + var stack = new Stack(); + stack.Push(new object()); + Assert.That(stack.Count, Is.GreaterThan(0)); + } + + [Test] + public void Count_EmptyStack_ReturnZero() + { + var stack = new Stack(); + Assert.That(stack.Count, Is.EqualTo(0)); + } + + [Test] + public void Pop_EmptyStack_ThrowInvalidOperationException() + { + var stack = new Stack(); + Assert.That(() => stack.Pop(), Throws.InvalidOperationException); + } + + [Test] + public void Pop_StackNotEmpty_ReturnTopElement() + { + var stack = new Stack(); + stack.Push("dog"); + stack.Push("mouse"); + stack.Push("cat"); + + var result = stack.Pop(); + + Assert.That(result, Is.EqualTo("cat")); + } + + [Test] + public void Pop_StackNotEmpty_RemoveTopElement() + { + var stack = new Stack(); + stack.Push("dog"); + stack.Push("mouse"); + stack.Push("cat"); + + stack.Pop(); + var result = stack.Peek(); + + Assert.That(stack.Count, Is.EqualTo(2)); + } + + [Test] + public void Peek_EmptyStack_ThrowInvalidOperationException() + { + var stack = new Stack(); + Assert.That(() => stack.Peek(), Throws.InvalidOperationException); + } + + [Test] + public void Peek_NotEmptyStack_ReturnElementAtTheTop() + { + var stack = new Stack(); + + stack.Push("dog"); + var result = stack.Peek(); + + Assert.That(result, Is.EqualTo("dog")); + } + } +} diff --git a/TestNinja/TestNinja.UnitTests/packages.config b/TestNinja/TestNinja.UnitTests/packages.config new file mode 100644 index 00000000..b5529657 --- /dev/null +++ b/TestNinja/TestNinja.UnitTests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TestNinja/TestNinja.sln b/TestNinja/TestNinja.sln new file mode 100644 index 00000000..c50d0441 --- /dev/null +++ b/TestNinja/TestNinja.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.0.0 +MinimumVisualStudioVersion = 10.0.0.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestNinja", "TestNinja/TestNinja.csproj", "{7328740E-4B78-464F-8352-65D887F2145F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7328740E-4B78-464F-8352-65D887F2145F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7328740E-4B78-464F-8352-65D887F2145F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7328740E-4B78-464F-8352-65D887F2145F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7328740E-4B78-464F-8352-65D887F2145F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/TestNinja/TestNinja/.DS_Store b/TestNinja/TestNinja/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ec136db37820072b00a7970007e2d45409728776 GIT binary patch literal 6148 zcmeHK&2G~`5S~o~wbKJe>VZleR^q@VheRnYy;*5{1A%Zv5BvnXwi*{}w{o235JfUC zzykmWF8n+QyaP|dnVH=UqNF{7D4LOGzuDQDS^HaS*9!omKS{d)0RVWYgbg2?bA-l8 zm!#o5gu>LwLBUZn9iJq{QZzgMMFwc?R^dKqIE0t*%lhdAN4_T~MLw=Noo}MC(!6qY z)$?0xeyeq@^(-3cX;j74WZaL-C)9fwSED2@hr!J#PcyU*^0XQaGPPf1r6xZQj7{P@-DH*ep4`1tAb7n217zgZ*K9WLN2 z8ozOJ8kMTh>Ig>`S&L{!W`G%B1}+~1ZYT5BF5jc`6Eg$Mz#nFS_6Lbd7&@#inymvH z`hBGFCLsyhbeABM4nv2vMI1p9HWksP3U|d2HXZ%a#f1)Qi#8pEnHlT2nT5Nd2s1nS zr3nWSTI7})U*FiAvvuj^=&Y5fFHlJ+ ouD19y1r2i)V=NuTH&BhBUy^|sI;<_C2ZetG3=P~c1Amo)AA`JNwg3PC literal 0 HcmV?d00001 diff --git a/TestNinja/TestNinja/App.config b/TestNinja/TestNinja/App.config new file mode 100644 index 00000000..a8739f8d --- /dev/null +++ b/TestNinja/TestNinja/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/CustomerController.cs b/TestNinja/TestNinja/Fundamentals/CustomerController.cs new file mode 100644 index 00000000..07961ba4 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/CustomerController.cs @@ -0,0 +1,19 @@ +namespace TestNinja.Fundamentals +{ + public class CustomerController + { + public ActionResult GetCustomer(int id) + { + if (id == 0) + return new NotFound(); + + return new Ok(); + } + } + + public class ActionResult { } + + public class NotFound : ActionResult { } + + public class Ok : ActionResult { } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/DateHelper.cs b/TestNinja/TestNinja/Fundamentals/DateHelper.cs new file mode 100644 index 00000000..b3c95e37 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/DateHelper.cs @@ -0,0 +1,12 @@ +using System; + +namespace TestNinja.Fundamentals +{ + public class DateHelper + { + public static DateTime FirstOfNextMonth(DateTime date) + { + return date.Month == 12 ? new DateTime(date.Year + 1, 1, 1) : new DateTime(date.Year, date.Month + 1, 1); + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/DemeritPointsCalculator.cs b/TestNinja/TestNinja/Fundamentals/DemeritPointsCalculator.cs new file mode 100644 index 00000000..03df162f --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/DemeritPointsCalculator.cs @@ -0,0 +1,23 @@ +using System; + +namespace TestNinja.Fundamentals +{ + public class DemeritPointsCalculator + { + private const int SpeedLimit = 65; + private const int MaxSpeed = 300; + + public int CalculateDemeritPoints(int speed) + { + if (speed < 0 || speed > MaxSpeed) + throw new ArgumentOutOfRangeException(); + + if (speed <= SpeedLimit) return 0; + + const int kmPerDemeritPoint = 5; + var demeritPoints = (speed - SpeedLimit)/kmPerDemeritPoint; + + return demeritPoints; + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/ErrorLogger.cs b/TestNinja/TestNinja/Fundamentals/ErrorLogger.cs new file mode 100644 index 00000000..1cb23bf7 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/ErrorLogger.cs @@ -0,0 +1,25 @@ + +using System; + +namespace TestNinja.Fundamentals +{ + public class ErrorLogger + { + public string LastError { get; set; } + + public event EventHandler ErrorLogged; + + public void Log(string error) + { + if (String.IsNullOrWhiteSpace(error)) + throw new ArgumentNullException(); + + LastError = error; + + // Write the log to a storage + // ... + + ErrorLogged?.Invoke(this, Guid.NewGuid()); + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/FizzBuzz.cs b/TestNinja/TestNinja/Fundamentals/FizzBuzz.cs new file mode 100644 index 00000000..3bbc99d0 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/FizzBuzz.cs @@ -0,0 +1,19 @@ +namespace TestNinja.Fundamentals +{ + public class FizzBuzz + { + public static string GetOutput(int number) + { + if ((number % 3 == 0) && (number % 5 == 0)) + return "FizzBuzz"; + + if (number % 3 == 0) + return "Fizz"; + + if (number % 5 == 0) + return "Buzz"; + + return number.ToString(); + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/HtmlFormatter.cs b/TestNinja/TestNinja/Fundamentals/HtmlFormatter.cs new file mode 100644 index 00000000..c8de293c --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/HtmlFormatter.cs @@ -0,0 +1,10 @@ +namespace TestNinja.Fundamentals +{ + public class HtmlFormatter + { + public string FormatAsBold(string content) + { + return $"{content}"; + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/Math.cs b/TestNinja/TestNinja/Fundamentals/Math.cs new file mode 100644 index 00000000..7e17f482 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/Math.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace TestNinja.Fundamentals +{ + public class Math + { + public int Add(int a, int b) + { + return a + b; + } + + public int Max(int a, int b) + { + return (a > b) ? a : b; + } + + public IEnumerable GetOddNumbers(int limit) + { + for (var i = 0; i <= limit; i++) + if (i % 2 != 0) + yield return i; + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/PhoneNumber.cs b/TestNinja/TestNinja/Fundamentals/PhoneNumber.cs new file mode 100644 index 00000000..30904914 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/PhoneNumber.cs @@ -0,0 +1,38 @@ +using System; + +namespace TestNinja.Fundamentals +{ + public class PhoneNumber + { + public string Area { get; } + public string Major { get; } + public string Minor { get; } + + private PhoneNumber(string area, string major, string minor) + { + Area = area; + Major = major; + Minor = minor; + } + + public static PhoneNumber Parse(string number) + { + if (String.IsNullOrWhiteSpace(number)) + throw new ArgumentException("Phone number cannot be blank."); + + if (number.Length != 10) + throw new ArgumentException("Phone number should be 10 digits long."); + + var area = number.Substring(0, 3); + var major = number.Substring(3, 3); + var minor = number.Substring(6); + + return new PhoneNumber(area, major, minor); + } + + public override string ToString() + { + return String.Format($"({Area}){Major}-{Minor}"); + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/PowersOf2.cs b/TestNinja/TestNinja/Fundamentals/PowersOf2.cs new file mode 100644 index 00000000..fb83f82b --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/PowersOf2.cs @@ -0,0 +1,29 @@ +using System; + +namespace TestNinja +{ + public class PowersOf2 + { + public static void Main() + { + // Display powers of 2 up to the exponent of 8: + foreach (int i in Power(2, 8)) + { + Console.Write("{0} ", i); + } + } + + public static System.Collections.Generic.IEnumerable Power(int number, int exponent) + { + int result = 1; + + for (int i = 0; i < exponent; i++) + { + result = result * number; + yield return result; + } + } + + // Output: 2 4 8 16 32 64 128 256 + } +} diff --git a/TestNinja/TestNinja/Fundamentals/Reservation.cs b/TestNinja/TestNinja/Fundamentals/Reservation.cs new file mode 100644 index 00000000..fad7a772 --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/Reservation.cs @@ -0,0 +1,18 @@ +namespace TestNinja.Fundamentals +{ + public class Reservation + { + public User MadeBy { get; set; } + + public bool CanBeCancelledBy(User user) + { + return (user.IsAdmin || MadeBy == user); + } + + } + + public class User + { + public bool IsAdmin { get; set; } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Fundamentals/Stack.cs b/TestNinja/TestNinja/Fundamentals/Stack.cs new file mode 100644 index 00000000..68ab325e --- /dev/null +++ b/TestNinja/TestNinja/Fundamentals/Stack.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +namespace TestNinja.Fundamentals +{ + public class Stack + { + private readonly List _list = new List(); + + public int Count => _list.Count; + + public void Push(T obj) + { + if (obj == null) + throw new ArgumentNullException(); + + _list.Add(obj); + } + + public T Pop() + { + if (_list.Count == 0) + throw new InvalidOperationException(); + + var result = _list[_list.Count - 1]; + _list.RemoveAt(_list.Count - 1); + + return result; + } + + + public T Peek() + { + if (_list.Count == 0) + throw new InvalidOperationException(); + + return _list[_list.Count - 1]; + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/.DS_Store b/TestNinja/TestNinja/Mocking/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0() + .Where( + b => b.Id != booking.Id && b.Status != "Cancelled"); + + var overlappingBooking = + bookings.FirstOrDefault( + b => + booking.ArrivalDate >= b.ArrivalDate + && booking.ArrivalDate < b.DepartureDate + || booking.DepartureDate > b.ArrivalDate + && booking.DepartureDate <= b.DepartureDate); + + return overlappingBooking == null ? string.Empty : overlappingBooking.Reference; + } + } + + public class UnitOfWork + { + public IQueryable Query() + { + return new List().AsQueryable(); + } + } + + public class Booking + { + public string Status { get; set; } + public int Id { get; set; } + public DateTime ArrivalDate { get; set; } + public DateTime DepartureDate { get; set; } + public string Reference { get; set; } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/EmployeeController.cs b/TestNinja/TestNinja/Mocking/EmployeeController.cs new file mode 100644 index 00000000..60d0b9f4 --- /dev/null +++ b/TestNinja/TestNinja/Mocking/EmployeeController.cs @@ -0,0 +1,44 @@ +using System.Data.Entity; + +namespace TestNinja.Mocking +{ + public class EmployeeController + { + private EmployeeContext _db; + + public EmployeeController() + { + _db = new EmployeeContext(); + } + + public ActionResult DeleteEmployee(int id) + { + var employee = _db.Employees.Find(id); + _db.Employees.Remove(employee); + _db.SaveChanges(); + return RedirectToAction("Employees"); + } + + private ActionResult RedirectToAction(string employees) + { + return new RedirectResult(); + } + } + + public class ActionResult { } + + public class RedirectResult : ActionResult { } + + public class EmployeeContext + { + public DbSet Employees { get; set; } + + public void SaveChanges() + { + } + } + + public class Employee + { + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/HousekeeperHelper.cs b/TestNinja/TestNinja/Mocking/HousekeeperHelper.cs new file mode 100644 index 00000000..0aa65fd5 --- /dev/null +++ b/TestNinja/TestNinja/Mocking/HousekeeperHelper.cs @@ -0,0 +1,165 @@ +using System; +using System.IO; +using System.Net; +using System.Net.Mail; +using System.Text; + +namespace TestNinja.Mocking +{ + public static class HousekeeperHelper + { + private static readonly UnitOfWork UnitOfWork = new UnitOfWork(); + + public static bool SendStatementEmails(DateTime statementDate) + { + var housekeepers = UnitOfWork.Query(); + + foreach (var housekeeper in housekeepers) + { + if (housekeeper.Email == null) + continue; + + var statementFilename = SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate); + + if (string.IsNullOrWhiteSpace(statementFilename)) + continue; + + var emailAddress = housekeeper.Email; + var emailBody = housekeeper.StatementEmailBody; + + try + { + EmailFile(emailAddress, emailBody, statementFilename, + string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName)); + } + catch (Exception e) + { + XtraMessageBox.Show(e.Message, string.Format("Email failure: {0}", emailAddress), + MessageBoxButtons.OK); + } + } + + return true; + } + + private static string SaveStatement(int housekeeperOid, string housekeeperName, DateTime statementDate) + { + var report = new HousekeeperStatementReport(housekeeperOid, statementDate); + + if (!report.HasData) + return string.Empty; + + report.CreateDocument(); + + var filename = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + string.Format("Sandpiper Statement {0:yyyy-MM} {1}.pdf", statementDate, housekeeperName)); + + report.ExportToPdf(filename); + + return filename; + } + + private static void EmailFile(string emailAddress, string emailBody, string filename, string subject) + { + var client = new SmtpClient(SystemSettingsHelper.EmailSmtpHost) + { + Port = SystemSettingsHelper.EmailPort, + Credentials = + new NetworkCredential( + SystemSettingsHelper.EmailUsername, + SystemSettingsHelper.EmailPassword) + }; + + var from = new MailAddress(SystemSettingsHelper.EmailFromEmail, SystemSettingsHelper.EmailFromName, + Encoding.UTF8); + var to = new MailAddress(emailAddress); + + var message = new MailMessage(from, to) + { + Subject = subject, + SubjectEncoding = Encoding.UTF8, + Body = emailBody, + BodyEncoding = Encoding.UTF8 + }; + + message.Attachments.Add(new Attachment(filename)); + client.Send(message); + message.Dispose(); + + File.Delete(filename); + } + } + + public enum MessageBoxButtons + { + OK + } + + public class XtraMessageBox + { + public static void Show(string s, string housekeeperStatements, MessageBoxButtons ok) + { + } + } + + public class MainForm + { + public bool HousekeeperStatementsSending { get; set; } + } + + public class DateForm + { + public DateForm(string statementDate, object endOfLastMonth) + { + } + + public DateTime Date { get; set; } + + public DialogResult ShowDialog() + { + return DialogResult.Abort; + } + } + + public enum DialogResult + { + Abort, + OK + } + + public class SystemSettingsHelper + { + public static string EmailSmtpHost { get; set; } + public static int EmailPort { get; set; } + public static string EmailUsername { get; set; } + public static string EmailPassword { get; set; } + public static string EmailFromEmail { get; set; } + public static string EmailFromName { get; set; } + } + + public class Housekeeper + { + public string Email { get; set; } + public int Oid { get; set; } + public string FullName { get; set; } + public string StatementEmailBody { get; set; } + } + + public class HousekeeperStatementReport + { + public HousekeeperStatementReport(int housekeeperOid, DateTime statementDate) + { + } + + public bool HasData { get; set; } + + public void CreateDocument() + { + } + + public void ExportToPdf(string filename) + { + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/InstallerHelper.cs b/TestNinja/TestNinja/Mocking/InstallerHelper.cs new file mode 100644 index 00000000..bb6d2594 --- /dev/null +++ b/TestNinja/TestNinja/Mocking/InstallerHelper.cs @@ -0,0 +1,28 @@ +using System.Net; + +namespace TestNinja.Mocking +{ + public class InstallerHelper + { + private string _setupDestinationFile; + + public bool DownloadInstaller(string customerName, string installerName) + { + var client = new WebClient(); + try + { + client.DownloadFile( + string.Format("http://example.com/{0}/{1}", + customerName, + installerName), + _setupDestinationFile); + + return true; + } + catch (WebException) + { + return false; + } + } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/OrderService.cs b/TestNinja/TestNinja/Mocking/OrderService.cs new file mode 100644 index 00000000..2d6a79d9 --- /dev/null +++ b/TestNinja/TestNinja/Mocking/OrderService.cs @@ -0,0 +1,30 @@ +namespace TestNinja.Mocking +{ + public class OrderService + { + private readonly IStorage _storage; + + public OrderService(IStorage storage) + { + _storage = storage; + } + + public int PlaceOrder(Order order) + { + var orderId = _storage.Store(order); + + // Some other work + + return orderId; + } + } + + public class Order + { + } + + public interface IStorage + { + int Store(object obj); + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/Product.cs b/TestNinja/TestNinja/Mocking/Product.cs new file mode 100644 index 00000000..c8e952eb --- /dev/null +++ b/TestNinja/TestNinja/Mocking/Product.cs @@ -0,0 +1,20 @@ +namespace TestNinja.Mocking +{ + public class Product + { + public float ListPrice { get; set; } + + public float GetPrice(Customer customer) + { + if (customer.IsGold) + return ListPrice * 0.7f; + + return ListPrice; + } + } + + public class Customer + { + public bool IsGold { get; set; } + } +} \ No newline at end of file diff --git a/TestNinja/TestNinja/Mocking/VideoService.cs b/TestNinja/TestNinja/Mocking/VideoService.cs new file mode 100644 index 00000000..06f6697a --- /dev/null +++ b/TestNinja/TestNinja/Mocking/VideoService.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.IO; +using System.Linq; +using Newtonsoft.Json; + +namespace TestNinja.Mocking +{ + public class VideoService + { + public string ReadVideoTitle() + { + var str = File.ReadAllText("video.txt"); + var video = JsonConvert.DeserializeObject