fluentassertions / fluentassertions.mvc

Fluent Assertions extensions for ASP.NET MVC
Microsoft Public License
35 stars 10 forks source link

Problem with BeOfType and IReadOnlyList #25

Closed firehorseuk closed 9 years ago

firehorseuk commented 9 years ago

Hi,

I seem to have a problem comparing types. VS2013.4 FA 3.3.0

using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using FluentAssertions;

namespace IReadOnlyList {     [TestClass]     public class UnitTest1     {         [TestMethod]         public void IReadOnlyListTest()         {             var newOrder = new Order();

            Assert.IsInstanceOfType(newOrder.Items, typeof(IReadOnlyList<OrderItem>)); // Works fine             newOrder.Items.Should().BeOfType(typeof(IReadOnlyList<OrderItem>)); // Error in comparison             newOrder.Items.Should().BeOfType<IReadOnlyList<OrderItem>>(); // Error in comparison         }     }

    public class OrderItem     {         public string Partid { get; set; }     }

    public class Order     {         public string OrderId { get; set; }

        private List<OrderItem> OrderItems { get; set; }

        public Order()         {             OrderItems = new List<OrderItem>();         }

        public IReadOnlyList<OrderItem> Items         {             get             {                 return OrderItems;             }         }     } }

I get the following error when running the unit test Test Name: IReadOnlyListTest Test FullName: IReadOnlyList.UnitTest1.IReadOnlyListTest Test Source: c:\Users\Alan\Documents\Visual Studio 2013\Projects\FluentAssertions\IReadOnlyList\IReadOnlyList\UnitTest1.cs : line 12 Test Outcome: Failed Test Duration: 0:00:00.032261

Result Message: Expected type to be System.Collections.Generic.IReadOnlyList1[[IReadOnlyList.OrderItem, IReadOnlyList, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], but found System.Collections.Generic.List1[[IReadOnlyList.OrderItem, IReadOnlyList, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. Result StackTrace:
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message) in z:\Builds\work\b7ceef20fdfcf0ee\Shared\Execution\LateBoundTestFramework.cs:line 22 at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message) in z:\Builds\work\b7ceef20fdfcf0ee\FluentAssertions.Net40\Execution\TestFrameworkProvider.cs:line 42 at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message) in z:\Builds\work\b7ceef20fdfcf0ee\FluentAssertions.Core\Execution\DefaultAssertionStrategy.cs:line 25 at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in z:\Builds\work\b7ceef20fdfcf0ee\FluentAssertions.Core\Execution\AssertionScope.cs:line 197 at FluentAssertions.Types.TypeAssertions.Be(Type expected, String because, Object[] reasonArgs) in z:\Builds\work\b7ceef20fdfcf0ee\FluentAssertions.Core\Types\TypeAssertions.cs:line 53 at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeOfType(Type expectedType, String because, Object[] reasonArgs) in z:\Builds\work\b7ceef20fdfcf0ee\FluentAssertions.Core\Primitives\ReferenceTypeAssertions.cs:line 143 at IReadOnlyList.UnitTest1.IReadOnlyListTest() in c:\Users\Alan\Documents\Visual Studio 2013\Projects\FluentAssertions\IReadOnlyList\IReadOnlyList\UnitTest1.cs:line 16

I'm expecting System.Collections.Generic.IReadOnlyList1 back from newOrder.Items but FluentAssertions seems to be picking up System.Collections.Generic.List1

MS Test Assert.IsInstanceOfType(newOrder.Items, typeof(IReadOnlyList)); seems to pick it up correctly, but FA newOrder.Items.Should().BeOfType(typeof(IReadOnlyList)); seems to pick up the underlying private type of List rather than the exposed public IReadOnlyList

I'm just wondering if I have the syntax for Fluent Assertions wrong or if there is a bug in FA.

Thanks

kevinkuszyk commented 9 years ago

That looks like an issue with the FA core. Can you post it over on the Fluent Assertions project?