Skip to content

Assertion of type (BeOfType<>) after And fails #1617

@rneeft

Description

@rneeft

Description

Assertion of type after And fails

Complete minimal example reproducing the issue

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace FluentAssertions
{
    [TestClass]
    public class FluentAssertionTest
    {
        private Exception exception = new ArgumentNullException();

        [TestMethod]
        public void This_should_work_but_it_does_not()
        {
            // TestMethod fails: Expected type to be System.ArgumentNullException, 
            // but found FluentAssertions.Primitives.ObjectAssertions.
            exception.Should().NotBeNull().And.Should().BeOfType<ArgumentNullException>();
        }

        [TestMethod]
        public void This_works()
        {
            exception.Should().NotBeNull();
            exception.Should().BeOfType<ArgumentNullException>();
        }
    }
}

Expected behavior:

Both test method to work

Actual behavior:

Test method with And (This_should_work_but_it_does_not) is not working

Versions

FluentAssertions version: 5.10.3 (and 6.0.0-beta0001)
.NET Core 3.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions