Skip to content

Add tests Chapter6 - v8 #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change visibility of classes. Add Tests 16,32,33,37
  • Loading branch information
COsborn2 committed Aug 27, 2019
commit c10b6193f4b0e3f642d1cbc1e5f4a5503c19e609
4 changes: 2 additions & 2 deletions src/Chapter05.Tests/Listing05.28.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public void Main_InputNameAndAge35_AgeProperlyParsed()
{
const string expected =
@"Enter your first name: <<Inigo
>>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);
Expand Down
62 changes: 62 additions & 0 deletions src/Chapter06.Tests/Listing06.16.GettersAndSetters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16.Tests
{
[TestClass]
public class EmployeeTests
{
[TestMethod]
public void SetFirstName_Inigo_FirstNameSetToInigo()
{
Employee employee = new Employee();
employee.SetFirstName("Inigo");

Assert.AreEqual("Inigo", employee.GetFirstName());
}

[TestMethod]
public void SetFirstName_Null_FirstNameRemainsNull()
{
Employee employee = new Employee();
employee.SetFirstName(null);

Assert.AreEqual(null, employee.GetFirstName());
}

[TestMethod]
public void SetFirstName_Blank_FirstNameRemainsNull()
{
Employee employee = new Employee();
employee.SetFirstName("");

Assert.AreEqual(null, employee.GetFirstName());
}

[TestMethod]
public void SetLastName_Montoya_LastNameSetToInigo()
{
Employee employee = new Employee();
employee.SetLastName("Montoya");

Assert.AreEqual("Montoya", employee.GetLastName());
}

[TestMethod]
public void SetLastName_Null_LastNameRemainsNull()
{
Employee employee = new Employee();
employee.SetLastName(null);

Assert.AreEqual(null, employee.GetLastName());
}

[TestMethod]
public void SetLastName_Blank_LastNameRemainsNull()
{
Employee employee = new Employee();
employee.SetLastName("");

Assert.AreEqual(null, employee.GetLastName());
}
}
}
Original file line number Diff line number Diff line change
@@ -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_AllFieldsSet()
{
Employee employee = new Employee(15, "Inigo", "Montoya");

Assert.AreEqual(15, employee.Id);
Assert.AreEqual("Inigo", employee.FirstName);
Assert.AreEqual("Montoya", employee.LastName);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
20 changes: 20 additions & 0 deletions src/Chapter06.Tests/Listing06.37.AccessingAStaticField.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Chapter06/Listing06.16.GettersAndSetters.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_16
{
class Employee
public class Employee
{
private string FirstName;
// FirstName getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32
{
class Employee
public class Employee
{
public Employee(string firstName, string lastName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main()
}
}

class Employee
public class Employee
{
public Employee(string firstName, string lastName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chapter06/Listing06.37.AccessingAStaticField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main()
}
}

class Employee
public class Employee
{
public Employee(string firstName, string lastName)
{
Expand Down