Switched to Target-Typed New Expressions
MODIFY
src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.Tests.cs
src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.Tests.cs
@@ -11,7 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_13.Tests
[TestMethod]
public void Store_StoreInigoMontoya_WriteToFileAndRetrieve()
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.FirstName = "Inigo";
employee.LastName = "Montoya";
employee.Salary = "Too Little";

MODIFY
src/Chapter06.Tests/Listing06.16.GettersAndSetters.Tests.cs
src/Chapter06.Tests/Listing06.16.GettersAndSetters.Tests.cs
@@ -11,7 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16.Tests
[DataRow("")]
public void SetFirstName_FirstNamePropertySet(string firstName)
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.SetFirstName(firstName);
Assert.AreEqual(firstName == "" ? null : firstName, employee.GetFirstName());
@@ -23,7 +23,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16.Tests
[DataRow("")]
public void SetLastName_LastNamePropertySet(string lastName)
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.SetLastName(lastName);
Assert.AreEqual(lastName == "" ? null : lastName, employee.GetLastName());

MODIFY
src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.Tests.cs
src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.Tests.cs
@@ -10,7 +10,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[ExpectedException(typeof(ArgumentNullException))]
public void Initialize_NullForFirstName_ThrowsArgumentNullException()
{
- Employee employee = new Employee();
+ Employee employee = new();
// Null-forgiving operator used with null for testing.
employee.Initialize(null!, "Montoya");
}
@@ -19,7 +19,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[ExpectedException(typeof(ArgumentNullException))]
public void Initialize_NullForLastName_ThrowsArgumentNullException()
{
- Employee employee = new Employee();
+ Employee employee = new();
// Null-forgiving operator used with null for testing.
employee.Initialize("Inigo", null!);
}
@@ -27,7 +27,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[TestMethod]
public void Initialize_FirstNameWithTrailingNewLine_FirstNameTrimmed()
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.Initialize("Inigo\n", "Montoya");
Assert.AreEqual("Inigo", employee.FirstName);
@@ -36,7 +36,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[TestMethod]
public void Initialize_LastNameWithTrailingNewLine_LastNameTrimmed()
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.Initialize("Inigo", "Montoya\n");
Assert.AreEqual("Montoya", employee.LastName);
@@ -46,7 +46,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[ExpectedException(typeof(ArgumentException))]
public void Initialize_BlankForFirstName_ThrowsArgumentException()
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.Initialize("", "Montoya");
}
@@ -54,7 +54,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_20.Tests
[ExpectedException(typeof(ArgumentException))]
public void Initialize_BlankForLastName_ThrowsArgumentException()
{
- Employee employee = new Employee();
+ Employee employee = new();
employee.Initialize("Inigo", "");
}
}

MODIFY
src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.Tests.cs
src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.Tests.cs
@@ -8,7 +8,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31.Tests
[TestMethod]
public void EmployeeConstructor_TwoParameterConstructorSuccess()
{
- Employee employee = new Employee("Inigo", "Montoya");
+ Employee employee = new("Inigo", "Montoya");
Assert.AreEqual("Inigo", employee.FirstName);
Assert.AreEqual("Montoya", employee.LastName);

MODIFY
src/Chapter06.Tests/Listing06.32.CallingOneConstructorFromAnother.Tests.cs
src/Chapter06.Tests/Listing06.32.CallingOneConstructorFromAnother.Tests.cs
@@ -8,7 +8,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32.Tests
[TestMethod]
public void CallConstructor_OtherConstructorCalled_AllPropertiesSet()
{
- Employee employee = new Employee(15, "Inigo", "Montoya");
+ Employee employee = new(15, "Inigo", "Montoya");
Assert.AreEqual(15, employee.Id);
Assert.AreEqual("Inigo", employee.FirstName);

MODIFY
src/Chapter06.Tests/Listing06.33.ProvidingAnInitializationMethod.Tests.cs
src/Chapter06.Tests/Listing06.33.ProvidingAnInitializationMethod.Tests.cs
@@ -8,7 +8,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33.Tests
[TestMethod]
public void InitializeMethod_InitializeSetsProperties_PropertiesCorrectlySet()
{
- Employee employee = new Employee(15, "Inigo", "Montoya");
+ Employee employee = new(15, "Inigo", "Montoya");
Assert.AreEqual(15, employee.Id);
Assert.AreEqual("Inigo", employee.FirstName);

Switched to Target-Typed New Expressions