Skip to content
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

Add tests Chapter6 - v8 #87

Merged
merged 14 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/Chapter05.Tests/Listing05.02.SimpleMethodCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class HeyYouTests
public void Main_MethodCalls_MethodsCalledSuccessfully()
{
const string expected =
@"Hey you!Enter your first name: <<Inigo
@"Hey you!
Enter your first name: <<Inigo
>>Enter your last name: <<Montoya
>>Your full name is Inigo Montoya.";

Expand Down
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
2 changes: 1 addition & 1 deletion src/Chapter05/Listing05.02.SimpleMethodCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.06.AccessingFields.cs
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_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);
}
}
}
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_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);
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.cs
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_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);
}
}
}
34 changes: 34 additions & 0 deletions src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.cs
Original file line number Diff line number Diff line change
@@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
File.Delete(employee.FirstName + employee.LastName + ".dat");
File.Delete(fileName);

}
}
}
19 changes: 19 additions & 0 deletions src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
32 changes: 32 additions & 0 deletions src/Chapter06.Tests/Listing06.16.GettersAndSetters.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.17.DefiningProperties.cs
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_17.Tests
{
[TestClass]
public class ProgramTests
{
[TestMethod]
public void Main_PropertySetterGetter_WriteProperty()
{
const string expected =
@"Inigo";

IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expected, Program.Main);
}
}
}
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_18.Tests
{
[TestClass]
public class ProgramTests
{
[TestMethod]
public void Main_PropertySetterGetter_WriteProperty()
{
const string expected =
@"Inigo";

IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expected, Program.Main);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
60 changes: 60 additions & 0 deletions src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.cs
Original file line number Diff line number Diff line change
@@ -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", "");
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.22.DefiningProperties.cs
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_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);
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.26.DefiningAConstructor.cs
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_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);
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.27.CallingAConstructor.cs
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_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);
}
}
}
18 changes: 18 additions & 0 deletions src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.cs
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_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);
}
}
}
17 changes: 17 additions & 0 deletions src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading