From d75a390f90c322ef6a35ff9b7d065a437c634637 Mon Sep 17 00:00:00 2001 From: Hennadii Lutsyshyn Date: Sat, 8 Oct 2022 12:07:51 +0300 Subject: [PATCH] Test coverage increased to 100%. --- .../Common/Dummies/SubSubItem.cs | 41 ++++++++++ Heleonix.Reflection.Tests/ReflectorTests.cs | 78 +++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/Heleonix.Reflection.Tests/Common/Dummies/SubSubItem.cs b/Heleonix.Reflection.Tests/Common/Dummies/SubSubItem.cs index f44558b..012bba6 100644 --- a/Heleonix.Reflection.Tests/Common/Dummies/SubSubItem.cs +++ b/Heleonix.Reflection.Tests/Common/Dummies/SubSubItem.cs @@ -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 + /// + /// Holds the value of the static text property. + /// + private static string staticTextSetProperty; + /// /// Provides a list for the indexer. /// private readonly IList list = new List { "111" }; + /// + /// Holds the value of the static text property. + /// + private string textSetProperty; + /// /// Gets text. /// public static string StaticTextGetProperty { get; } + /// + /// Sets text. + /// +#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 + /// /// Gets or sets the static text. /// public static string StaticTextProperty { get; set; } + /// + /// Gets the text. + /// + public string TextGetProperty { get; } + + /// + /// Sets text. + /// +#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 + /// /// Gets or sets the text. /// diff --git a/Heleonix.Reflection.Tests/ReflectorTests.cs b/Heleonix.Reflection.Tests/ReflectorTests.cs index 751f034..1da114d 100644 --- a/Heleonix.Reflection.Tests/ReflectorTests.cs +++ b/Heleonix.Reflection.Tests/ReflectorTests.cs @@ -5,7 +5,11 @@ 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; /// /// Tests the . @@ -13,5 +17,79 @@ namespace Heleonix.Reflection.Tests [ComponentTest(Type = typeof(Reflector))] public static partial class ReflectorTests { + /// + /// Tests the . + /// + [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); + }); + }); + } } }