Giter VIP home page Giter VIP logo

Comments (3)

stevenaw avatar stevenaw commented on June 9, 2024 1

This is a neat idea, so I'm going to label it idea for the team to consider.
One thought about option 2 here is that if the expected is the same POCO type and not all properties are specified then it may be tough for the framework to understand if a prop not listed, and thus with a default value, should be considered or not. One alternative option which could be considered is passing an anonymous object instead.

Perhaps some variation involving:

Assert.That(thing, Is.EqualTo(new {
    SomeInt = 5,
    SomeDouble = 5d,
    SomeString = "bla bla don't care",
}).UsingPropertiesComparer());

from nunit.

Rabadash8820 avatar Rabadash8820 commented on June 9, 2024

Ooh that's a cool idea. I assumed some Expression magic would be necessary for NUnit to distinguish whether a property was provided or not, but simply iterating the provided properties on an anonymous (or dynamic) object could be simpler. FWIW, I got this idea from ts-mockito (a TypeScript mocking library inspired by Java's Mockito library), where such "sub-equality" comparisons are possible. This may be due to the "duck typing" that TS uses under the hood, so I wasn't sure if this would be possible in .NET, but hopefully it will be with one of the above approaches.

from nunit.

mikkelbu avatar mikkelbu commented on June 9, 2024

@Rabadash8820 Usually, when I have to do assertions like this, then I use an assertion framework - e.g. FluentAssertions. Using FluentAssertions can specify it like this

orderDto.Should().BeEquivalentTo(order, options => options
    .Including(o => o.OrderNumber)
    .Including(pi => pi.Name == "Date"));

Or perhaps using ExcludingMissingMembers to only compare the properties that exists in both objects that are being compared

from nunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.