Skip to content
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
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));
}
}
11 changes: 10 additions & 1 deletion 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)
{
return new TestMethodBodyWithNullCheck(canonicalDataCase, CanonicalData);
}

return new TestMethodBodyWithEqualityCheck(canonicalDataCase, CanonicalData);
}
Expand All @@ -86,4 +95,4 @@ protected virtual string RenderTestMethodBodyAct(TestMethodBody testMethodBody)
protected virtual string RenderTestMethodBodyAssert(TestMethodBody testMethodBody)
=> TemplateRenderer.RenderPartial(testMethodBody.AssertTemplateName, testMethodBody.AssertTemplateParameters);
}
}
}
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 };
}
}
}