Quantcast
Channel: Fluent Assertions
Viewing all 1402 articles
Browse latest View live

Edited Feature: Extended reporting for ShouldBeEquivalentTo [12472]

$
0
0
Fluent Assertion 2.0 has excellent method to compare objects: ShouldBeEquivalentTo. It works great for most cases, but stops as soon as a first not matching property or field is found. From time to time it is good to display complete difference between objects (all properties). It provides deep information for cases when several related properties have unexpected values.

Now we are using KellermanSoftware.CompareNetObjects for this purpose. This library is able to report a complete list of differences between two objects, but ideally we would like to have the same functionality directly in FluentAssertions. Is it possibly to implement such extended reporting for the ShouldBeEquivalentTo method?

Commented Feature: Extended reporting for ShouldBeEquivalentTo [12472]

$
0
0
Fluent Assertion 2.0 has excellent method to compare objects: ShouldBeEquivalentTo. It works great for most cases, but stops as soon as a first not matching property or field is found. From time to time it is good to display complete difference between objects (all properties). It provides deep information for cases when several related properties have unexpected values.

Now we are using KellermanSoftware.CompareNetObjects for this purpose. This library is able to report a complete list of differences between two objects, but ideally we would like to have the same functionality directly in FluentAssertions. Is it possibly to implement such extended reporting for the ShouldBeEquivalentTo method?
Comments: Added in commit: http://fluentassertions.codeplex.com/SourceControl/changeset/92fd4e10a7c7

Edited Issue: HaveElement should support XNames [12453]

$
0
0
See discussion http://stackoverflow.com/questions/12099510/how-to-test-xelement-and-its-child-elements

Closed Issue: BeOfTypeImplements to test IEnumerable instead of specific implementation (list/dictionary) [12463]

$
0
0
Unit tests for my controller include type validation of the model.
I first attempted:
ViewResult.Model.Should().BeOfType<IEnumerable<model>>()

but it failed, stating that the type is List<model>
This is true, but I don't want to worry about that during my testing... I just need to verify that the model is IEnumerable

As a result, I must use:
ViewResult.Model.GetType().Implements<IEnumerable<model>>().Should().BeTrue()

I would prefer something along the lines of:
- some sort of optional parameter for the BeOfType() to allow classes that inherit/implement T
or
- BeOfTypeImplementing<>


PS: keep up the great work... FA is probably my most frequently used nuget package :)
Comments: An alternative is provided.

New Post: ShouldBeEquivalentTo method still relies on override of Object.Equals()?

$
0
0
In the FA 2.1 branch, I've fixed this behavior. I will also make the list of steps public so that you can tweak it to your needs.

Created Issue: AssertEquality - include property value [12480]

$
0
0
If properties are not equal and property types are the same - show expected and actual property values. This would greatly help debugging the issue.

I ran into the problem when using ShouldAllBeEquivalentTo

Commented Issue: AssertEquality - include property value [12480]

$
0
0
If properties are not equal and property types are the same - show expected and actual property values. This would greatly help debugging the issue.

I ran into the problem when using ShouldAllBeEquivalentTo
Comments: Hi Ornus, I'm not sure I understand your issue because what you're saying is exactly what it does now. It will always list both the property path, the expected value and the actual value. Regards, Dennis

Commented Issue: AssertEquality - include property value [12480]

$
0
0
If properties are not equal and property types are the same - show expected and actual property values. This would greatly help debugging the issue.

I ran into the problem when using ShouldAllBeEquivalentTo
Comments: I only see the property name and property types. From looking at the code, it's showing this brief information as designed: AssertionRule.AssertEquality It only shows property types there. Doesn't check for values nor attempts to show values. This is the problem when I'm doing ShouldAllBeEquivalentTo, not regular Should()

Commented Issue: AssertEquality - include property value [12480]

$
0
0
If properties are not equal and property types are the same - show expected and actual property values. This would greatly help debugging the issue.

I ran into the problem when using ShouldAllBeEquivalentTo
Comments: Can you compare your scenario with EquivalencySpecs.When_two_lists_dont_contain_the_same_structural_equal_objects_it_should_throw()? If I disable the exception handling in the spec, the output is (as I expected): Expected item[1].Age to be 30, but found 24. Using configuration: - Select all declared properties - Match property by name (or throw) - FluentAssertions.Equivalency.AssertionRule`1[System.DateTime] - FluentAssertions.Equivalency.AssertionRule`1[System.String]

Created Issue: ShouldBeEquivalentTo crashes on signature hiding properties [12481]

$
0
0
Take this example. Foo is overriden with new. This crashes TypeExtensions.FindProperty because it will see object Foo and string Foo

```c#
[TestMethod]
public void FluentAssertionsTest()
{
var a1 = new B<string> { Foo = "test" };
var a2 = new E<string> { Foo = "test" };

a1.ShouldBeEquivalentTo(a2);
//a1.ShouldBeEquivalentTo(a2, ex => ex.Using(new MustMatchByNameAndTypeRule()));
}

public class A
{
public object Foo { get; set; }
}

public class B<T> : A
{
public new T Foo
{
get
{
return (T)base.Foo;
}

set
{
base.Foo = value;
}
}
}

public class D
{
public object Foo { get; set; }
}

public class E<T> : D
{
public new T Foo
{
get
{
return (T)base.Foo;
}

set
{
base.Foo = value;
}
}
}
```

My suggestion is to add 2 new matchers:
```c#
public class MustMatchByNameAndTypeRule : IMatchingRule
{
public PropertyInfo Match(PropertyInfo subjectProperty, object expectation, string propertyPath)
{
PropertyInfo compareeProperty = expectation.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.SingleOrDefault(pi => pi.Name == subjectProperty.Name && pi.PropertyType == subjectProperty.PropertyType);

if (compareeProperty == null)
{
string path = (propertyPath.Length > 0) ? propertyPath + "." : "property ";

Execute.Verification.FailWith(
"Subject has " + path + subjectProperty.Name + " that the other object does not have.");
}

return compareeProperty;
}

public override string ToString()
{
return "Match property by name and type (or throw)";
}
}

public class TryMatchByNameAndTypeRule : IMatchingRule
{
public PropertyInfo Match(PropertyInfo subjectProperty, object expectation, string propertyPath)
{
PropertyInfo compareeProperty = expectation.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.SingleOrDefault(pi => pi.Name == subjectProperty.Name && pi.PropertyType == subjectProperty.PropertyType);

return compareeProperty;
}

public override string ToString()
{
return "Try to match property by name and type";
}
}
```

New Post: ShouldBeEquivalentTo method still relies on override of Object.Equals()?

$
0
0
Hi Dennis,

Thanks for addressing this need. Is there a defect number or feature request I can track?
-Mitch

New Post: ShouldBeEquivalentTo method still relies on override of Object.Equals()?

$
0
0
Hi Mitch,

The commit that fixes the Equals() problem can be tracked here.

For opening up the list I had some local changes that I lost because I didn't know that checking out another branch in Git can have some unexpected effects. Will apply that tonight or tomorrow.

Commented Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```
Comments: Hi Dennis Do you have an estimation when a new version of Fluent Assert is in Nuget which fixes this bug. Thanks Mike

Commented Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```
Comments: 2.1 is still a few weeks away, so I'm thinking of releasing a 2.0.1 that fixes those type-load issues.

Commented Issue: ShouldBeEquivalentTo crashes on signature hiding properties [12481]

$
0
0
Take this example. Foo is overriden with new. This crashes TypeExtensions.FindProperty because it will see object Foo and string Foo

```c#
[TestMethod]
public void FluentAssertionsTest()
{
var a1 = new B<string> { Foo = "test" };
var a2 = new E<string> { Foo = "test" };

a1.ShouldBeEquivalentTo(a2);
//a1.ShouldBeEquivalentTo(a2, ex => ex.Using(new MustMatchByNameAndTypeRule()));
}

public class A
{
public object Foo { get; set; }
}

public class B<T> : A
{
public new T Foo
{
get
{
return (T)base.Foo;
}

set
{
base.Foo = value;
}
}
}

public class D
{
public object Foo { get; set; }
}

public class E<T> : D
{
public new T Foo
{
get
{
return (T)base.Foo;
}

set
{
base.Foo = value;
}
}
}
```

My suggestion is to add 2 new matchers:
```c#
public class MustMatchByNameAndTypeRule : IMatchingRule
{
public PropertyInfo Match(PropertyInfo subjectProperty, object expectation, string propertyPath)
{
PropertyInfo compareeProperty = expectation.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.SingleOrDefault(pi => pi.Name == subjectProperty.Name && pi.PropertyType == subjectProperty.PropertyType);

if (compareeProperty == null)
{
string path = (propertyPath.Length > 0) ? propertyPath + "." : "property ";

Execute.Verification.FailWith(
"Subject has " + path + subjectProperty.Name + " that the other object does not have.");
}

return compareeProperty;
}

public override string ToString()
{
return "Match property by name and type (or throw)";
}
}

public class TryMatchByNameAndTypeRule : IMatchingRule
{
public PropertyInfo Match(PropertyInfo subjectProperty, object expectation, string propertyPath)
{
PropertyInfo compareeProperty = expectation.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.SingleOrDefault(pi => pi.Name == subjectProperty.Name && pi.PropertyType == subjectProperty.PropertyType);

return compareeProperty;
}

public override string ToString()
{
return "Try to match property by name and type";
}
}
```
Comments: I'll need to check that sample out. I'm currently working on 2.1, but it might take a couple of weeks to fix.

Commented Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```
Comments: Hmm, I just noticed that the 2.0 version of the AttributeBasedFormatter is actually already intercepting that exception. Don't understand why it still bubbles through...

Source code checked in, #be730a9b66d1

Source code checked in, #f8a3077d06ec

$
0
0
Removed the old pre-Git releases folder

Source code checked in, #98604628836d

$
0
0
Small bug-fix to better intercept and/or prevent exceptions while scanning for methods annotated with [ValueFormatter]. Updated version number to 2.0.1

Updated Release: Release 2.0.1 (Oct 07, 2012)

Viewing all 1402 articles
Browse latest View live