From 3ffcc02b79a6b021a6cc6ee3d35af8f1e6c0fd9b Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Fri, 16 Oct 2015 11:06:39 -0600 Subject: [PATCH 01/14] Switch to 4.5 --- CSharp/CSharp.csproj | 227 ++++++++++---------- CSharp/packages.config | 6 +- KoanHelpers/KoanHelpers.csproj | 197 +++++++++--------- KoanHelpers/packages.config | 6 +- KoanRunner/KoanRunner.csproj | 222 ++++++++++---------- KoanRunner/app.config | 3 + KoanRunner/packages.config | 6 +- VBNet/My Project/Application.Designer.vb | 26 +-- VBNet/My Project/Resources.Designer.vb | 126 +++++------ VBNet/My Project/Settings.Designer.vb | 146 ++++++------- VBNet/VBNet.vbproj | 254 ++++++++++++----------- 11 files changed, 617 insertions(+), 602 deletions(-) create mode 100644 KoanRunner/app.config diff --git a/CSharp/CSharp.csproj b/CSharp/CSharp.csproj index d7d322a..f5329a9 100644 --- a/CSharp/CSharp.csproj +++ b/CSharp/CSharp.csproj @@ -1,119 +1,122 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {981750A0-F5CA-42BA-84A1-FE52656B778F} - Library - Properties - DotNetKoans.CSharp - CSharp - v3.5 - 512 - Always - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - 3.5 - - - False - ..\packages\xunit.1.8.0.1549\lib\xunit.dll - - - - - - - - - - - - - - - - - - - - {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} - KoanHelpers - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {981750A0-F5CA-42BA-84A1-FE52656B778F} + Library + Properties + DotNetKoans.CSharp + CSharp + v4.5.2 + 512 + Always + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + 3.5 + + + False + ..\packages\xunit.1.8.0.1549\lib\xunit.dll + + + + + + + + + + + + + + + + + + + + {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} + KoanHelpers + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + + + + + - - - - + --> + + + + \ No newline at end of file diff --git a/CSharp/packages.config b/CSharp/packages.config index f156cf4..b81d8a4 100644 --- a/CSharp/packages.config +++ b/CSharp/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/KoanHelpers/KoanHelpers.csproj b/KoanHelpers/KoanHelpers.csproj index c255914..206c907 100644 --- a/KoanHelpers/KoanHelpers.csproj +++ b/KoanHelpers/KoanHelpers.csproj @@ -1,104 +1,107 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} - Library - Properties - KoanHelpers - KoanHelpers - v3.5 - 512 - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - False - ..\packages\xunit.1.8.0.1549\lib\xunit.dll - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - - + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} + Library + Properties + KoanHelpers + KoanHelpers + v4.5.2 + 512 + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + False + ..\packages\xunit.1.8.0.1549\lib\xunit.dll + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + + + --> \ No newline at end of file diff --git a/KoanHelpers/packages.config b/KoanHelpers/packages.config index f156cf4..b81d8a4 100644 --- a/KoanHelpers/packages.config +++ b/KoanHelpers/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/KoanRunner/KoanRunner.csproj b/KoanRunner/KoanRunner.csproj index f6a9684..de85197 100644 --- a/KoanRunner/KoanRunner.csproj +++ b/KoanRunner/KoanRunner.csproj @@ -1,116 +1,120 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {6631FC60-7B21-4C72-A1EB-A02365A101E0} - Exe - Properties - KoanRunner - KoanRunner - v3.5 - 512 - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - False - ..\packages\xunit.1.8.0.1549\lib\xunit.dll - - - False - ..\packages\xunit.1.8.0.1549\lib\xunit.runner.utility.dll - - - - - - - - - {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} - KoanHelpers - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - - + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {6631FC60-7B21-4C72-A1EB-A02365A101E0} + Exe + Properties + KoanRunner + KoanRunner + v4.5.2 + 512 + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + False + ..\packages\xunit.1.8.0.1549\lib\xunit.dll + + + False + ..\packages\xunit.1.8.0.1549\lib\xunit.runner.utility.dll + + + + + + + + + {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} + KoanHelpers + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + + + - - - - + --> + + + + \ No newline at end of file diff --git a/KoanRunner/app.config b/KoanRunner/app.config new file mode 100644 index 0000000..9c72f14 --- /dev/null +++ b/KoanRunner/app.config @@ -0,0 +1,3 @@ + + + diff --git a/KoanRunner/packages.config b/KoanRunner/packages.config index f156cf4..b81d8a4 100644 --- a/KoanRunner/packages.config +++ b/KoanRunner/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/VBNet/My Project/Application.Designer.vb b/VBNet/My Project/Application.Designer.vb index 66fb81a..db8b8b3 100644 --- a/VBNet/My Project/Application.Designer.vb +++ b/VBNet/My Project/Application.Designer.vb @@ -1,13 +1,13 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.239 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/VBNet/My Project/Resources.Designer.vb b/VBNet/My Project/Resources.Designer.vb index b975674..4133090 100644 --- a/VBNet/My Project/Resources.Designer.vb +++ b/VBNet/My Project/Resources.Designer.vb @@ -1,63 +1,63 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.239 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - -Imports System - -Namespace My.Resources - - 'This class was auto-generated by the StronglyTypedResourceBuilder - 'class via a tool like ResGen or Visual Studio. - 'To add or remove a member, edit your .ResX file then rerun ResGen - 'with the /str option, or rebuild your VS project. - ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. - ''' - _ - Friend Module Resources - - Private resourceMan As Global.System.Resources.ResourceManager - - Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' - ''' Returns the cached ResourceManager instance used by this class. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DotNetKoans.VBNet.Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property - - ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set - resourceCulture = value - End Set - End Property - End Module -End Namespace +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + +Imports System + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DotNetKoans.VBNet.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/VBNet/My Project/Settings.Designer.vb b/VBNet/My Project/Settings.Designer.vb index bb178b1..ae8f7c4 100644 --- a/VBNet/My Project/Settings.Designer.vb +++ b/VBNet/My Project/Settings.Designer.vb @@ -1,73 +1,73 @@ -'------------------------------------------------------------------------------ -' -' This code was generated by a tool. -' Runtime Version:4.0.30319.239 -' -' Changes to this file may cause incorrect behavior and will be lost if -' the code is regenerated. -' -'------------------------------------------------------------------------------ - -Option Strict On -Option Explicit On - - -Namespace My - - _ - Partial Friend NotInheritable Class MySettings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) - -#Region "My.Settings Auto-Save Functionality" -#If _MyType = "WindowsForms" Then - Private Shared addedHandler As Boolean - - Private Shared addedHandlerLockObject As New Object - - _ - Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) - If My.Application.SaveMySettingsOnExit Then - My.Settings.Save() - End If - End Sub -#End If -#End Region - - Public Shared ReadOnly Property [Default]() As MySettings - Get - -#If _MyType = "WindowsForms" Then - If Not addedHandler Then - SyncLock addedHandlerLockObject - If Not addedHandler Then - AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings - addedHandler = True - End If - End SyncLock - End If -#End If - Return defaultInstance - End Get - End Property - End Class -End Namespace - -Namespace My - - _ - Friend Module MySettingsProperty - - _ - Friend ReadOnly Property Settings() As Global.DotNetKoans.VBNet.My.MySettings - Get - Return Global.DotNetKoans.VBNet.My.MySettings.Default - End Get - End Property - End Module -End Namespace +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.DotNetKoans.VBNet.My.MySettings + Get + Return Global.DotNetKoans.VBNet.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/VBNet/VBNet.vbproj b/VBNet/VBNet.vbproj index 54517f3..6753578 100644 --- a/VBNet/VBNet.vbproj +++ b/VBNet/VBNet.vbproj @@ -1,133 +1,135 @@ - - - - Debug - AnyCPU - - - - - {1A8E8E55-4B39-43FA-A693-85D5BD48C324} - Library - DotNetKoans.VBNet - VBNet - 512 - Windows - v3.5 - - - - true - full - true - true - bin\Debug\ - VBNet.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - pdbonly - false - true - true - bin\Release\ - VBNet.xml - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - - - On - - - Binary - - - Off - - - On - - - - - - - - - - ..\packages\xunit.1.8.0.1549\lib\xunit.dll - - - - - - - - - - - - - - - - - - - - - - - - - True - Application.myapp - - - True - True - Resources.resx - - - True - Settings.settings - True - - - - - - VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb - My.Resources - Designer - - - - - MyApplicationCodeGenerator - Application.Designer.vb - - - SettingsSingleFileGenerator - My - Settings.Designer.vb - - - - - {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} - KoanHelpers - - - - - - + + + + Debug + AnyCPU + + + + + {1A8E8E55-4B39-43FA-A693-85D5BD48C324} + Library + DotNetKoans.VBNet + VBNet + 512 + Windows + v4.5.2 + + + + true + full + true + true + bin\Debug\ + VBNet.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false + + + pdbonly + false + true + true + bin\Release\ + VBNet.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + false + + + On + + + Binary + + + Off + + + On + + + + + + + + + + ..\packages\xunit.1.8.0.1549\lib\xunit.dll + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + {0BDD5CF4-EA4B-43E1-A947-0FADC67EE6C3} + KoanHelpers + + + + + + + --> \ No newline at end of file From e1e408ab06e681585f4e97abd017c6a867eebc19 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 22 Oct 2015 16:21:49 -0600 Subject: [PATCH 02/14] Correct spelling errors --- AutoKoanRunner/Program.cs | 2 +- CSharp/AboutDelegates.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AutoKoanRunner/Program.cs b/AutoKoanRunner/Program.cs index 826257d..fe668c5 100644 --- a/AutoKoanRunner/Program.cs +++ b/AutoKoanRunner/Program.cs @@ -19,7 +19,7 @@ static void Main(string[] args) { if (Array.TrueForAll(KoanSource.Sources, source => Directory.Exists(source.SourceFolder)) == false) { - Console.WriteLine("The Koans were not where we expecte them to be."); + Console.WriteLine("The Koans were not where we expected them to be."); return; } FileSystemWatcher[] watchers = Array.ConvertAll( diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index e49bbb6..d709e91 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -10,7 +10,7 @@ public class AboutDelegates : Koan { //A delegate is a user defined type just like a class. //A delegate lets you reference methods with the same signature and return type. - //Once you have the reference to the method, pass them as paramters or call it via the delegate. + //Once you have the reference to the method, pass them as parameters or call it via the delegate. //In other languages this is known as functions as first class citizens. //Here is a delegate declaration @@ -169,7 +169,7 @@ public void BuiltInActionDelegateTakesString() [Koan(14)] public void BuiltInActionDelegateIsOverloaded() { - //Action is an overloaded delegate so it can take more than one paramter + //Action is an overloaded delegate so it can take more than one parameter Action a = AssertAddEqualsFourtyTwo; a(12, (string)FILL_ME_IN); } @@ -270,8 +270,8 @@ public void FuncWithNoParameters() // public delegate TResult Func(T arg); //Is very similar to the Action<> delegate. However, Func<> does not require any parameters, while does require returns a value. //The last type parameter specifies the return type. If you only specify a single - //type, Func, then the method takes no paramters and returns an int. - //If you specify more than one parameter, then you are specifying the paramter types as well. + //type, Func, then the method takes no parameters and returns an int. + //If you specify more than one parameter, then you are specifying the parameter types as well. Func d = FirstMonth; Assert.Equal(FILL_ME_IN, d()); From b7206dfa830d1c2a4cd2c720852e176ddf10d51a Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 22 Oct 2015 16:30:57 -0600 Subject: [PATCH 03/14] Clarify that `this` is an instance, not a Type. --- CSharp/AboutControlStatements.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CSharp/AboutControlStatements.cs b/CSharp/AboutControlStatements.cs index 16d9033..45dde5a 100644 --- a/CSharp/AboutControlStatements.cs +++ b/CSharp/AboutControlStatements.cs @@ -109,15 +109,15 @@ public void IsOperators() bool isAboutControlStatements = false; bool isAboutMethods = false; - var myType = this; + var myInstance = this; - if (myType is Koan) + if (myInstance is Koan) isKoan = true; - if (myType is AboutControlStatements) + if (myInstance is AboutControlStatements) isAboutControlStatements = true; - if (myType is AboutMethods) + if (myInstance is AboutMethods) isAboutMethods = true; Assert.Equal(FILL_ME_IN, isKoan); From 9cf45047b07aa7c44d3495a2bfa742522df14529 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 22 Oct 2015 16:35:34 -0600 Subject: [PATCH 04/14] Add/Reorder Cars to clarify that sorting occurs. --- CSharp/AboutDelegates.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index d709e91..097de7d 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -308,7 +308,10 @@ public void SortingWithComparison() //You could make classes sortable by implementing IComparable or IComparer. But the Comparison<> delegate makes it easier // public delegate int Comparison(T x, T y); //All you need is a method which takes two of the same type and returns -1, 0, or 1 depending upon what order they should go in. - var cars = new[] { new Car("Alfa Romero", "GTV-6", 1986), new Car("BMC", "Mini", 1959) }; + var cars = new[] { + new Car("BMC", "Mini", 1959), + new Car("Alfa Romero", "GTV-6", 1986), + new Car("Dodge", "Ram", 2011) }; Comparison by = SortByModel; Array.Sort(cars, by); From 40f6bbd43b201ee5ff2fe96147894381106dc867 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 22 Oct 2015 16:44:34 -0600 Subject: [PATCH 05/14] Adjust delegate passing koans to match standard unit-testing style. My students found it quite confusing to have the assertions in the body of another method. --- CSharp/AboutDelegates.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index 097de7d..5e1643d 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -62,22 +62,22 @@ public void MethodsCalledViaDelegate() BinaryOp op = math.Add; Assert.Equal(FILL_ME_IN, op(3,3)); } - private void PassMeTheDelegate(BinaryOp passed) + private int PassMeTheDelegate(BinaryOp passed) { - Assert.Equal(FILL_ME_IN, passed(3,3)); + return passed(3, 3); } [Koan(6)] public void DelegatesCanBePassed() { MyMath math = new MyMath(); BinaryOp op = math.Add; - PassMeTheDelegate(op); + Assert.Equal(FILL_ME_IN, PassMeTheDelegate(op)); } [Koan(7)] public void MethodCanBePassedDirectly() { MyMath math = new MyMath(); - PassMeTheDelegate(math.Add); + Assert.Equal(FILL_ME_IN, PassMeTheDelegate(math.Add)); } [Koan(8)] public void DelegatesAreImmutable() From 151ae258b83c3822f83b73fdf828e1552c9d6354 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 14:13:47 -0600 Subject: [PATCH 06/14] Clarify and reorder koans related to Arrays and Generics --- CSharp/AboutArrays.cs | 36 ------ ...tArrayAssignment.cs => AboutAssignment.cs} | 2 +- CSharp/AboutGenericContainers.cs | 111 +++++++++++++----- CSharp/CSharp.csproj | 2 +- CSharp/PathToEnlightenment.cs | 4 +- 5 files changed, 83 insertions(+), 72 deletions(-) rename CSharp/{AboutArrayAssignment.cs => AboutAssignment.cs} (97%) diff --git a/CSharp/AboutArrays.cs b/CSharp/AboutArrays.cs index 27584db..50284d0 100644 --- a/CSharp/AboutArrays.cs +++ b/CSharp/AboutArrays.cs @@ -67,41 +67,5 @@ public void SlicingArrays() Assert.Equal(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Take(2).ToArray()); Assert.Equal(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Skip(1).Take(2).ToArray()); } - - [Koan(5)] - public void PushingAndPopping() - { - var array = new[] { 1, 2 }; - Stack stack = new Stack(array); - stack.Push("last"); - Assert.Equal(FILL_ME_IN, stack.ToArray()); - var poppedValue = stack.Pop(); - Assert.Equal(FILL_ME_IN, poppedValue); - Assert.Equal(FILL_ME_IN, stack.ToArray()); - } - - [Koan(6)] - public void Shifting() - { - //Shift == Remove First Element - //Unshift == Insert Element at Beginning - //C# doesn't provide this natively. You have a couple - //of options, but we'll use the LinkedList to implement - var array = new[] { "Hello", "World" }; - var list = new LinkedList(array); - - list.AddFirst("Say"); - Assert.Equal(FILL_ME_IN, list.ToArray()); - - list.RemoveLast(); - Assert.Equal(FILL_ME_IN, list.ToArray()); - - list.RemoveFirst(); - Assert.Equal(FILL_ME_IN, list.ToArray()); - - list.AddAfter(list.Find("Hello"), "World"); - Assert.Equal(FILL_ME_IN, list.ToArray()); - } - } } diff --git a/CSharp/AboutArrayAssignment.cs b/CSharp/AboutAssignment.cs similarity index 97% rename from CSharp/AboutArrayAssignment.cs rename to CSharp/AboutAssignment.cs index eaa59f3..1022fac 100644 --- a/CSharp/AboutArrayAssignment.cs +++ b/CSharp/AboutAssignment.cs @@ -6,7 +6,7 @@ namespace DotNetKoans.CSharp { - public class AboutArrayAssignment : Koan + public class AboutAssignment : Koan { //Parallel Assignments are a feature in Ruby which allow one //to set multiple variables at once using an array syntax. e.g. diff --git a/CSharp/AboutGenericContainers.cs b/CSharp/AboutGenericContainers.cs index 6c3b0da..1411ae2 100644 --- a/CSharp/AboutGenericContainers.cs +++ b/CSharp/AboutGenericContainers.cs @@ -1,7 +1,8 @@ using System; +using System.Collections; using System.Collections.Generic; using Xunit; -using System.Collections; +using System.Linq; namespace DotNetKoans.CSharp { @@ -129,7 +130,7 @@ public void BeyondTheLimits() Assert.Throws(typeof(FillMeIn), delegate() { int x = list[3]; }); } [Koan(12)] - public void ConvertingToFixedSize() + public void ConvertingToFixedSizeArray() { List list = new List { 1, 2, 3 }; Assert.Equal(FILL_ME_IN, list.ToArray()); @@ -148,8 +149,21 @@ public void RemovingItems() list.Remove(2); Assert.Equal(FILL_ME_IN, list.ToArray()); } + [Koan(15)] - public void StackPushPop() + public void BasicStackPushingAndPopping() + { + var array = new[] { 1, 2 }; + Stack stack = new Stack(array); + stack.Push("last"); + Assert.Equal(FILL_ME_IN, stack.ToArray()); + var poppedValue = stack.Pop(); + Assert.Equal(FILL_ME_IN, poppedValue); + Assert.Equal(FILL_ME_IN, stack.ToArray()); + } + + [Koan(16)] + public void GenericStackPushPop() { var stack = new Stack(); Assert.Equal(FILL_ME_IN, stack.Count); @@ -162,7 +176,7 @@ public void StackPushPop() Assert.Equal(FILL_ME_IN, stack.Count); } - [Koan(16)] + [Koan(17)] public void StackOrder() { var stack = new Stack(); @@ -172,7 +186,7 @@ public void StackOrder() Assert.Equal(FILL_ME_IN, stack.ToArray()); } - [Koan(17)] + [Koan(18)] public void PeekingIntoAQueue() { Queue queue = new Queue(); @@ -181,7 +195,7 @@ public void PeekingIntoAQueue() queue.Enqueue("two"); Assert.Equal(FILL_ME_IN, queue.Peek()); } - [Koan(18)] + [Koan(19)] public void RemovingItemsFromTheQueue() { Queue queue = new Queue(); @@ -190,7 +204,29 @@ public void RemovingItemsFromTheQueue() Assert.Equal(FILL_ME_IN, queue.Dequeue()); Assert.Equal(FILL_ME_IN, queue.Count); } - [Koan(19)] + [Koan(20)] + public void Shifting() + { + //Shift == Remove First Element + //Unshift == Insert Element at Beginning + //C# doesn't provide this natively. You have a couple + //of options, but we'll use the LinkedList to implement + var array = new[] { "Hello", "World" }; + var list = new LinkedList(array); + + list.AddFirst("Say"); + Assert.Equal(FILL_ME_IN, list.ToArray()); + + list.RemoveLast(); + Assert.Equal(FILL_ME_IN, list.ToArray()); + + list.RemoveFirst(); + Assert.Equal(FILL_ME_IN, list.ToArray()); + + list.AddAfter(list.Find("Hello"), "World"); + Assert.Equal(FILL_ME_IN, list.ToArray()); + } + [Koan(21)] public void AddingToADictionary() { //Dictionary is .Net's key value store. The key and the value do not need to be the same types. @@ -199,7 +235,7 @@ public void AddingToADictionary() dictionary[1] = "one"; Assert.Equal(FILL_ME_IN, dictionary.Count); } - [Koan(20)] + [Koan(22)] public void AccessingData() { Dictionary dictionary = new Dictionary(); @@ -209,14 +245,14 @@ public void AccessingData() Assert.Equal(FILL_ME_IN, dictionary["one"]); Assert.Equal(FILL_ME_IN, dictionary["two"]); } - [Koan(21)] + [Koan(23)] public void AccessingDataNotAdded() { Dictionary dictionary = new Dictionary(); dictionary["one"] = "uno"; Assert.Throws(typeof(FillMeIn), delegate() { string s = dictionary["two"]; }); } - [Koan(22)] + [Koan(24)] public void CatchingMissingData() { //To deal with the throw when data is not there, you could wrap the data access in a try/catch block... @@ -233,7 +269,26 @@ public void CatchingMissingData() } Assert.Equal(FILL_ME_IN, result); } - [Koan(23)] + [Koan(25)] + public void KeyExists() + { + Dictionary dictionary = new Dictionary(); + dictionary["one"] = "uno"; + Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("one")); + Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("two")); + } + + [Koan(26)] + public void ValueExists() + { + // This should have been at the top + Dictionary dictionary = new Dictionary(); + dictionary["one"] = "uno"; + Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("uno")); + Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("dos")); + } + + [Koan(27)] public void PreCheckForMissingData() { Dictionary dictionary = new Dictionary(); @@ -249,19 +304,26 @@ public void PreCheckForMissingData() } Assert.Equal(FILL_ME_IN, result); } - [Koan(24)] + + [Koan(28)] public void TryGetValueForMissingData() { Dictionary dictionary = new Dictionary(); dictionary["one"] = "uno"; string result; + if (!dictionary.TryGetValue("one", out result)) + { + result = "is the lonliest number"; + } + Assert.Equal(FILL_ME_IN, result); + if (!dictionary.TryGetValue("two", out result)) { result = "dos"; } Assert.Equal(FILL_ME_IN, result); } - [Koan(25)] + [Koan(29)] public void InitializingADictionary() { //Although it is not common, you can initialize a dictionary... @@ -269,7 +331,7 @@ public void InitializingADictionary() Assert.Equal(FILL_ME_IN, dictionary["one"]); Assert.Equal(FILL_ME_IN, dictionary["two"]); } - [Koan(26)] + [Koan(30)] public void ModifyingData() { Dictionary dictionary = new Dictionary(); @@ -278,24 +340,9 @@ public void ModifyingData() dictionary["one"] = "ein"; Assert.Equal(FILL_ME_IN, dictionary["one"]); } - [Koan(27)] - public void KeyExists() - { - Dictionary dictionary = new Dictionary(); - dictionary["one"] = "uno"; - Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("one")); - Assert.Equal(FILL_ME_IN, dictionary.ContainsKey("two")); - } - [Koan(28)] - public void ValueExists() - { - Dictionary dictionary = new Dictionary(); - dictionary["one"] = "uno"; - Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("uno")); - Assert.Equal(FILL_ME_IN, dictionary.ContainsValue("dos")); - } - [Koan(29)] - public void f() + + [Koan(31)] + public void ForEachKeyValuePair() { Dictionary one = new Dictionary(); one["jim"] = 53; diff --git a/CSharp/CSharp.csproj b/CSharp/CSharp.csproj index f5329a9..42d9c13 100644 --- a/CSharp/CSharp.csproj +++ b/CSharp/CSharp.csproj @@ -64,9 +64,9 @@ - + diff --git a/CSharp/PathToEnlightenment.cs b/CSharp/PathToEnlightenment.cs index 31dbbd1..7b873ab 100644 --- a/CSharp/PathToEnlightenment.cs +++ b/CSharp/PathToEnlightenment.cs @@ -10,12 +10,12 @@ public string[] ThePath "DotNetKoans.CSharp.AboutAsserts", "DotNetKoans.CSharp.AboutNil", "DotNetKoans.CSharp.AboutArrays", - "DotNetKoans.CSharp.AboutArrayAssignment", + "DotNetKoans.CSharp.AboutGenericContainers", + "DotNetKoans.CSharp.AboutAssignment", "DotNetKoans.CSharp.AboutStrings", "DotNetKoans.CSharp.AboutInheritance", "DotNetKoans.CSharp.AboutMethods", "DotNetKoans.CSharp.AboutControlStatements", - "DotNetKoans.CSharp.AboutGenericContainers", "DotNetKoans.CSharp.AboutDelegates", "DotNetKoans.CSharp.AboutLambdas" }; From be217da8670bcc52f01b5a4aacfac24aea66440f Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:20:47 -0600 Subject: [PATCH 07/14] `this Koan koan` severly confused my students; renaming to `this Koan me` for clarity --- CSharp/AboutMethods.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CSharp/AboutMethods.cs b/CSharp/AboutMethods.cs index f8f8108..882e4fd 100644 --- a/CSharp/AboutMethods.cs +++ b/CSharp/AboutMethods.cs @@ -7,17 +7,17 @@ namespace DotNetKoans.CSharp { public static class ExtensionMethods { - public static string HelloWorld(this Koan koan) + public static string HelloWorld(this Koan me) { return "Hello!"; } - public static string SayHello(this Koan koan, string name) + public static string SayHello(this Koan me, string name) { return String.Format("Hello, {0}!", name); } - public static string[] MethodWithVariableArguments(this Koan koan, params string[] names) + public static string[] MethodWithVariableArguments(this Koan me, params string[] names) { return names; } From d5636cfd4883fbe609618f3412eda12854880644 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:21:59 -0600 Subject: [PATCH 08/14] Rename `SooperSekrit` to `TopSecret` for clarity when discussing the Koans out loud. Also, it just makes a little more sense this way. --- CSharp/AboutMethods.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CSharp/AboutMethods.cs b/CSharp/AboutMethods.cs index 882e4fd..d105260 100644 --- a/CSharp/AboutMethods.cs +++ b/CSharp/AboutMethods.cs @@ -98,7 +98,7 @@ class InnerSecret public static string Key() { return "Key"; } public string Secret() { return "Secret"; } protected string SuperSecret() { return "This is secret"; } - private string SooperSeekrit() { return "No one will find me!"; } + private string TopSecret() { return "No one will find me!"; } } class StateSecret : InnerSecret @@ -150,7 +150,7 @@ public void SubvertPrivateMethods() { InnerSecret secret = new InnerSecret(); string superSecretMessage = secret.GetType() - .GetMethod("SooperSeekrit", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .GetMethod("TopSecret", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .Invoke(secret, null) as string; Assert.Equal(FILL_ME_IN, superSecretMessage); } From 4a9fe79f2e58a28179fac737ec4bdfdb9c69f795 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:33:52 -0600 Subject: [PATCH 09/14] Reorder AboutMethods so that variable parameters are introduced before they are used in the Extension Methods. --- CSharp/AboutMethods.cs | 67 ++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/CSharp/AboutMethods.cs b/CSharp/AboutMethods.cs index d105260..5cd7984 100644 --- a/CSharp/AboutMethods.cs +++ b/CSharp/AboutMethods.cs @@ -30,6 +30,29 @@ public static string SayHi(this String str) public class AboutMethods : Koan { + + // Methods can accept a variable number of arguments, using the + // params keyword + public string[] LocalMethodWithVariableParameters(params string[] names) + { + return names; + } + + [Koan(1)] + public void LocalMethodsWithVariableParams() + { + Assert.Equal(FILL_ME_IN, LocalMethodWithVariableParameters("Cory", "Will", "Corey")); + } + + //Note how we called the method by saying "this.LocalMethodWithVariableParameters" + //That isn't necessary for local methods + + [Koan(2)] + public void LocalMethodsWithoutExplicitReceiver() + { + Assert.Equal(FILL_ME_IN, LocalMethodWithVariableParameters("Cory", "Will", "Corey")); + } + //Extension Methods allow us to "add" methods to any class //without having to recompile. You only have to reference the //namespace the methods are in to use them. Here, since both the @@ -37,19 +60,27 @@ public class AboutMethods : Koan //DotNetKoans.CSharp namespace, AboutMethods can automatically //find them - [Koan(1)] + [Koan(3)] public void ExtensionMethodsShowUpInTheCurrentClass() { Assert.Equal(FILL_ME_IN, this.HelloWorld()); } - [Koan(2)] + //Unlike the local methods above, an explicit receiver is required + //for Extension Methods, since Extension Methods need an instance + //variable. So, this wouldn't work, giving a compile-time error: + //Assert.Equal(FILL_ME_IN, HelloWorld()); + + [Koan(4)] public void ExtensionMethodsWithParameters() { Assert.Equal(FILL_ME_IN, this.SayHello("Cory")); } - [Koan(3)] + //Any of the parameter things you can do with + //extension methods you can also do with local methods + + [Koan(5)] public void ExtensionMethodsWithVariableParameters() { Assert.Equal(FILL_ME_IN, this.MethodWithVariableArguments("Cory", "Will", "Corey")); @@ -59,40 +90,12 @@ public void ExtensionMethodsWithVariableParameters() //the name of the class they are extending. For example, //we can "extend" the string class like so: - [Koan(4)] + [Koan(6)] public void ExtendingCoreClasses() { Assert.Equal(FILL_ME_IN, "Cory".SayHi()); } - //Of course, any of the parameter things you can do with - //extension methods you can also do with local methods - - private string[] LocalMethodWithVariableParameters(params string[] names) - { - return names; - } - - [Koan(5)] - public void LocalMethodsWithVariableParams() - { - Assert.Equal(FILL_ME_IN, this.LocalMethodWithVariableParameters("Cory", "Will", "Corey")); - } - - //Note how we called the method by saying "this.LocalMethodWithVariableParameters" - //That isn't necessary for local methods - - [Koan(6)] - public void LocalMethodsWithoutExplicitReceiver() - { - Assert.Equal(FILL_ME_IN, LocalMethodWithVariableParameters("Cory", "Will", "Corey")); - } - - //But it is required for Extension Methods, since it needs - //an instance variable. So this wouldn't work, giving a - //compile-time error: - //Assert.Equal(FILL_ME_IN, MethodWithVariableArguments("Cory", "Will", "Corey")); - class InnerSecret { public static string Key() { return "Key"; } From cfd423b7af4104b8b4b3d8ca24e2ad2c4b9e5e3f Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:38:14 -0600 Subject: [PATCH 10/14] Null, not Nil. --- CSharp/AboutNil.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharp/AboutNil.cs b/CSharp/AboutNil.cs index c522005..2e52d62 100644 --- a/CSharp/AboutNil.cs +++ b/CSharp/AboutNil.cs @@ -5,7 +5,7 @@ namespace DotNetKoans.CSharp public class AboutNil : Koan { [Koan(1)] - public void NilIsNotAnObject() + public void NullIsNotAnObject() { Assert.True(typeof(object).IsAssignableFrom(null)); //not everything is an object } From e9d8c29eb46a1ac7a280af6b29248d4bb56a249a Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:40:38 -0600 Subject: [PATCH 11/14] Use the currency designator --- CSharp/AboutStrings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharp/AboutStrings.cs b/CSharp/AboutStrings.cs index 34dc44a..8c4e2f9 100644 --- a/CSharp/AboutStrings.cs +++ b/CSharp/AboutStrings.cs @@ -169,7 +169,7 @@ public void SeperatorsCanBeAdded() [Koan(17)] public void CurrencyDesignatorsCanBeAdded() { - var str = string.Format("{0:n}", 123456); + var str = string.Format("{0:C}", 123456); Assert.Equal(FILL_ME_IN, str); } From c3a6cf055fed0653d4e6e92311605620245972f5 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:41:47 -0600 Subject: [PATCH 12/14] Fix typo --- CSharp/AboutDelegates.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index 5e1643d..140f3da 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -31,7 +31,7 @@ public static int Subtract(int lhs, int rhs) [Koan(1)] public void DelegatesAreReferenceTypes() { - //If you don't initialize a delegate it will be a null value, just as any other refrence type. + //If you don't initialize a delegate it will be a null value, just as any other reference type. BinaryOp op; Assert.Null(FILL_ME_IN); } From b4b502ddf801d46850fbe66f574bcb1bbe617cf5 Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 15:45:51 -0600 Subject: [PATCH 13/14] Clarify the results of AboutDelegate's first koan. --- CSharp/AboutDelegates.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CSharp/AboutDelegates.cs b/CSharp/AboutDelegates.cs index 140f3da..c1817da 100644 --- a/CSharp/AboutDelegates.cs +++ b/CSharp/AboutDelegates.cs @@ -33,7 +33,8 @@ public void DelegatesAreReferenceTypes() { //If you don't initialize a delegate it will be a null value, just as any other reference type. BinaryOp op; - Assert.Null(FILL_ME_IN); + // At this point op is so null that the following line won't even compile: + // Assert.Null(op); } [Koan(2)] public void DelegatesCanBeInstantiated() From 7ea909125205c6ca318be7e7320bed6ea62914ca Mon Sep 17 00:00:00 2001 From: Eliza Brock Marcum Date: Thu, 19 Nov 2015 16:04:53 -0600 Subject: [PATCH 14/14] Inform the student when builds fail. Because, fail they will. --- AutoKoanRunner/Program.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AutoKoanRunner/Program.cs b/AutoKoanRunner/Program.cs index fe668c5..28ab00e 100644 --- a/AutoKoanRunner/Program.cs +++ b/AutoKoanRunner/Program.cs @@ -86,6 +86,10 @@ private static bool BuildProject(KoanSource koans) build.StartInfo.CreateNoWindow = true; build.Start(); build.WaitForExit(); + if(build.ExitCode != 0) + { + Console.WriteLine("There was a build error. Please check your code and try again."); + } } return false; }