From 22cb9bbc2bb618bdc0fd74918a45c5da71679446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bagnier?= Date: Thu, 13 Nov 2014 16:44:41 +0100 Subject: [PATCH] Cleanup --- .gitattributes | 22 ++ .gitignore | 189 +++++++++++++++++- .../ShippingInfo_After.cs | 154 +++++++------- .../Day2_MoveMethod/BankAccount_After.cs | 31 +++ .../Day2_MoveMethod/BankAccount_Before.cs | 34 ---- 5 files changed, 312 insertions(+), 118 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.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 index 79f239b..20938ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,184 @@ -_ReSharper.* -bin -obj -build -dist +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files *.suo -*resharper* *.user -~$* \ No newline at end of file +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# 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 + +*_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 +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# 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 addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# 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 + +# 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/ +# If using the old MSBuild-Integrated Package Restore, uncomment this: +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# 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/ \ No newline at end of file diff --git a/LosTechies.DaysOfRefactoring.SampleCode/Day11_SwitchToStrategy/ShippingInfo_After.cs b/LosTechies.DaysOfRefactoring.SampleCode/Day11_SwitchToStrategy/ShippingInfo_After.cs index 489c25b..11b11fc 100644 --- a/LosTechies.DaysOfRefactoring.SampleCode/Day11_SwitchToStrategy/ShippingInfo_After.cs +++ b/LosTechies.DaysOfRefactoring.SampleCode/Day11_SwitchToStrategy/ShippingInfo_After.cs @@ -2,83 +2,6 @@ using System.Collections.Generic; using System.Linq; -namespace LosTechies.DaysOfRefactoring.SwitchToStrategy.After_WithIoC -{ - public interface IShippingInfo - { - decimal CalculateShippingAmount(State state); - } - - public class ClientCode - { - [Inject] - public IShippingInfo ShippingInfo { get; set; } - - public decimal CalculateShipping() - { - return ShippingInfo.CalculateShippingAmount(State.Alaska); - } - } - - public enum State - { - Alaska, - NewYork, - Florida - } - - public class ShippingInfo : IShippingInfo - { - private IDictionary ShippingCalculations { get; set; } - - public ShippingInfo(IEnumerable shippingCalculations) - { - ShippingCalculations = shippingCalculations.ToDictionary(calc => calc.State); - } - - public decimal CalculateShippingAmount(State shipToState) - { - return ShippingCalculations[shipToState].Calculate(); - } - } - - public interface IShippingCalculation - { - State State { get; } - decimal Calculate(); - } - - public class AlaskShippingCalculation : IShippingCalculation - { - public State State { get { return State.Alaska; } } - - public decimal Calculate() - { - return 15m; - } - } - - public class NewYorkShippingCalculation : IShippingCalculation - { - public State State { get { return State.NewYork; } } - - public decimal Calculate() - { - return 10m; - } - } - - public class FloridaShippingCalculation : IShippingCalculation - { - public State State { get { return State.Florida; } } - - public decimal Calculate() - { - return 3m; - } - } -} - namespace LosTechies.DaysOfRefactoring.SwitchToStrategy.After { public class ClientCode @@ -146,3 +69,80 @@ public decimal Calculate() } } } + +namespace LosTechies.DaysOfRefactoring.SwitchToStrategy.After_WithIoC +{ + public interface IShippingInfo + { + decimal CalculateShippingAmount(State state); + } + + public class ClientCode + { + [Inject] + public IShippingInfo ShippingInfo { get; set; } + + public decimal CalculateShipping() + { + return ShippingInfo.CalculateShippingAmount(State.Alaska); + } + } + + public enum State + { + Alaska, + NewYork, + Florida + } + + public class ShippingInfo : IShippingInfo + { + private IDictionary ShippingCalculations { get; set; } + + public ShippingInfo(IEnumerable shippingCalculations) + { + ShippingCalculations = shippingCalculations.ToDictionary(calc => calc.State); + } + + public decimal CalculateShippingAmount(State shipToState) + { + return ShippingCalculations[shipToState].Calculate(); + } + } + + public interface IShippingCalculation + { + State State { get; } + decimal Calculate(); + } + + public class AlaskShippingCalculation : IShippingCalculation + { + public State State { get { return State.Alaska; } } + + public decimal Calculate() + { + return 15m; + } + } + + public class NewYorkShippingCalculation : IShippingCalculation + { + public State State { get { return State.NewYork; } } + + public decimal Calculate() + { + return 10m; + } + } + + public class FloridaShippingCalculation : IShippingCalculation + { + public State State { get { return State.Florida; } } + + public decimal Calculate() + { + return 3m; + } + } +} diff --git a/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_After.cs b/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_After.cs index 73edd36..05b729d 100644 --- a/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_After.cs +++ b/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_After.cs @@ -13,4 +13,35 @@ public BankAccount(int accountAge, int creditScore, AccountInterest accountInter public int CreditScore { get; private set; } public AccountInterest AccountInterest { get; private set; } } + + public class AccountInterest + { + public BankAccount Account { get; private set; } + + public AccountInterest(BankAccount account) + { + Account = account; + } + + public double InterestRate + { + get { return CalculateInterestRate(); } + } + + public bool IntroductoryRate + { + get { return CalculateInterestRate() < 0.05; } + } + + public double CalculateInterestRate() + { + if (Account.CreditScore > 800) + return 0.02; + + if (Account.AccountAge > 10) + return 0.03; + + return 0.05; + } + } } \ No newline at end of file diff --git a/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_Before.cs b/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_Before.cs index b3a3543..059cc1c 100644 --- a/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_Before.cs +++ b/LosTechies.DaysOfRefactoring.SampleCode/Day2_MoveMethod/BankAccount_Before.cs @@ -44,38 +44,4 @@ public bool IntroductoryRate get { return Account.CalculateInterestRate() < 0.05; } } } -} - -namespace LosTechies.DaysOfRefactoring.MoveMethod.After -{ - public class AccountInterest - { - public BankAccount Account { get; private set; } - - public AccountInterest(BankAccount account) - { - Account = account; - } - - public double InterestRate - { - get { return CalculateInterestRate(); } - } - - public bool IntroductoryRate - { - get { return CalculateInterestRate() < 0.05; } - } - - public double CalculateInterestRate() - { - if (Account.CreditScore > 800) - return 0.02; - - if (Account.AccountAge > 10) - return 0.03; - - return 0.05; - } - } } \ No newline at end of file