Skip to content

Commit

Permalink
Test coverage increased to 100%.
Browse files Browse the repository at this point in the history
  • Loading branch information
hennadiilu committed Oct 8, 2022
1 parent 2416257 commit d75a390
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Heleonix.Reflection.Tests/Common/Dummies/SubSubItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,62 @@ public class SubSubItem
#pragma warning restore SA1401 // Fields must be private
#pragma warning restore S1104 // Fields should not have public accessibility

/// <summary>
/// Holds the value of the static text property.
/// </summary>
private static string staticTextSetProperty;

/// <summary>
/// Provides a list for the indexer.
/// </summary>
private readonly IList<string> list = new List<string> { "111" };

/// <summary>
/// Holds the value of the static text property.
/// </summary>
private string textSetProperty;

/// <summary>
/// Gets text.
/// </summary>
public static string StaticTextGetProperty { get; }

/// <summary>
/// Sets text.
/// </summary>
#pragma warning disable S2376 // Write-only properties should not be used
public static string StaticTextSetProperty
{
set
{
staticTextSetProperty = value;
}
}
#pragma warning restore S2376 // Write-only properties should not be used

/// <summary>
/// Gets or sets the static text.
/// </summary>
public static string StaticTextProperty { get; set; }

/// <summary>
/// Gets the text.
/// </summary>
public string TextGetProperty { get; }

/// <summary>
/// Sets text.
/// </summary>
#pragma warning disable S2376 // Write-only properties should not be used
public string TextSetProperty
{
set
{
this.textSetProperty = value;
}
}
#pragma warning restore S2376 // Write-only properties should not be used

/// <summary>
/// Gets or sets the text.
/// </summary>
Expand Down
78 changes: 78 additions & 0 deletions Heleonix.Reflection.Tests/ReflectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,91 @@

namespace Heleonix.Reflection.Tests
{
using System.Reflection;
using Heleonix.Reflection.Tests.Common.Dummies;
using Heleonix.Testing.NUnit.Aaa;
using NUnit.Framework;
using static Heleonix.Testing.NUnit.Aaa.AaaSpec;

/// <summary>
/// Tests the <see cref="Reflector"/>.
/// </summary>
[ComponentTest(Type = typeof(Reflector))]
public static partial class ReflectorTests
{
/// <summary>
/// Tests the <see cref="Reflector.IsStatic(System.Reflection.PropertyInfo)"/>.
/// </summary>
[MemberTest(Name =nameof(Reflector.IsStatic))]
public static void IsStatic()
{
var result = false;
PropertyInfo propertyInfo = null;

Act(() =>
{
result = Reflector.IsStatic(propertyInfo);
});

When("the pased parameter is null", () =>
{
propertyInfo = null;

Should("return false", () =>
{
Assert.That(result, Is.False);
});
});

When("the pased parameter is non-static property", () =>
{
propertyInfo = typeof(SubSubItem).GetProperty("TextProperty");

Should("return false", () =>
{
Assert.That(result, Is.False);
});
});

When("the pased parameter is static get property", () =>
{
propertyInfo = typeof(SubSubItem).GetProperty("StaticTextGetProperty");

Should("return true", () =>
{
Assert.That(result, Is.True);
});
});

When("the pased parameter is static set property", () =>
{
propertyInfo = typeof(SubSubItem).GetProperty("StaticTextSetProperty");

Should("return true", () =>
{
Assert.That(result, Is.True);
});
});

When("the pased parameter is non-static set property", () =>
{
propertyInfo = typeof(SubSubItem).GetProperty("TextSetProperty");

Should("return false", () =>
{
Assert.That(result, Is.False);
});
});

When("the pased parameter is non-static get property", () =>
{
propertyInfo = typeof(SubSubItem).GetProperty("TextGetProperty");

Should("return false", () =>
{
Assert.That(result, Is.False);
});
});
}
}
}

0 comments on commit d75a390

Please sign in to comment.