diff --git a/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.cs b/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.cs index a911c826a..432023136 100644 --- a/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.cs +++ b/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.cs @@ -9,7 +9,8 @@ public class HeyYouTests public void Main_MethodCalls_MethodsCalledSuccessfully() { const string expected = -@"Hey you!Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; diff --git a/src/Chapter05.Tests/Listing05.28.Tests.cs b/src/Chapter05.Tests/Listing05.28.Tests.cs index a7a4420ad..2a2848a7c 100644 --- a/src/Chapter05.Tests/Listing05.28.Tests.cs +++ b/src/Chapter05.Tests/Listing05.28.Tests.cs @@ -12,8 +12,8 @@ public void Main_InputNameAndAge35_AgeProperlyParsed() { const string expected = @"Enter your first name: <>Enter your age: <<35 ->>Hi Inigo! You are 420 months old."; +>>Enter your age: <<36 +>>Hi Inigo! You are 432 months old."; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, LeveragingTryParse.Main); diff --git a/src/Chapter05/Listing05.02.SimpleMethodCall.cs b/src/Chapter05/Listing05.02.SimpleMethodCall.cs index 568238ca3..605ed6ebb 100644 --- a/src/Chapter05/Listing05.02.SimpleMethodCall.cs +++ b/src/Chapter05/Listing05.02.SimpleMethodCall.cs @@ -7,7 +7,7 @@ public static void Main() string firstName; string lastName; - System.Console.Write("Hey you!"); + System.Console.WriteLine("Hey you!"); System.Console.Write("Enter your first name: "); firstName = System.Console.ReadLine(); diff --git a/src/Chapter06.Tests/Listing06.06.AccessingFields.cs b/src/Chapter06.Tests/Listing06.06.AccessingFields.cs new file mode 100644 index 000000000..b81c84119 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.06.AccessingFields.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_06.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_AccessingFields_WriteFieldValues() + { + const string expected = + @"Inigo Montoya: Enough to survive on"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.cs b/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.cs new file mode 100644 index 000000000..855ff8c84 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_08.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_AccessingFieldsFromOutsideClass_WriteFieldValues() + { + const string expected = + @"Inigo Montoya: Enough to survive on"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.cs b/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.cs new file mode 100644 index 000000000..42ee49053 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_11.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_AccessMethodWithThis_WriteMethodResult() + { + const string expected = + @"Name changed to 'Inigo Montoya'"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.cs b/src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.cs new file mode 100644 index 000000000..e06df9a38 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_12; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_13.Tests +{ + [TestClass] + public class DataStorageTests + { + [TestMethod] + public void Store_StoreInigoMontoya_WriteToFileAndRetrieve() + { + Employee employee = new Employee(); + employee.FirstName = "Inigo"; + employee.LastName = "Montoya"; + employee.Salary = "Too Little"; + + string expected = "Inigo" + Environment.NewLine + "Montoya" + Environment.NewLine + + "Too Little" + Environment.NewLine; + + DataStorage.Store(employee); + + string fileName = employee.FirstName + employee.LastName + ".dat"; + + var contents = File.ReadAllText(fileName); + + Assert.AreEqual(expected, contents); + + //Cleanup file + File.Delete(employee.FirstName + employee.LastName + ".dat"); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.cs b/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.cs new file mode 100644 index 000000000..d133fc69e --- /dev/null +++ b/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.cs @@ -0,0 +1,19 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_14.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_WriteToFileThenRetrieveDataFromFile_WriteStoredDataToScreen() + { + const string expected = +@"Name changed to 'Inigo Montoya' +Inigo Montoya: "; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.16.GettersAndSetters.cs b/src/Chapter06.Tests/Listing06.16.GettersAndSetters.cs new file mode 100644 index 000000000..18829e87e --- /dev/null +++ b/src/Chapter06.Tests/Listing06.16.GettersAndSetters.cs @@ -0,0 +1,32 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16.Tests +{ + [TestClass] + public class EmployeeTests + { + [TestMethod] + [DataRow("Inigo")] + [DataRow(null)] + [DataRow("")] + public void SetFirstName_FirstNamePropertySet(string firstName) + { + Employee employee = new Employee(); + employee.SetFirstName(firstName); + + Assert.AreEqual(firstName == "" ? null : firstName, employee.GetFirstName()); + } + + [TestMethod] + [DataRow("Montoya")] + [DataRow(null)] + [DataRow("")] + public void SetLastName_LastNamePropertySet(string lastName) + { + Employee employee = new Employee(); + employee.SetLastName(lastName); + + Assert.AreEqual(lastName == "" ? null : lastName, employee.GetLastName()); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.17.DefiningProperties.cs b/src/Chapter06.Tests/Listing06.17.DefiningProperties.cs new file mode 100644 index 000000000..c3367ce1e --- /dev/null +++ b/src/Chapter06.Tests/Listing06.17.DefiningProperties.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_17.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_PropertySetterGetter_WriteProperty() + { + const string expected = + @"Inigo"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.cs b/src/Chapter06.Tests/Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.cs new file mode 100644 index 000000000..9434b6585 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_18.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_PropertySetterGetter_WriteProperty() + { + const string expected = + @"Inigo"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.cs b/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.cs new file mode 100644 index 000000000..1ee0d25c5 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.cs @@ -0,0 +1,19 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_19.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_AutoPropertySetterGetter_WriteGetterValue() + { + const string expected = +@"Inigo +Computer Nerd"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.cs b/src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.cs new file mode 100644 index 000000000..e93f2ba3b --- /dev/null +++ b/src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.cs @@ -0,0 +1,60 @@ +using System; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_14; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Initialize_NullForFirstName_ThrowsArgumentNullException() + { + Employee employee = new Employee(); + employee.Initialize(null, "Montoya"); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Initialize_NullForLastName_ThrowsArgumentNullException() + { + Employee employee = new Employee(); + employee.Initialize("Inigo", null); + } + + [TestMethod] + public void Initialize_FirstNameWithTrailingNewLine_FirstNameTrimmed() + { + Employee employee = new Employee(); + employee.Initialize("Inigo\n", "Montoya"); + + Assert.AreEqual("Inigo", employee.FirstName); + } + + [TestMethod] + public void Initialize_LastNameWithTrailingNewLine_LastNameTrimmed() + { + Employee employee = new Employee(); + employee.Initialize("Inigo", "Montoya\n"); + + Assert.AreEqual("Montoya", employee.LastName); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void Initialize_BlankForFirstName_ThrowsArgumentException() + { + Employee employee = new Employee(); + employee.Initialize("", "Montoya"); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException))] + public void Initialize_BlankForLastName_ThrowsArgumentException() + { + Employee employee = new Employee(); + employee.Initialize("Inigo", ""); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.22.DefiningProperties.cs b/src/Chapter06.Tests/Listing06.22.DefiningProperties.cs new file mode 100644 index 000000000..da45b5183 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.22.DefiningProperties.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_22.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_CalculatedPropertySetGet_WriteGetterValue() + { + const string expected = + @"Inigo Montoya"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.cs b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.cs new file mode 100644 index 000000000..0844fea25 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() + { + const string expected = + @"Inigo Montoya: Too Little"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.27.CallingAConstructor.cs b/src/Chapter06.Tests/Listing06.27.CallingAConstructor.cs new file mode 100644 index 000000000..ae120ec63 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.27.CallingAConstructor.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() + { + const string expected = + @"Inigo Montoya: Too Little"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.cs b/src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.cs new file mode 100644 index 000000000..3666c69b8 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_29.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_ObjectInitializerSetTitleSalary_WriteEmployeeWithTitleSalary() + { + const string expected = + @"Inigo Montoya (Computer Nerd): Not enough"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.cs b/src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.cs new file mode 100644 index 000000000..593fe7a6d --- /dev/null +++ b/src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.cs @@ -0,0 +1,17 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31.Tests +{ + [TestClass] + public class EmployeeTests + { + [TestMethod] + public void EmployeeConstructor_TwoParameterConstructorSuccess() + { + Employee employee = new Employee("Inigo", "Montoya"); + + Assert.AreEqual("Inigo", employee.FirstName); + Assert.AreEqual("Montoya", employee.LastName); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.32.CallingOneConstructorFromAnother.cs b/src/Chapter06.Tests/Listing06.32.CallingOneConstructorFromAnother.cs new file mode 100644 index 000000000..7bfab86c9 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.32.CallingOneConstructorFromAnother.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32.Tests +{ + [TestClass] + public class EmployeeTests + { + [TestMethod] + public void CallConstructor_OtherConstructorCalled_AllPropertiesSet() + { + Employee employee = new Employee(15, "Inigo", "Montoya"); + + Assert.AreEqual(15, employee.Id); + Assert.AreEqual("Inigo", employee.FirstName); + Assert.AreEqual("Montoya", employee.LastName); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.33.ProvidingAnInitializationMethod.cs b/src/Chapter06.Tests/Listing06.33.ProvidingAnInitializationMethod.cs new file mode 100644 index 000000000..433449e8a --- /dev/null +++ b/src/Chapter06.Tests/Listing06.33.ProvidingAnInitializationMethod.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33.Tests +{ + [TestClass] + public class EmployeeTests + { + [TestMethod] + public void InitializeMethod_InitializeSetsProperties_PropertiesCorrectlySet() + { + Employee employee = new Employee(15, "Inigo", "Montoya"); + + Assert.AreEqual(15, employee.Id); + Assert.AreEqual("Inigo", employee.FirstName); + Assert.AreEqual("Montoya", employee.LastName); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.37.AccessingAStaticField.cs b/src/Chapter06.Tests/Listing06.37.AccessingAStaticField.cs new file mode 100644 index 000000000..2b42a2743 --- /dev/null +++ b/src/Chapter06.Tests/Listing06.37.AccessingAStaticField.cs @@ -0,0 +1,20 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_37.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_AccessStaticField_EmployeeIdIncrements() + { + const string expected = +@"Inigo Montoya (1000000) +Princess Buttercup (1000001) +NextId = 1000002"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter06.Tests/Listing06.46.DefiningANestedClass.cs b/src/Chapter06.Tests/Listing06.46.DefiningANestedClass.cs new file mode 100644 index 000000000..93d74e7eb --- /dev/null +++ b/src/Chapter06.Tests/Listing06.46.DefiningANestedClass.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_CreatesEmployee() + { + string[] arguments = { + "new", + "15", + "Inigo", + "Montoya" + }; + + const string expected = + @"'Creating' a new Employee."; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, (Action)Program.Main, arguments); + } + + [TestMethod] + public void Main_UpdateEmployee_EmployeeUpdated() + { + string[] arguments = { + "update", + "15", + "Inigo", + "Montoya" + }; + + const string expected = + @"'Updating' a new Employee."; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, (Action)Program.Main, arguments); + } + + [TestMethod] + public void Main_RemovesEmployee() + { + string[] arguments = { + "update", + "15", + "Inigo", + "Montoya" + }; + + const string expected = + @"'Updating' a new Employee."; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, (Action)Program.Main, arguments); + } + } +} diff --git a/src/Chapter06/Listing06.11.UsingThisWithAMethod.cs b/src/Chapter06/Listing06.11.UsingThisWithAMethod.cs index e02613148..1d4812858 100644 --- a/src/Chapter06/Listing06.11.UsingThisWithAMethod.cs +++ b/src/Chapter06/Listing06.11.UsingThisWithAMethod.cs @@ -20,7 +20,7 @@ class Employee public string GetName() { - return $"{ FirstName } { LastName }"; + return $"{ FirstName } { LastName }"; } public void SetName(string newFirstName, string newLastName) diff --git a/src/Chapter06/Listing06.12.PassingThisInAMethodCall.cs b/src/Chapter06/Listing06.12.PassingThisInAMethodCall.cs index dde02e647..ed42f2eaa 100644 --- a/src/Chapter06/Listing06.12.PassingThisInAMethodCall.cs +++ b/src/Chapter06/Listing06.12.PassingThisInAMethodCall.cs @@ -2,7 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_12 { // In a finished implementation these fields would be used #pragma warning disable CS0649 - class Employee + public class Employee { public string FirstName; public string LastName; diff --git a/src/Chapter06/Listing06.13.DataPersistenceToAFile.cs b/src/Chapter06/Listing06.13.DataPersistenceToAFile.cs index 5ff245acf..07f8b8e76 100644 --- a/src/Chapter06/Listing06.13.DataPersistenceToAFile.cs +++ b/src/Chapter06/Listing06.13.DataPersistenceToAFile.cs @@ -4,7 +4,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_13 using System.IO; using Listing06_12; - class DataStorage + public class DataStorage { // Save an employee object to a file // named with the Employee name diff --git a/src/Chapter06/Listing06.14.DataRetrievalFromAFile.cs b/src/Chapter06/Listing06.14.DataRetrievalFromAFile.cs index bb2d6a88e..57a363b37 100644 --- a/src/Chapter06/Listing06.14.DataRetrievalFromAFile.cs +++ b/src/Chapter06/Listing06.14.DataRetrievalFromAFile.cs @@ -37,7 +37,7 @@ class Employee public string GetName() { - return $"{ FirstName } { LastName }"; + return $"{ FirstName } { LastName }"; } public void SetName(string newFirstName, string newLastName) diff --git a/src/Chapter06/Listing06.16.GettersAndSetters.cs b/src/Chapter06/Listing06.16.GettersAndSetters.cs index c81c5aba2..65f87f1fd 100644 --- a/src/Chapter06/Listing06.16.GettersAndSetters.cs +++ b/src/Chapter06/Listing06.16.GettersAndSetters.cs @@ -1,6 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16 { - class Employee + public class Employee { private string FirstName; // FirstName getter diff --git a/src/Chapter06/Listing06.20.ProvidingPropertyValidation.cs b/src/Chapter06/Listing06.20.ProvidingPropertyValidation.cs index b48c93297..1b9e3b8a1 100644 --- a/src/Chapter06/Listing06.20.ProvidingPropertyValidation.cs +++ b/src/Chapter06/Listing06.20.ProvidingPropertyValidation.cs @@ -2,7 +2,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20 { - class Employee + public class Employee { // ... public void Initialize( @@ -17,7 +17,7 @@ public void Initialize( // LastName property public string LastName { - get => _FirstName; + get => _LastName; set { // Validate LastName assignment diff --git a/src/Chapter06/Listing06.22.DefiningProperties.cs b/src/Chapter06/Listing06.22.DefiningProperties.cs index ea645dd35..98cb68811 100644 --- a/src/Chapter06/Listing06.22.DefiningProperties.cs +++ b/src/Chapter06/Listing06.22.DefiningProperties.cs @@ -35,7 +35,7 @@ public string FirstName // LastName property public string LastName { - get => _FirstName; + get => _LastName; set => _LastName = value; } private string _LastName; diff --git a/src/Chapter06/Listing06.31.OverloadingAConstructor.cs b/src/Chapter06/Listing06.31.OverloadingAConstructor.cs index 26c996aba..c059f124a 100644 --- a/src/Chapter06/Listing06.31.OverloadingAConstructor.cs +++ b/src/Chapter06/Listing06.31.OverloadingAConstructor.cs @@ -1,6 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31 { - class Employee + public class Employee { public Employee(string firstName, string lastName) { @@ -18,9 +18,10 @@ public Employee( public Employee(int id) => Id = id; + private int _Id; public int Id { - get => Id; + get => _Id; private set { // Look up employee name... diff --git a/src/Chapter06/Listing06.32.CallingOneConstructorFromAnother.cs b/src/Chapter06/Listing06.32.CallingOneConstructorFromAnother.cs index d56f3f0bd..c9f1f5590 100644 --- a/src/Chapter06/Listing06.32.CallingOneConstructorFromAnother.cs +++ b/src/Chapter06/Listing06.32.CallingOneConstructorFromAnother.cs @@ -1,6 +1,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32 { - class Employee + public class Employee { public Employee(string firstName, string lastName) { diff --git a/src/Chapter06/Listing06.33.ProvidingAnInitializationMethod.cs b/src/Chapter06/Listing06.33.ProvidingAnInitializationMethod.cs index c5623ba36..d3eb9777d 100644 --- a/src/Chapter06/Listing06.33.ProvidingAnInitializationMethod.cs +++ b/src/Chapter06/Listing06.33.ProvidingAnInitializationMethod.cs @@ -11,7 +11,7 @@ public static void Main() } } - class Employee + public class Employee { public Employee(string firstName, string lastName) { diff --git a/src/Chapter06/Listing06.37.AccessingAStaticField.cs b/src/Chapter06/Listing06.37.AccessingAStaticField.cs index e3d7ad8b9..00ee119c0 100644 --- a/src/Chapter06/Listing06.37.AccessingAStaticField.cs +++ b/src/Chapter06/Listing06.37.AccessingAStaticField.cs @@ -29,7 +29,7 @@ public static void Main() } } - class Employee + public class Employee { public Employee(string firstName, string lastName) { diff --git a/src/Chapter06/Listing06.46.DefiningANestedClass.cs b/src/Chapter06/Listing06.46.DefiningANestedClass.cs index 7de4dbc2c..682ae7342 100644 --- a/src/Chapter06/Listing06.46.DefiningANestedClass.cs +++ b/src/Chapter06/Listing06.46.DefiningANestedClass.cs @@ -2,7 +2,7 @@ { using System; - class Program + public class Program { // Define a nested class for processing the command line private class CommandLine