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

Commented Unassigned: Collection should contain other collection behaving unexpectedly [12495]

$
0
0
I want to assert that a collection of simple objects includes a smaller collection of the same object type. For some reason actualCollection.Should().Contain(expectedCollection) is failing with a message that shows all of the expected objects are in the actual collection but it's claiming that they aren't.

Here's the assertion failure output I'm getting:
```
Expected collection {
ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "only me"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}} to contain {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}, but could not find {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}
```
Comments: Thanks for your thoughtful and informative responses. All the objects I care to compare using FA are serializable and a vast majority of them could be made immutable because they are only instantiated by a deserializer.

Edited Feature: Collection should contain other collection behaving unexpectedly [12495]

$
0
0
I want to assert that a collection of simple objects includes a smaller collection of the same object type. For some reason actualCollection.Should().Contain(expectedCollection) is failing with a message that shows all of the expected objects are in the actual collection but it's claiming that they aren't.

Here's the assertion failure output I'm getting:
```
Expected collection {
ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "only me"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}} to contain {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}, but could not find {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}
```

New Post: Narrowing down after BeOfType and similar assertions

$
0
0
A lot of times we do assertions in two steps. For example, we first assert a certain type and then we do more specific assertions on that type.
myVar.Should().BeOfType<SomeSubclass>();
var castedVar = (SomeSubclass)myVar;
castedVar.SubclassProperty.Should().Be("someValue");
But it would be much cleaner if we could write it like:
myVar.Should().BeOfType<SomeSubclass>()
    .AndIts.SubclassProperty.Should().Be("someValue");
Similarly for narrowing down to one item in a collection:
myCollection.Should().HaveCount(1);
var onlyItem = myCollection.Single();
onlyItem.Property.Should().Be("someValue");
Could be much cleaner like:
myCollection.Should().HaveSingleItem()
    .AndIts.Property.Should().Be("someValue");
Same goes for:
myCollection.Should().ContainSingle(i => item.Code == code)
    .AndIts.Property.Should().Be("someValue");
I would love to see that in the next version.

I appreciate the work a lot!

Edited Issue: Fluent assertions v1.7.1 fails to compare nullable timespans [12462]

$
0
0
Not tested with latest version. It seems that an overload on SimpleTimeSpanAssertions which accepts a Nullable<TimeSpan> is missing. I was able to work around this by writing the next extension method:

public static class SimpleTimeSpanAssertionsExtensions
{
// The current version of Fluent Assertions (v1.7.1) seems unable to compare nullable timespans.
// Example: myObject.OptionalTime.Should().Be(expectedOptionalTime);
// This method implements a workaround for this problem.
public static void Be(this SimpleTimeSpanAssertions source, TimeSpan? expected)
{
if (expected == null)
{
source.Subject.As<object>().Should().BeNull();
}
else
{
source.Subject.Should().Be(expected.Value);
}
}
}

I am aware that the return type should not be void and that this method does not have parameters for describing the error. But for the moment it fixes my problem at hand.

Best regards,
Bart Koelman

Edited Issue: WP8: Extend ShouldThrow() to Func [12485]

$
0
0
As fixed for the issue below in WinRT:

http://fluentassertions.codeplex.com/workitem/12148

It would be really useful to be fixed as well for Windows Phone 8. Most of the functionality is also async, so testing must be adpated accordingly.

Thank you very much!

Edited Issue: Fluent Assertions should not format exceptions using the default formatter [12461]

$
0
0
We use a custom ApplicationErrorException which implements IEnumerable returning a list of parameters associated with that exception.

When the verification fails Fluent Assertions formats the exception using the default formatter, which can result in a message like:

Expected System.ApplicationException, but found {[EntityType, Book], [Key, 123]}.

Which is obviously not providing enough information.

Commented Issue: Fluent Assertions should not format exceptions using the default formatter [12461]

$
0
0
We use a custom ApplicationErrorException which implements IEnumerable returning a list of parameters associated with that exception.

When the verification fails Fluent Assertions formats the exception using the default formatter, which can result in a message like:

Expected System.ApplicationException, but found {[EntityType, Book], [Key, 123]}.

Which is obviously not providing enough information.
Comments: 2.1 contains a dedicated formatter for (aggregated) exceptions.

Closed Issue: PropertyAssertion does not throw if a class overwrites Equals(object obj) [12475]

$
0
0
PropertyAssertions do not work properly if a class overwrites the Equals-method:

```
class ClassThatOverwritesEquals
{
public int Age { get; set; }

public override bool Equals(object obj) {
return true;
}
}
```

This will never throw if you compare two instances of the same type:

```
var subject = new ClassThatOverwritesEquals {
Age = 36,
};

var expectation = new ClassThatOverwritesEquals {
Age = 37,
};

Action act = () => subject
.ShouldHave()
.AllProperties()
.EqualTo(expectation, "because {0} are the same", "they");
```

I would guess the problem is in ReferenceEqualityEquivalencyStep.cs line 43:

```
return !ReferenceEquals(context.Subject, null) && context.Subject.Equals(context.Expectation);
```

The Equals(..) should be replaced by object.ReferenceEquals(..).


Comments: During dogfooding 2.1 I came to the conclusion that I have to roll back this change. Other than using the Equals() implementation, there's no reliable way for detecting whether I should continue traversing an object graph. If an object overrides Equals() it is essentially stating that it behaves like a value type (even though it still is a class).

Edited Issue: PropertyAssertion does not throw if a class overwrites Equals(object obj) [12475]

$
0
0
PropertyAssertions do not work properly if a class overwrites the Equals-method:

```
class ClassThatOverwritesEquals
{
public int Age { get; set; }

public override bool Equals(object obj) {
return true;
}
}
```

This will never throw if you compare two instances of the same type:

```
var subject = new ClassThatOverwritesEquals {
Age = 36,
};

var expectation = new ClassThatOverwritesEquals {
Age = 37,
};

Action act = () => subject
.ShouldHave()
.AllProperties()
.EqualTo(expectation, "because {0} are the same", "they");
```

I would guess the problem is in ReferenceEqualityEquivalencyStep.cs line 43:

```
return !ReferenceEquals(context.Subject, null) && context.Subject.Equals(context.Expectation);
```

The Equals(..) should be replaced by object.ReferenceEquals(..).


Edited Feature: Asserting the contents of an XElement [12454]

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

Closed Feature: Asserting the contents of an XElement [12454]

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

Closed Task: Create A4 cheat sheet [10813]

$
0
0
Create an A4-sized cheat sheet with an overview of the supported extension syntax.

Closed Issue: FluentAssertions with Continuous Integration [11205]

$
0
0
it would be nice to have FluentAssertions on a CI environment so that everyone can get the latest and greatest build with correct versioning without having to build it manually.

If you'd like, I can get that running on teamcity.codebetter.com, just let me know. I need your okay because maybe there will be some changes to the build process.

Cheers
Urs

Closed Unassigned: XElement.Should().Match() [12489]

$
0
0
Because there are a lot more things to test than just both attributes and elements.
Currently I use something like this:
``` C#
XElement.As<XNode>().Should().Match<XElement>(x => x.Name == "foo")
```
Comments: Moved to https://github.com/dennisdoomen/fluentassertions/issues/1

Closed Issue: add new string assertion .Should().BeInFormat(format, args) [12467]

$
0
0
This is similar to wildcards, but I think it will be useful too. If maintainers says ok for that I will be happy to contribute an implementation.


Comments: No response

Closed Issue: Add BeNull() for nullable types [12440]

$
0
0
I just added an assertion for a int? field. I expected a Should().BeNull() extension method but it is not there. Writing actual.SomeValue.Should().Be(null); seems wrong compared to all the other nice extension methods.
Comments: Duplicate

Closed Feature: Collection should contain other collection behaving unexpectedly [12495]

$
0
0
I want to assert that a collection of simple objects includes a smaller collection of the same object type. For some reason actualCollection.Should().Contain(expectedCollection) is failing with a message that shows all of the expected objects are in the actual collection but it's claiming that they aren't.

Here's the assertion failure output I'm getting:
```
Expected collection {
ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "only me"
percentage = 0
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}} to contain {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}, but could not find {

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "custom"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "friends of friends"
percentage = 0.333333333333333
},

ActivityServiceTest.DataTypes.SocialItemSummary
{
category = "public"
percentage = 0.333333333333333
}}
```
Comments: Replaced by https://github.com/dennisdoomen/fluentassertions/issues/2

Closed Unassigned: XElement .Should().Be() gives false positives. [12494]

$
0
0
The current implementation of the Be assertion for XElement is implemented in such a way as to cause apparent false positive tests. It only checks the element names, but other Be() assertions in FluentAssertions tend to work closer to equals.

The following test should not pass, but does because the Be comparison does a name check.

[Test]
public void XElement_Be_Assertion_Should_Be_Deeper()
{
var expected =
new XElement("parent"
, new XElement("child"
, new XElement("grandChild")));

var actual =
new XElement("parent"
, new XElement("child"
, new XElement("grandChild2")));

actual.Should().Be(expected);
}

Either Be (And NotBe) should be hidden/removed for XElement or it should do something a much better check:
Worse case the check would be to call ToString() on both XElements and do a string comparison. The reason I don't just resort to this is that the formatted message for a string comparison is not as helpful as a message catered specifically for XElement might be.
Comments: Replaced by https://github.com/dennisdoomen/fluentassertions/issues/3

Closed Unassigned: Print x.0 when x is is a double/float representing a whole number [12493]

$
0
0
I certainly will understand if this does not get picked up since there are a lot of other similar situations that would not be as easy to fix, but it would be a nice-to-have so I thought I would throw it out.

```
var a = new {A = (object) 5};
var b = new {A = (object) 5.0};

a.Should().Be(b);
```

Fails with
> Expected object to be { A = 5 }, but found { A = 5 }.

It would be nice if it failed with
> Expected object to be { A = 5.0 }, but found { A = 5 }.

because then one would not need to go into the debugger to figure out what is different.

Of course this is a very simple example, would be more useful for with things with larger printouts such as more complex objects, or CollectionAssertions.BeEquivalentTo on collections of complex objects.

Comments: Continued on GitHub https://github.com/dennisdoomen/fluentassertions/issues/4

Closed Feature: String comparison with 'ignore whitespace' [12423]

$
0
0
The "Should().BeEquivalentTo()" ignores casing, but it would be great to have an option for ignoring whitespace and tab/carriage return/newline characters as well
Comments: Won't fix
Viewing all 1402 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>