Skip to content

Commit

Permalink
Update ObjectExtensionsTests to Include Derived Types (#136)
Browse files Browse the repository at this point in the history
* Add Unit Tests for types deriving from `Entry` and `Label`

* Update ObjectExtensionsTests.cs

* Add `<WarningsAsErrors>CS1710</WarningsAsErrors>`
  • Loading branch information
brminnick committed Nov 8, 2022
1 parent bfa3d4c commit 3ef9b97
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<!--CS1572: XML comment has a param tag for '[parameter]', but there is no parameter by that name -->
<!--CS1573: Parameter has no matching param tag in the XML comment -->
<!--CS1574: XML comment has cref attribute that could not be resolved-->
<!--CS1710: XML comment has a duplicate typeparam tag-->
<!--CS1734: XML comment has a paramref tag, but there is no parameter by that name-->
<WarningsAsErrors>nullable,CS1570,CS1571,CS1572,CS1573,CS1574,CS1734</WarningsAsErrors>
<WarningsAsErrors>nullable,CS1570,CS1571,CS1572,CS1573,CS1574,CS1710,CS1734</WarningsAsErrors>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public void AssignLabel()
Assert.That(ReferenceEquals(createdLabel, assignedLabel));
}

[Test]
public void AssignCustomLabel()
{
var createdLabel = new CustomLabel().Assign(out Label assignedLabel).Assign(out CustomLabel assignedCustomLabel);
Assert.That(ReferenceEquals(createdLabel, assignedLabel));
Assert.That(ReferenceEquals(assignedCustomLabel, assignedLabel));
}

[Test]
public void AssignString()
{
Expand All @@ -39,11 +47,30 @@ public void Invoke()
Assert.That(createdLabel.Text, Is.EqualTo(text));
}

[Test]
public void InvokeCustomEntry()
{
const string text = nameof(Invoke);

var createdLabel = new CustomEntry().Invoke(l => l.Text = text);
Assert.That(createdLabel.Text, Is.EqualTo(text));
}

[Test]
public void InvokeNullThrowsArgumentNullException()
{
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
Assert.Throws<ArgumentNullException>(() => new Label().Invoke(null));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}

class CustomLabel : Label
{

}

class CustomEntry : Entry
{

}
}
4 changes: 2 additions & 2 deletions src/CommunityToolkit.Maui.Markup/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public static class ObjectExtensions
{
/// <summary>
/// Assign <typeparam name="TAssignable"/> to a variable
/// Assign <typeparamref name="TAssignable"/> to a variable
/// </summary>
/// <typeparam name="TAssignable"></typeparam>
/// <typeparam name="TVariable"></typeparam>
Expand All @@ -21,7 +21,7 @@ public static class ObjectExtensions
}

/// <summary>
/// Perform an action on <typeparam name="TAssignable"/>
/// Perform an action on <typeparamref name="TAssignable"/>
/// </summary>
/// <typeparam name="TAssignable"></typeparam>
/// <param name="assignable"></param>
Expand Down

0 comments on commit 3ef9b97

Please sign in to comment.