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

Edited Feature: Show details about an AggregateException in ShouldNotThrow [12482]

$
0
0
When an AggregateException is thrown it would be nice if ShouldNotThrow shows the details about the inner exception. Now you only see that an AggregateException is thrown, but is is more interesting to know what the inner exceptions are.

Commented Feature: Show details about an AggregateException in ShouldNotThrow [12482]

$
0
0
When an AggregateException is thrown it would be nice if ShouldNotThrow shows the details about the inner exception. Now you only see that an AggregateException is thrown, but is is more interesting to know what the inner exceptions are.
Comments: Fixed in https://fluentassertions.codeplex.com/SourceControl/changeset/e1c6cd2580b4ca4e78adcbeecc1f51d219f9fbbb

Source code checked in, #c80ef7b47411e5af6cd7d751ec7cc5f971a6f625

$
0
0
Merge branch 'master' of https://git01.codeplex.com/forks/groostav/fluentassertionscountingbug into Groostav/FluentAssertionsCountingBug Conflicts: .gitignore

Edited Issue: CollectionAssertions.HaveCount never calls Count property, always Enumerates [12469]

$
0
0
FIrst off, I'm checking out your repo and I'll supply a fix with this issue... tagged in a pull request?

Gents,

public AndConstraint<TAssertions> HaveCount(int expected, string reason = "", params object[] reasonArgs)
{
...
int num = Enumerable.Count<object>(Enumerable.Cast<object>((IEnumerable) this.Subject));
...
}

is no good. In that call to Linq.Enumerable.Cast() --a function which isn't strictly a cast-- you're getting a yielded value from Subject, a type that doesn't actually relate to the original type of Subject. You cant use an uncasted Subject because Count requires a typed IEnumerable, not an untyped one.

I think the best solution is to do a couple things:
- Make HaveCount virtual.
- Have the non-generic one do the type checking to find the best method (either the property Count or manually enumerating via Count()).
- Have the GenericCollectionAssertions() override the Non-generic one and simply call Linq.Enumerable.Count() with an un-modified Subject.

So branch and pull request pending?

Edited Unassigned: CollectionAssertions.Equal does not handle null properly [12490]

$
0
0
I have the following situation:

string[] expected = null;
string[] result = null;

result.Should().Equal(expected) // Throws Exception

"Expected collection to be equal, but found <null>."

Since the result is equal to the expected, this should not throw an exception.

Edited Issue: Windows phone throwing non descript exceptions [12470]

$
0
0
Given the following code.

[TestMethod]
public void InitialiseSession()
{
false.Should().BeTrue();
}

Results in :
New exception: "Could not find windows phone test framework.".

I'm using the latest test framework from toolkit (https://nuget.org/packages/WPToolkitTestFx)

Expected results: "True excepted ... "


Commented Issue: Windows phone throwing non descript exceptions [12470]

$
0
0
Given the following code.

[TestMethod]
public void InitialiseSession()
{
false.Should().BeTrue();
}

Results in :
New exception: "Could not find windows phone test framework.".

I'm using the latest test framework from toolkit (https://nuget.org/packages/WPToolkitTestFx)

Expected results: "True excepted ... "


Comments: Solved in commit https://fluentassertions.codeplex.com/SourceControl/changeset/b8d94a2387fa83afb7ebbe89744b16a0d2623a7d

Closed 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: Seems to be a developer error.

Edited 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
}}
```

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: Why would it use reference equality when it can print out this perfect textual comparison that clearly shows object equality? I shouldn't need to implement an Equals method for simple objects like this where the FluentAssertion was capable of perfectly representing the object in textual form.

Reopened 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
}}
```

Edited 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
}}
```

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: I understand you're reasoning, but .NET itself relies on Equals() for all comparisons. If your object doesn't override the default Equals() provided by Object, you'll end up with reference equality. To support 'structural equality', FA has a specialized API for comparing (collections of) objects. You can read more about that in my blog post http://www.dennisdoomen.net/2012/09/asserting-object-graph-equivalence.html. In the future I might consider using that same engine for the normal collection methods as well, but I'm quite sure most users prefer the current behavior in most cases.

Edited Unassigned: Equal and collections of generics = bad message description [12492]

$
0
0
If a Equal test fail on a collection containing generic types (Class<T>) the test failed message returns a generic error message, telling just the index of the collection were the test failed, instead with a normal object graph the message contains the full object text rapresentation that is really useful.

Class samples:

public class BaseStuff
{
public int StuffId { get; set; }
public string Description { get; set; }
}

public class Stuff<TChild> : BaseStuff
{
public List<TChild> Childs { get; set; }
}

Testing with this code:

stuff.Should().NotBeNull()
.And.HaveCount(2)
.And.Equal(expectedStuff, (t1, t2) => t1.StuffId == t2.StuffId && t1.Description == t2.Description);

Case 1 (good message):

var stuff = new List<BaseStuff>();
var expectedStuff = new List<BaseStuff>();

Returned Message if fails:

Expected collection to be equal to {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "WRONG_DESCRIPTION"
StuffId = 2
}}, but {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "Stuff_2"
StuffId = 2
}} differs at index 1.

Case 2 (bad message):

var stuff = new List<Stuff<int>>();
var expectedStuff = new List<Stuff<int>>();

Returned Message if fails:

Result Message: Expected collection to be equal to {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]}, but {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]} differs at index 1.


Is there possible to have the same fail message also for generics?

I've attached also the complete test class to test the behavior.

New Post: AllProperties for collection

$
0
0
Is this do-able with the AllPropertiesBut condition as well?

New Post: AllProperties for collection

$
0
0
You should use the new API for comparing two collections for structural equality, e.g. collection.ShouldAllBeEquivalentTo().

New Post: AllProperties for collection

$
0
0
So I'll get this:
sessions.Should().HaveCount(1);
sessions.Single().ShouldHave().AllPropertiesBut(x => x.Id).EqualTo(expected);
turning into this:
sessions.ShouldAllBeEquivalentTo(new[] { expected }, config => config.Excluding(x => x.Id));
Correct?

New Post: AllProperties for collection

Edited Unassigned: Equal and collections of generics = bad message description [12492]

$
0
0
If a Equal test fail on a collection containing generic types (Class<T>) the test failed message returns a generic error message, telling just the index of the collection were the test failed, instead with a normal object graph the message contains the full object text rapresentation that is really useful.

Class samples:

public class BaseStuff
{
public int StuffId { get; set; }
public string Description { get; set; }
}

public class Stuff<TChild> : BaseStuff
{
public List<TChild> Childs { get; set; }
}

Testing with this code:

stuff.Should().NotBeNull()
.And.HaveCount(2)
.And.Equal(expectedStuff, (t1, t2) => t1.StuffId == t2.StuffId && t1.Description == t2.Description);

Case 1 (good message):

var stuff = new List<BaseStuff>();
var expectedStuff = new List<BaseStuff>();

Returned Message if fails:

Expected collection to be equal to {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "WRONG_DESCRIPTION"
StuffId = 2
}}, but {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "Stuff_2"
StuffId = 2
}} differs at index 1.

Case 2 (bad message):

var stuff = new List<Stuff<int>>();
var expectedStuff = new List<Stuff<int>>();

Returned Message if fails:

Result Message: Expected collection to be equal to {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]}, but {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]} differs at index 1.


Is there possible to have the same fail message also for generics?

I've attached also the complete test class to test the behavior.

Commented Unassigned: Equal and collections of generics = bad message description [12492]

$
0
0
If a Equal test fail on a collection containing generic types (Class<T>) the test failed message returns a generic error message, telling just the index of the collection were the test failed, instead with a normal object graph the message contains the full object text rapresentation that is really useful.

Class samples:

public class BaseStuff
{
public int StuffId { get; set; }
public string Description { get; set; }
}

public class Stuff<TChild> : BaseStuff
{
public List<TChild> Childs { get; set; }
}

Testing with this code:

stuff.Should().NotBeNull()
.And.HaveCount(2)
.And.Equal(expectedStuff, (t1, t2) => t1.StuffId == t2.StuffId && t1.Description == t2.Description);

Case 1 (good message):

var stuff = new List<BaseStuff>();
var expectedStuff = new List<BaseStuff>();

Returned Message if fails:

Expected collection to be equal to {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "WRONG_DESCRIPTION"
StuffId = 2
}}, but {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "Stuff_2"
StuffId = 2
}} differs at index 1.

Case 2 (bad message):

var stuff = new List<Stuff<int>>();
var expectedStuff = new List<Stuff<int>>();

Returned Message if fails:

Result Message: Expected collection to be equal to {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]}, but {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]} differs at index 1.


Is there possible to have the same fail message also for generics?

I've attached also the complete test class to test the behavior.
Comments: Fixed in commit https://fluentassertions.codeplex.com/SourceControl/changeset/02cf8a5090fcab043d139b2aa3126c5f9cb4d204
Viewing all 1402 articles
Browse latest View live


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