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

Commented Issue: Test framework detection using assembly scanning is case sensitive [12483]

$
0
0
LateBoundTestFramework checks if an assembly with the given name is loaded. But the check is case sensitive. Therefore in our case the NUnit cannot be determined - NUnitTestFramework defines "nunit.framework" assembly, but we have "NUnit.Framework" instead.

Suggested one line fix would be in LateBoundTestFramework::IsAvailable - call overloaded StartsWith method which takes StringComparison.InvariantCultureIgnoreCase instead.
Comments: The proposed solution has been applied.

Edited Issue: Add NotStartWith and NotEndWith methods [12441]

$
0
0
Add NotEndWith, NotStartWith, NotEndWithEquivalent and NotStartWithEquivalent.

Commented Issue: Test framework detection using assembly scanning is case sensitive [12483]

$
0
0
LateBoundTestFramework checks if an assembly with the given name is loaded. But the check is case sensitive. Therefore in our case the NUnit cannot be determined - NUnitTestFramework defines "nunit.framework" assembly, but we have "NUnit.Framework" instead.

Suggested one line fix would be in LateBoundTestFramework::IsAvailable - call overloaded StartsWith method which takes StringComparison.InvariantCultureIgnoreCase instead.
Comments: wow, this was really fast! Thank you very much :)

New Post: Why so many negation methods?

$
0
0
Yeah you can either do it.Should().Not().BeWhatever() or it.ShouldNot().BeWhatever(), obviously there are few options here but instead of introducing a breaking change, I'd imagine you can create the functionality without breaking anything and let people the time they need to adapt it.

Well, it might not save you time but it will streamline the APIs and make it easier to work with because ShouldNot() (or Should().Not()) and Should() will look exactly the same and it may simplify a thing or two in the design itself.

Commented Issue: Extend ShouldThrow*() to Func [12148]

$
0
0
Extend the ShouldThrow*() methods for Func<Task> too so you can work with async methods:

Func<Task> foo = async () => { await DoSthAsync(); }
foo.ShouldThrow<ArgumentNullException>();
Comments: Could it be also included in Windows Phone package? It'd be really useful for a asynchronous-like interface as WP. Currently, I see it is only available in WinRT.

New Post: Exception in Excluding from nested property.

$
0
0
hi
I tried exclude from test one property how writing in Docs:
orderDto.ShouldBeEquivalentTo(order, options => options.Excluding(o => o.Products[1].Status));
My classes:
public class Product
    {
        public String name { get; set; }
        public Int32 Status { get; set; }
    }
public class Order
    {
        public Int32 Id { get; set; }
        public List<Product> Products { get; set; }
    }
My test:
[Test]
        public void test()
        {
            Order order1 = new Order();
            order1.Products = new List<Product>();
            order1.Products.Add(new Product());
            order1.Products.Add(new Product());

            Order order2 = new Order();
            order2.Products = new List<Product>();
            order2.Products.Add(new Product());
            order2.Products.Add(new Product());

            order2.ShouldBeEquivalentTo(order1, options =>options.Excluding(o => o.Products[0].Status)); 
        }
But Test Failed with:
System.ArgumentException : Expression {Convert(o.Products.get_Item(0).Status)} is not a valid property expression
if i write:
order2.ShouldBeEquivalentTo(order1, options =>options.Excluding(o => o.Products[0]));
Test failed with:
System.ArgumentException : Expression {o.Products.get_Item(0)} is not a valid property expression

When i write:
order2.ShouldBeEquivalentTo(order1, options =>options.Excluding(o => o.Products));
Test is success.

What am I doing wrong?
Thanks.

New Post: Exception in Excluding from nested property.

$
0
0
I think using an Expression with an indexer only works if the collection is an array. You should use the overload that takes a Func<ISubjectInfo, bool>() to compare the property path against "Products[0].Status".

New Post: Exception in Excluding from nested property.

$
0
0
dennisdoomen wrote:
I think using an Expression with an indexer only works if the collection is an array. You should use the overload that takes a Func<ISubjectInfo, bool>() to compare the property path against "Products[0].Status".
Big Thanks!!!

Yes
I wrote:
public class Order
    {
        public Int32 Id { get; set; }
        public Product[] Products { get; set; }
    }

~~~~~~~
[Test]
~~~
order2.ShouldBeEquivalentTo(order1, options => options.Excluding(o => o.Products[0].Status).Excluding(o => o.Products[1].Status));
And test is success.
With List<Product> don't working :( May can used List<T> ?
private List<Product> _product;
public Product[] Products 
{
   get{ return _product.ToArray(); }
}
is bad option.

And second question:
How can exclude property Status from class Product for all elements of array?
Thanks.

New Post: Exception in Excluding from nested property.

$
0
0
Then you need the other overload and use the string-representation of the PropertyPath property on ISubjectInfo.

New Post: Exception in Excluding from nested property.

$
0
0
dennisdoomen wrote:
Then you need the other overload and use the string-representation of the PropertyPath property on ISubjectInfo.
You can a sample please?
Thanks.

Edited Issue: Add NotStartWith and NotEndWith methods [12441]

$
0
0
Add NotEndWith, NotStartWith, NotEndWithEquivalent and NotStartWithEquivalent.

Closed Issue: Nullable does not provide BeNull() extensions [12459]

$
0
0
The extension methods available for asserting the state of a Nullable<Guid> value only cater for the Guid type and not the nullable condition. I expected that I could assert that the value either is or is not null, but all I have use is the *Be and *BeEmpty methods.
Comments: Not a bug.

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

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);
}
}
}
Comments: That's because the object implements IEnumerable. If you want to force FA to use an alternative comparison, you need to override that behavior using the Using<T>() method on the options object. See specification When_an_assertion_is_overridden_for_a_predicate_it_should_use_the_provided_action() in EquivalencySpecs.cs for an example.

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

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);
}
}
}
Comments: Behavior is by design.

Edited 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

Edited Issue: Inconsistent ShouldBeEquivalentTo() behaviour for collections of complex types [12484]

$
0
0
I'm having trouble comparing lists of objects that come back in an indeterminate order. I thought `ShouldBeEquivalentTo()` would take care of this for me, but it doesn't seem to :(
Check out the comments in following sample class for a more thorough description.
```
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;

namespace CrazyMo.Tests
{
[TestFixture]
public class ShouldBeEquivalentToTests
{
public class SomeClass
{
public int SomeInt { get; set; }
}
[Test]
public void DoSomethingAwesome_Scenario_ExpectedResult()
{
SomeClass some1 = new SomeClass { SomeInt = 1 };
SomeClass someOther1 = new SomeClass { SomeInt = 1 };
some1.ShouldBeEquivalentTo(someOther1); // This works

IEnumerable<int> someInts = new List<int> {1, 2};
IEnumerable<int> someOtherInts = new List<int> {2, 1};
someInts.Should().BeEquivalentTo(someOtherInts); // This works
someInts.Should().BeEquivalentTo(2, 1); // This works

IEnumerable<SomeClass> actual = new List<SomeClass>
{
new SomeClass{SomeInt = 1},
new SomeClass{SomeInt = 2}
};

// This does work
actual.ShouldBeEquivalentTo(new List<SomeClass>{
new SomeClass { SomeInt = 1 },
new SomeClass { SomeInt = 2 }
});


// The following is in reverse order, just like someOtherInts above.
// This doesn't work, but should?
actual.ShouldBeEquivalentTo(new List<SomeClass>
{
new SomeClass{SomeInt = 2},
new SomeClass{SomeInt = 1}
});
// This is similar to BeEquivalentTo(2, 1) above, but doesn't work.
// It's even in the correct order.
actual.Should().BeEquivalentTo(
new SomeClass { SomeInt = 1 },
new SomeClass { SomeInt = 2 }
);

}
}
}
```

Commented Issue: Inconsistent ShouldBeEquivalentTo() behaviour for collections of complex types [12484]

$
0
0
I'm having trouble comparing lists of objects that come back in an indeterminate order. I thought `ShouldBeEquivalentTo()` would take care of this for me, but it doesn't seem to :(
Check out the comments in following sample class for a more thorough description.
```
using System.Collections.Generic;
using FluentAssertions;
using NUnit.Framework;

namespace CrazyMo.Tests
{
[TestFixture]
public class ShouldBeEquivalentToTests
{
public class SomeClass
{
public int SomeInt { get; set; }
}
[Test]
public void DoSomethingAwesome_Scenario_ExpectedResult()
{
SomeClass some1 = new SomeClass { SomeInt = 1 };
SomeClass someOther1 = new SomeClass { SomeInt = 1 };
some1.ShouldBeEquivalentTo(someOther1); // This works

IEnumerable<int> someInts = new List<int> {1, 2};
IEnumerable<int> someOtherInts = new List<int> {2, 1};
someInts.Should().BeEquivalentTo(someOtherInts); // This works
someInts.Should().BeEquivalentTo(2, 1); // This works

IEnumerable<SomeClass> actual = new List<SomeClass>
{
new SomeClass{SomeInt = 1},
new SomeClass{SomeInt = 2}
};

// This does work
actual.ShouldBeEquivalentTo(new List<SomeClass>{
new SomeClass { SomeInt = 1 },
new SomeClass { SomeInt = 2 }
});


// The following is in reverse order, just like someOtherInts above.
// This doesn't work, but should?
actual.ShouldBeEquivalentTo(new List<SomeClass>
{
new SomeClass{SomeInt = 2},
new SomeClass{SomeInt = 1}
});
// This is similar to BeEquivalentTo(2, 1) above, but doesn't work.
// It's even in the correct order.
actual.Should().BeEquivalentTo(
new SomeClass { SomeInt = 1 },
new SomeClass { SomeInt = 2 }
);

}
}
}
```
Comments: I'm going to ignore the order of items in collections by default starting with 2.1.0.

Edited Issue: DateTimeOffset support [12464]

$
0
0
It would be great if FA supported DateTimeOffset in the same way it supported DateTime.

Created 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: 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!
Viewing all 1402 articles
Browse latest View live


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