-
Notifications
You must be signed in to change notification settings - Fork 162
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3d06659
Remove space from Listing06.11. Add tests 6,8,11
COsborn2 b301ec8
Remove space from GetName Listing14. Fix Listing20 property, visibility.
COsborn2 b5ed427
Fix property for Listing22
COsborn2 7f8cf0d
Add test 22
COsborn2 fe4768d
Make Listing31 public. Add tests 26,27,29,31
COsborn2 ee5adbe
Change visibility of Listings12,13,31. Add test to Listing 13
COsborn2 c10b619
Change visibility of classes. Add Tests 16,32,33,37
COsborn2 5abf3bf
Change visibility of Program. Add test for Listing 46
COsborn2 56c2fb3
Attempt to resolve ambiguity on Expect type
COsborn2 8737aa0
Apply suggestions from code review
COsborn2 9007480
Update based off code review
COsborn2 0b1702a
Add assertions to Listing6.13 test
COsborn2 bc3349b
Change to WriteLine for consistency between Listing5.2 && 5.9
COsborn2 c41b6ce
Cleanup file after creation
COsborn2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
src/Chapter06.Tests/Listing06.13.DataPersistenceToAFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Chapter06.Tests/Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
src/Chapter06.Tests/Listing06.20.ProvidingPropertyValidation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/Chapter06.Tests/Listing06.29.CallingAnObjectInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/Chapter06.Tests/Listing06.31.OverloadingAConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.