Skip to content

Use Assert.Null when validating against null #359

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 2 commits into from
Aug 19, 2017
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
14 changes: 7 additions & 7 deletions exercises/phone-number/PhoneNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void Cleans_numbers_with_multiple_spaces()
public void Invalid_when_9_digits()
{
var phrase = "123456789";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_when_11_digits_does_not_start_with_a_1()
{
var phrase = "22234567890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
Expand All @@ -57,34 +57,34 @@ public void Valid_when_11_digits_and_starting_with_1_even_with_punctuation()
public void Invalid_when_more_than_11_digits()
{
var phrase = "321234567890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_with_letters()
{
var phrase = "123-abc-7890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_with_punctuations()
{
var phrase = "123-@:!-7890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_if_area_code_does_not_start_with_2_9()
{
var phrase = "(123) 456-7890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_if_exchange_code_does_not_start_with_2_9()
{
var phrase = "(223) 056-7890";
Assert.Equal(null, PhoneNumber.Clean(phrase));
Assert.Null(PhoneNumber.Clean(phrase));
}
}
9 changes: 9 additions & 0 deletions generators/Exercise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,19 @@ protected virtual string RenderTestMethodBody(CanonicalDataCase canonicalDataCas
protected virtual TestMethodBody CreateTestMethodBody(CanonicalDataCase canonicalDataCase)
{
if (canonicalDataCase.ExceptionThrown != null)
{
return new TestMethodBodyWithExceptionCheck(canonicalDataCase, CanonicalData);
}

if (canonicalDataCase.Expected is bool)
{
return new TestMethodBodyWithBooleanCheck(canonicalDataCase, CanonicalData);
}

if(canonicalDataCase.Expected is null)
Copy link
Contributor

Choose a reason for hiding this comment

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

The Type A in me is screaming about a missing space after the if ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

I forgot that I can fix it inline :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh man, that would bother me too. I didn't even notice that. Usually Visual Studio just automatically tosses that in for me.

{
return new TestMethodBodyWithNullCheck(canonicalDataCase, CanonicalData);
}

return new TestMethodBodyWithEqualityCheck(canonicalDataCase, CanonicalData);
}
Expand Down
2 changes: 0 additions & 2 deletions generators/Exercises/PhoneNumber.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Generators.Input;
using Generators.Output;

namespace Generators.Exercises
{
Expand All @@ -10,7 +9,6 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData)
foreach (var canonicalDataCase in CanonicalData.Cases)
{
canonicalDataCase.UseVariablesForInput = true;
canonicalDataCase.Expected = canonicalDataCase.Expected ?? new UnescapedValue("null");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions generators/Output/Templates/_AssertNull.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Assert.Null({{ TestedValue }});
13 changes: 13 additions & 0 deletions generators/Output/TestMethodBodyWithNullCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Generators.Input;

namespace Generators.Output
{
public class TestMethodBodyWithNullCheck : TestMethodBody
{
public TestMethodBodyWithNullCheck(CanonicalDataCase canonicalDataCase, CanonicalData canonicalData) : base(canonicalDataCase, canonicalData)
{
AssertTemplateName = "AssertNull";
AssertTemplateParameters = new { Data.TestedValue };
}
}
}