Comments (3)
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.
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.
@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)
- Difference between net5.0/net6.0 and netframework 4.7.2 in test tear down HOT 5
- Either enable partial TestCaseSource combinatorial with Values, or document this is a limitation of TestCaseSource HOT 1
- Re-add "legacy" Assert methods HOT 7
- Constraint helper classes modification request HOT 3
- State that the scope of a `SetUpFixture` is limited to an assembly HOT 2
- Possibilities to estimate the total test duration before starting the first test? HOT 13
- Provide a way to ignore a failed assertion HOT 14
- The dll's in the release 4.1 has version 4.0.1
- Missing possibility to retrieve a test's resulting `ParallelScope` HOT 1
- Improve PropertiesComparer diagnostics HOT 1
- Unexpected GreaterThan(NaN) behavior HOT 2
- AssemblySelectLimit does not work HOT 1
- Is.EqualTo stopped working after upgrade from 4.0.1 to 4.1.0 HOT 3
- Provide generic type definitions for `TestCaseData` to make it type safe. HOT 2
- Stacktrace calls lost on exception of type TargetInvocationException HOT 2
- Sections in Assert.Multiple HOT 3
- [OneTimeSetup] method runs even if all test methods are marked as [Explicit]
- CurrentContext.Result.Outcome.Status is inconclusive in TearDown if Timeout attribute is used in 4.x HOT 3
- `Contains` with a custom comparer does not work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nunit.