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

Created Issue: Output text of a collection assertion should be more friendly [12466]

$
0
0
The output text of a collection assertion (Should().BeEquivalentTo()) should describe specific differences in objects like ShouldHave().AllProperties().EqualTo() does.

Commented Issue: Output text of a collection assertion should be more friendly [12466]

$
0
0
The output text of a collection assertion (Should().BeEquivalentTo()) should describe specific differences in objects like ShouldHave().AllProperties().EqualTo() does.
Comments: Just realized that 2.0 improves support for this scenario with ShouldAllBeEquivalentTo() but I would like to see something more like ShouldAllHave().AllProperties().EqualTo()

New Post: Comparing two IEnumerables for Properties is not working

$
0
0

I have an IEnumerable of HappenedBusinessEvents and one of ExpectedBusinessEvents, and I want to assert that they both contain the same BusinessEvents by value, not by reference.

I tried it with HappenedBusinessEvents.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(ExpectedBusinessEvents);

But it did not work. I have different texts in the 'description' string on both sides, but the test still passes. I have searched the forum but found no solution to my problem. 

 

I would be glad for a hint.

 

Have a nice code,

Marco

New Post: Comparing two IEnumerables for Properties is not working

New Post: Comparing two IEnumerables for Properties is not working

$
0
0

Thank you, 

I tried that, but it is not working. Let me provide a small codeexample:

public class DomainEvent    
{
        public readonly Guid ID;
        public readonly string Info;

        public DomainEvent(Guid iD, string info)
        {
            ID = Id;
            Info = info;
        }
}

[Test]
public void Testing_FluentAssertations()
{
    var newID  = Guid.NewGuid();
            var given   = new[] { new DomainEvent(newID(), info: "SomeInfo")};
            var expect = new[] { new DomainEvent(newID(), info: "SomeInfo")};

            given.ShouldAllBeEquivalentTo(expect);
}

It tells me, that the test fails with: "Expected item[0] to be DomainEvent      info: SomeInfo., but found DomainEventt      info: SomeInfo..

New Post: Comparing two IEnumerables for Properties is not working

$
0
0

The reason that this test is failing, lies in the fact that the DomainEvent class does not have any public properties. This causes the equivalency validation logic to treat it as a simple object, instead of a complex type. Complex types are compared, by looking at their properties, whereas simple objects are compared by reference. If you write your test like this, it will work:

        [TestMethod]        public void Testing_FluentAssertations()        {            var newID = Guid.NewGuid();            var given = new[] { new DomainEvent(newID, "SomeInfo") };            var expect = new[] { new DomainEvent(newID, "SomeInfo") };            given.ShouldAllBeEquivalentTo(expect);        }        internal class DomainEvent        {            public Guid ID { getprivate set; }            public string Info { getprivate set; }            public DomainEvent(Guid id, string info)            {                ID = id;                Info = info;            }        }

New Post: Comparing two IEnumerables for Properties is not working

$
0
0

Thank you very much, of course that was it.

Sorry for the stupid question due to lack of attention on my side :)

Created 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.



Created Issue: BeInOrder does not cater for duplicate values [12468]

$
0
0
The internal method BeInOrder does not cater for duplicate values.

An array like this {1, 6 12, 12, 15 ,17, 26}

Reports that the item at index 2 is in the wrong order. Looking at the code I can see this is because the comparison of items is done with

int indexOfActualItem = Array.IndexOf(actualItems, orderedItem);

Which of course is going to return 2 for both instances of 12.

Created 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?

Commented 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?

Comments: ahh I have to have permissions to create a branch, that makes sense. I don't really want to fork the whole damn repo for something this small, should I just work off master? Presumably you wouldn't let me push. Sorry gents, new at this, can some one point me in the right direction? I'll work off a local branch in the mean time.

Commented 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?

Comments: Should().HaveCount(predicate) doesn't make any sense to me, shouldn't you be giving the predicate to Linq's Count()? What good is a transform on the integer?

Commented 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?

Comments: Alright, created a branch, throughly screwed up my git config but eventually got everything to where it needs to be. A little bit of background context, I'm working on some transactional memory stuff, and asking for the Count property is very different to a transaction than enumerating the whole list, so I'd really like fluent assertions to hit the property if it can.

New Post: name or description of the object being tested?

$
0
0

I'd like to specify the thing being tested? 

For example, when this assertion fails
    target.SystemCheckStatus.Should().Be(SystemCheckStatus.Warning);
the message is
     "Expected object to be Warning, but found Ok."

I'd like the message to be 
    "Expected the status to be Warning, but found Ok."
or
    "Expected systemCheckStatus to be Warning, but found Ok."

Is there a way to do this already?

Created 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 ... "



Created Issue: FluentAssertions 2.0: objects, which are inherited from collections, are always compared as collections even that a comparison only by specified properties was requested. [12471]

$
0
0
In our project we have classes inherited from collections. These classes have own properties and we should compare their instances only by specified properties and ignore data in collections. But the Fluent Assertion's object comparer always compares objects as collections first.

Is this a bug? If not then how to compare similar objects only by specified properties?

Code to test the specified problem.
<pre>
using System;
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;

namespace FluentAssertionsTests
{
[TestFixture]
public class Tests
{
public class TestCollection : List<int>
{
public TestCollection()
{
Uid = Guid.NewGuid();
}

public int CollectionId { get; set; }

public Guid Uid { get; set; }
}

[Test]
public void DifferentCollectionsObjectGraphComparisonTest()
{
var actual = new TestCollection {CollectionId = 1};
actual.Add(1);
var expected = new TestCollection {CollectionId = 1};
expected.Add(2);
// this test failed with "Expected item[0] to be 2, but found 1."
actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.CollectionId));
}

[Test]
public void ObjectGraphComparisonTest()
{
var actual = new TestCollection {CollectionId = 1};
var expected = new TestCollection {CollectionId = 1};
// this test success
actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.CollectionId));

actual.Uid.Should().NotBe(expected.Uid);
// this test success but should be failed because objects has a different Uid
actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.Uid));
// this test success but should be failed because objects has a different Uid
actual.ShouldBeEquivalentTo(expected);
}

[Test]
public void DifferentCollectionsPropertyComparisonTest()
{
var actual = new TestCollection {CollectionId = 1};
actual.Add(1);
var expected = new TestCollection {CollectionId = 1};
expected.Add(2);
// this test failed with "Expected item[0] to be 2, but found 1."
actual.ShouldHave().Properties(p => p.CollectionId).EqualTo(expected);
}

[Test]
public void ObjectPropertyComparisonTest()
{
var actual = new TestCollection {CollectionId = 1};
var expected = new TestCollection {CollectionId = 1};
// this test success
actual.ShouldHave().Properties(p => p.CollectionId).EqualTo(expected);

actual.Uid.Should().NotBe(expected.Uid);
// this test success but should be failed because objects has a different Uid
actual.ShouldHave().Properties(p => p.Uid).EqualTo(expected);
// this test success but should be failed because objects has a different Uid
actual.ShouldHave().AllProperties().EqualTo(expected);
}
}
}
</pre>

Edited Issue: FluentAssertions 2.0: objects, which are inherited from collections, are always compared as collections even that a comparison only by specified properties was requested. [12471]

$
0
0
In our project we have classes inherited from collections. These classes have own properties and we should compare their instances only by specified properties and ignore data in collections. But the Fluent Assertion's object comparer always compares objects as collections first.<br /><br />Is this a bug? If not then how to compare similar objects only by specified properties?<br /><br />Code to test the specified problem.<br /><br />using System;<br />using System.Collections.Generic;<br />using FluentAssertions;<br />using NUnit.Framework;<br /><br />namespace FluentAssertionsTests<br />{<br /> [TestFixture]<br /> public class Tests<br /> {<br /> public class TestCollection : List<int><br /> {<br /> public TestCollection()<br /> {<br /> Uid = Guid.NewGuid();<br /> }<br /><br /> public int CollectionId { get; set; }<br /><br /> public Guid Uid { get; set; }<br /> }<br /><br /> [Test]<br /> public void DifferentCollectionsObjectGraphComparisonTest()<br /> {<br /> var actual = new TestCollection {CollectionId = 1};<br /> actual.Add(1);<br /> var expected = new TestCollection {CollectionId = 1};<br /> expected.Add(2);<br /> // this test failed with "Expected item[0] to be 2, but found 1."<br /> actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.CollectionId));<br /> }<br /><br /> [Test]<br /> public void ObjectGraphComparisonTest()<br /> {<br /> var actual = new TestCollection {CollectionId = 1};<br /> var expected = new TestCollection {CollectionId = 1};<br /> // this test success<br /> actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.CollectionId));<br /><br /> actual.Uid.Should().NotBe(expected.Uid);<br /> // this test success but should be failed because objects has a different Uid<br /> actual.ShouldBeEquivalentTo(expected, options => options.Including(p => p.Uid));<br /> // this test success but should be failed because objects has a different Uid<br /> actual.ShouldBeEquivalentTo(expected);<br /> }<br /><br /> [Test]<br /> public void DifferentCollectionsPropertyComparisonTest()<br /> {<br /> var actual = new TestCollection {CollectionId = 1};<br /> actual.Add(1);<br /> var expected = new TestCollection {CollectionId = 1};<br /> expected.Add(2);<br /> // this test failed with "Expected item[0] to be 2, but found 1."<br /> actual.ShouldHave().Properties(p => p.CollectionId).EqualTo(expected);<br /> }<br /><br /> [Test]<br /> public void ObjectPropertyComparisonTest()<br /> {<br /> var actual = new TestCollection {CollectionId = 1};<br /> var expected = new TestCollection {CollectionId = 1};<br /> // this test success<br /> actual.ShouldHave().Properties(p => p.CollectionId).EqualTo(expected);<br /><br /> actual.Uid.Should().NotBe(expected.Uid);<br /> // this test success but should be failed because objects has a different Uid<br /> actual.ShouldHave().Properties(p => p.Uid).EqualTo(expected);<br /> // this test success but should be failed because objects has a different Uid<br /> actual.ShouldHave().AllProperties().EqualTo(expected);<br /> }<br /> }<br />}

Created Issue: 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 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: This happens when lib is used in windows phone 8 project. Updating the following class fixes the issue internal class WindowsPhoneTestFramework : LateBoundTestFramework { protected override string AssemblyName { get { return "Microsoft.VisualStudio.QualityTools.UnitTesting.Phone"; } } protected override string ExceptionFullName { get { return "Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException"; } } }

New Post: Throw custom exception on failed assertions

$
0
0

Hi, I like the library and I'm about to use it for objects validation in the production code, not in tests. Is it possible to set it to throw my own exception instead of the built-inAssertFailedException?

Viewing all 1402 articles
Browse latest View live


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