dimanche 26 avril 2020

How to assert that collection is IReadOnlyCollection using NUnit

I have a method in SomeClass, which return IReadOnlyCollection. Something like that:

    public calss SomeClass
{
   private readonly List<Part> _parts;

   ...

   public IReadOnlyCollection<Part> GetAllParts =>
            this._parts;
}

In my Unit tests I want to assert that returned collection (expectedCollection) is IReadOnlyCollection. I have tried with reflection:

[Test]
        public void TestWariorsShoudReturnReadOnlyCollectionOfWariors()
        {
            var expectedCollection = MyPartsLib.GetAllParts;

            Type type = expectedCollection.GetType();
            string acctualtypeName = type.Name;
            string expectedTypeName = "IReadOnlyCollection";
            Assert.AreEqual(expectedTypeName,acctualtypeName);
        }

But acctualtypeName after executing is List`1. How can I assert that expectedCollection is IReadOnlyCollection?

Thanks for you help.





Aucun commentaire:

Enregistrer un commentaire