Add ShouldBeLike #103

Closed
lanwin opened this Issue May 10, 2012 · 9 comments

Comments

Projects
None yet
4 participants

lanwin commented May 10, 2012

Simple example

foo.ShouldBeLike(new{
Id=123,
Name="foobar"
});

This does not use Equals for check. Instead it checks each property with reflection. This way its very easy to check multiple properties of an object without having an instance of that object before and without having to impl Equals for each object.

rho24 commented May 11, 2012

rho24@49e4858

I've had a go at an implementation. Couldn't figure out how to link to the commit properly so any tips would be handy!

lanwin commented May 31, 2012

Nice! Ive totally overlooked your comment.

I have build some prototype code to make a comparison of a complete object graph instead of only the local properties.

https://gist.github.com/2841822

What do you think?

rho24 commented May 31, 2012

Looks good, i'll try and get round to merging it with my bits this weekend. Or if you want feel free to fork my branch and do it yourself.
Looking at this i'm wondering if it would be useful to test multiple depths e.g.
new{
Id=123,
Name="Bob",
Address = new{
Line1 = "123 Fake Street",
Country = "UK"
}
}

But maybe that's over complicating things...

lanwin commented Jun 3, 2012

Hmm I dont think it will be over complicated and I want it exactly for this scenarios like this.

rho24 commented Jun 4, 2012

Updated implementation which now checks fields, arrays, and nested objects.
rho24@aadce82

lanwin commented Jun 14, 2012

Interesting. Did you send it as pull request?

@rho24 rho24 added a commit to rho24/machine.specifications that referenced this issue Jun 16, 2012

@rho24 rho24 Merge branch 'master' into ShouldBeLike
Implements issue #103
c988f51

rho24 referenced this issue Jun 16, 2012

Closed

Should be like #108

rho24 commented Jun 16, 2012

Pull request attached. Any feedback welcome!

Owner

agross commented Jun 29, 2012

See #108

agross closed this Jun 29, 2012

I wish I had seen this. I would have pointed you to https://github.com/derekgreer/expectedObjects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment