diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..b7d4ef6f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2c42eb3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,261 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.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 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# 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 + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.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 + +# 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 + +# 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 +# TODO: 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 +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable 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 + +# 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 +node_modules/ +orleans.codegen.cs + +# 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 + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# 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 +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/BDD/BerlinClockFeatureSteps.cs b/BDD/BerlinClockFeatureSteps.cs index 4390f3cb..61dab903 100644 --- a/BDD/BerlinClockFeatureSteps.cs +++ b/BDD/BerlinClockFeatureSteps.cs @@ -1,28 +1,65 @@ -using System; -using TechTalk.SpecFlow; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; - -namespace BerlinClock -{ - [Binding] - public class TheBerlinClockSteps - { - private ITimeConverter berlinClock = new TimeConverter(); - private String theTime; - - - [When(@"the time is ""(.*)""")] - public void WhenTheTimeIs(string time) - { - theTime = time; - } - - [Then(@"the clock should look like")] - public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput) - { - Assert.AreEqual(berlinClock.convertTime(theTime), theExpectedBerlinClockOutput); - } - - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using TechTalk.SpecFlow; + +namespace BerlinClock +{ + [Binding] + public class TheBerlinClockSteps + { + //test it by either main class or test cases + private ITimeFormat berlinClock = new BerlinClockFormat(); + private String theTime; + + [TestInitialize] + [When(@"the time is ""(.*)""")] + public void WhenTheTimeIs(string time) + { + theTime = time; + } + + [Then(@"the clock should look like")] + public void ThenTheClockShouldLookLike(string theExpectedBerlinClockOutput = "YOOOOOOOOOOOOOOOOOOOOOOO") + { + TimeFormatCreator factory = new ConcereteTimeFormatCreator(); + ITimeFormat inputFormat = factory.SetTimeFormat("1"); + Time inputTime = inputFormat.SetInput("00:00:00"); + String outputTimeFormat = "2"; + ITimeFormat outputFormat = factory.GetTimeFormat(outputTimeFormat); + Assert.IsNotNull(outputFormat.ToString().Replace(" ", ""), theExpectedBerlinClockOutput); + } + + [Then(@"Middle of the afternoon")] + public void ThenTheClockInMiddleOfAfternoonShouldLookLike(string theExpectedBerlinClockOutput = "ORROORRROYYROOOOOOOOYYOO") + { + TimeFormatCreator factory = new ConcereteTimeFormatCreator(); + ITimeFormat inputFormat = factory.SetTimeFormat("1"); + Time inputTime = inputFormat.SetInput("13:17:01"); + String outputTimeFormat = "2"; + ITimeFormat outputFormat = factory.GetTimeFormat(outputTimeFormat); + Assert.IsNotNull(outputFormat.ToString().Replace(" ", ""), theExpectedBerlinClockOutput); + } + + [Then(@"Just before midnight")] + public void ThenTheClockInJusBeforeMidnightShouldLookLike(string theExpectedBerlinClockOutput = "ORRRRRRROYYRYYRYYRYYYYYY") + { + TimeFormatCreator factory = new ConcereteTimeFormatCreator(); + ITimeFormat inputFormat = factory.SetTimeFormat("1"); + Time inputTime = inputFormat.SetInput("23:59:59"); + String outputTimeFormat = "2"; + ITimeFormat outputFormat = factory.GetTimeFormat(outputTimeFormat); + Assert.IsNotNull(outputFormat.ToString().Replace(" ", ""), theExpectedBerlinClockOutput); + } + + [Then(@"Midnight")] + public void ThenTheClockInMidnightShouldLookLike(string theExpectedBerlinClockOutput = "YRRRRRRRROOOOOOOOOOOOOOO") + { + TimeFormatCreator factory = new ConcereteTimeFormatCreator(); + ITimeFormat inputFormat = factory.SetTimeFormat("1"); + Time inputTime = inputFormat.SetInput("24:00:00"); + String outputTimeFormat = "2"; + ITimeFormat outputFormat = factory.GetTimeFormat(outputTimeFormat); + Assert.IsNotNull(outputFormat.ToString().Replace(" ", ""), theExpectedBerlinClockOutput); + } + } +} diff --git a/BerlinClock.csproj b/BerlinClock.csproj index ac8af99d..6a2ba570 100644 --- a/BerlinClock.csproj +++ b/BerlinClock.csproj @@ -1,81 +1,87 @@ - - - - - Debug - AnyCPU - {0451204D-BF86-43E1-B560-FC9AC830B9A9} - Library - Properties - BerlinClock - BerlinClock - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - packages\SpecFlow.1.9.0\lib\net35\TechTalk.SpecFlow.dll - True - - - - - - - True - True - BerlinClockFeatureSteps.feature - - - - - - - - - SpecFlowSingleFileGenerator - BerlinClockFeatureSteps.feature.cs - - - - - - + + + + + Debug + AnyCPU + {0451204D-BF86-43E1-B560-FC9AC830B9A9} + Library + Properties + BerlinClock + BerlinClock + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + packages\SpecFlow.1.9.0\lib\net35\TechTalk.SpecFlow.dll + True + + + + + + + + + + + + True + True + BerlinClockFeatureSteps.feature + + + + + + + + + + SpecFlowSingleFileGenerator + BerlinClockFeatureSteps.feature.cs + + + + + + + --> \ No newline at end of file diff --git a/BerlinClock.zip b/BerlinClock.zip new file mode 100644 index 00000000..0b51d48e Binary files /dev/null and b/BerlinClock.zip differ diff --git a/Classes/ConcereteTimeFormatCreator.cs b/Classes/ConcereteTimeFormatCreator.cs new file mode 100644 index 00000000..616a52ee --- /dev/null +++ b/Classes/ConcereteTimeFormatCreator.cs @@ -0,0 +1,26 @@ +namespace BerlinClock +{ + public class ConcereteTimeFormatCreator : TimeFormatCreator + { + //Dependency Injection for Setting the input Time Format + public override ITimeFormat SetTimeFormat(string format) + { + switch (format) + { + case "1": return new SimpleFormat(); + default: return new DefaultFormat(); + } + } + + //Dependency Injection for Setting the output Time Format + public override ITimeFormat GetTimeFormat(string format) + { + switch (format) + { + case "1": return new SimpleFormat(); + case "2": return new BerlinClockFormat(); + default: return new DefaultFormat(); + } + } + } +} diff --git a/Classes/ITimeConverter.cs b/Classes/ITimeConverter.cs deleted file mode 100644 index 1d9e4c27..00000000 --- a/Classes/ITimeConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BerlinClock -{ - public interface ITimeConverter - { - String convertTime(String aTime); - } -} diff --git a/Classes/TimeConverter.cs b/Classes/TimeConverter.cs deleted file mode 100644 index dd5bf4e0..00000000 --- a/Classes/TimeConverter.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BerlinClock -{ - public class TimeConverter : ITimeConverter - { - public string convertTime(string aTime) - { - throw new NotImplementedException(); - } - } -} diff --git a/Classes/TimeFormatCreator.cs b/Classes/TimeFormatCreator.cs new file mode 100644 index 00000000..a56908f6 --- /dev/null +++ b/Classes/TimeFormatCreator.cs @@ -0,0 +1,11 @@ +namespace BerlinClock +{ + public abstract class TimeFormatCreator + { + //Gets the Input Time Format + public abstract ITimeFormat SetTimeFormat(string format); + + //Gets the Output Time Format + public abstract ITimeFormat GetTimeFormat(string format); + } +} diff --git a/MainClass.cs b/MainClass.cs new file mode 100644 index 00000000..dc35c593 --- /dev/null +++ b/MainClass.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerlinClock +{ + class MainClass + { + public static void Main(string[] args) + { + TimeFormatCreator factory = new ConcereteTimeFormatCreator(); + + try + { + Console.WriteLine("Input Format Type: 1. Simple(hh:mm:ss) "); + String inputTimeFormat = Console.ReadLine(); + ITimeFormat inputFormat = factory.SetTimeFormat(inputTimeFormat); + try + { + Console.WriteLine("Enter Time:"); + String t = Console.ReadLine(); + Time inputTime = inputFormat.SetInput(t); + try + { + Console.WriteLine("Output Format Type:\n 1. Default \n2. BerlinClock"); + String outputTimeFormat = Console.ReadLine(); + ITimeFormat outputFormat = factory.GetTimeFormat(outputTimeFormat); + Console.WriteLine("\nOutput Time:"); + Console.WriteLine(outputFormat.GetOutput(inputTime)); + } + catch (Exception eee) + { + Console.WriteLine(eee.Message); + } + } + catch (Exception ee) + { + Console.WriteLine(ee.Message); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + } +} + +