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

Created Issue: Misleading AllDeclaredPublicPropertiesSelectionRule class [12486]

$
0
0
I would expect this class to provide a list of public properties only. However under the hood, in the SelectProperties method, it is calling GetNonPrivateProperties which can return protected, internal & public properties.







Created Unassigned: NullReferenceException caused by AttributeBasedFormatter on Mono 3.0.6 [12487]

$
0
0
```
(true).Should().BeFalse();
```

results in

```
System.NullReferenceException : Object reference not set to an instance of an object

at FluentAssertions.Formatting.AttributeBasedFormatter.<FindCustomFormatters>b__4 (System.Type type) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator29`3[System.Type,System.Reflection.MethodInfo,<>f__AnonymousType0`2[System.Type,System.Reflection.MethodInfo]].MoveNext () [0x00059] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.6/_build/mono-3.0.6.git/mcs/class/System.Core/System.Linq/Enumerable.cs:2335
```

Obviously, AttributeBasedFormatter.GetExportedTypes(Assembly) sometimes returns an array that contains null references in Mono, because a ReflectionTypeLoadException is thrown whose Types property contains some null values.

We can easily fix that in AttributeBaseFormatter.FindCustomFormatters():

```
IEnumerable<MethodInfo> source =
from type in AttributeBasedFormatter.AllTypes
where type != null // FIX
from method in type.GetMethods(24)
where method.get_IsStatic()
where method.HasAttribute<ValueFormatterAttribute>()
where method.GetParameters().Count<ParameterInfo>() == 1
select method;
return source.ToArray<MethodInfo>();
```


New Comment on "Documentation"

$
0
0
Could you break down the wiki so that there is a page for each section?

New Post: Adding a method to measure how many times some text repeats within a string

$
0
0
Hello,

I want to measure how many times some text repeats within a string so I'd really love to have additional method that does that.

Here is an example.

int times = 1;
string text = "Some text that should not contain repetitions";

text.Should().Contains("text", times);

Thank you for your hard work.

New Post: Adding a method to measure how many times some text repeats within a string

$
0
0
Thanks for the suggestion.

Could you provide us with the suggested syntax?

New Post: Adding a method to measure how many times some text repeats within a string

$
0
0
Well, overloading Contains seems like one way to do that or adding a new method such as Find?

int times = 3;
string text = "textX textY textZ";
text.Should().Find("text", times);

In addition, I think that it would be a good idea to include an overload that supports StringComparison.

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: Late reply but I was referring to the new MSTest-based unit test framework brought in with the VS2012 Update 2.

New Post: Bug: Optional parameters in .NET 3.5 build

$
0
0
Hi,

I'm working on a project that has target framework of .NET 3.5 and recently imported Fluent Assertions for that specific version. It seems that this build version uses optional parameters that are not supported in earlier versions of .NET than 4.0 I think this should be changed to overloads instead.

Anyone else that have been addressing this problem?

Regards
Niklas

New Post: Bug: Optional parameters in .NET 3.5 build

$
0
0
Actually, you need Visual Studio 2010. Named and optional arguments is just syntactical sugar provided by the compiler and has nothing to do with the .NET Framework version.

New Comment on "Documentation"

$
0
0
I love this to be on a single page. I hate that MS's .Net documentation is too normalized (you have to click on each method just to discover the return type); this one presents all you need to get hands on!

New Post: Support for C# Dynamics

$
0
0
You could try delcaring your test item as an object, that worked for me :) e.g. ((object)queryResult.Single().Value2).Should().NotBeNull

Created Unassigned: string.Should().NotBeNullOrWhitespace(); [12488]

$
0
0
Can a method for NullOrWhitespace be added to String assertions please? A NullOrEmpty already exists, but not one for whitespace.


Cheers

Created 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")
```

Commented 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: Sounds like a good idea.

New Post: Comparing object equivalence for dictionaries

$
0
0
I've been using ShouldBeEquivalentTo() to compare 2 dictionaries, which works fine.

What I want to be do is check that the keys are the same, while the values can be within a range (say within 1 %) through the assertion options. Is this possible?

At the moment I'm doing the following (both dictionaries are sorted by key):
foreach (var o in actual)
{
    expectedValues.Should().ContainKey(o.Key);
    o.Value.Should().BeInRange(oo.Value*0.99, oo.Value*1.01);
}
Which works but doesn't look very elegant...

New Post: Comparing object equivalence for dictionaries

$
0
0
Hi Sarah,

Version 2.0 doesn't even really support dictionaries. It just compares the value pairs in order of appearance. In the upcoming version 2.1, I've added logic that tries to match the values with the same keys. However, what you ask is a bit more special. I don't think it should be core functionality, but in 2.1, you can add your own equivalency step that would do just that.

New Comment on "Documentation"

$
0
0
I have a couple of questions on the section "Object Graph Comparison --> Overriding and collections" orderDto.ShouldBeEquivalentTo(order, options => options .Using<DateTime>(ctx => ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) .WhenTypeIs<DateTime>(); 1) ctx.Date should actually read ctx.Subject, right? 2) If yes, this is not working for me. The validation seems to always succeed even though the corresponding DateTime properties differ greatly. I can provide a sample code if you let me know where. Or if I'm using the feature wrong, I'd appreciate any guidance. I'm using the line above just as it is on this page, except that I'm using my own variable names of course, and that I'm using ctx.Subject instead of ctx.Date

Updated Wiki: Home

$
0
0

Project Description

Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.

Why?

Nothing is more annoying then a unit test that fails without clearly explaining why. More than often, you need to set a breakpoint and start up the debugger to be able to figure out what went wrong. Jeremy D. Miller once gave the advice to "keep out of the debugger hell" and I can only agree with that.

For instance, only test a single condition per test case. If you don't, and the first condition fails, the test engine will not even try to test the other conditions. But if any of the others fail, you'll be on your own to figure out which one. I often run into this problem when developers try to combine multiple related tests that test a member using different parameters into one test case. If you really need to do that, consider using aparameterized test that is being called by several clearly named test cases.

That’s why we designed Fluent Assertions to help you in this area. Not only by using clearly named assertion methods, but also by making sure the failure message provides as much information as possible. Consider this example:

"1234567890".Should().Be("0987654321");

This will be reported as:

clip_image001[6]

The fact that both strings are displayed on a separate line is on purpose and happens if any of them is longer than 8 characters. However, if that's not enough, all assertion methods take an optional formatted reason with placeholders, similarly to String.Format, that you can use to enrich the failure message. For instance, the assertion

new[] { 1, 2, 3 }.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);

will fail with:

clip_image002[6]

Examples

To verify that a string begins, ends and contains a particular phrase.

string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

To verify that a collection contains a specified number of elements and that all elements match a predicate.


IEnumerable collection = new[] { 1, 2, 3 }; collection.Should().HaveCount(4, "because we thought we put three items in the collection"))
collection.Should().Contain(i => i > 0);
The nice thing about the second failing example is that it will throw an exception with the message

"Expected <4> items because we thought we put three items in the collection, but found <3>."

To verify that a particular business rule is enforced using exceptions.

var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For("Milk").WithQuantity(200, Unit.Milliliters))
   .Build();

Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);

action
   .ShouldThrow<RuleViolationException>()
   .WithMessage("change the unit of an existing ingredient", ComparisonMode.Substring)
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);

What’s new?

 
 
March 3rd, 2013
We've released a small bugfix on Nuget and CodePlex.
October 7th, 2012
Version 2.0 is now out of beta.
August 25th, 2012
Fluent Assertions 2.0, a major new version with support for .NET 4.5, Windows Phone and Windows Store Apps is inbeta. Read all the details in this blog post.
  
January 13th, 2012
A relatively small release. Read all about it in this blog post.
 
October 31st, 2011
Another release with lots of bug fixes and small improvements and with great contributions by Martin Opdam and Urs Enzler. Download ithere or get it throughNuGet.
 

About versioning

The version numbers of Fluent Assertions releases comply to the Semantic Versioning scheme. In other words, release 1.4.0 only adds backwards-compatible functionality and bug fixes compared to 1.3.0. Release 1.4.1 should only include bug fixes. And if we ever introduce breaking changes, the number increased to 2.0.0.

Who are we?

We are a bunch of developers working for Aviva Solutions who highly value software quality, in particular

If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.

clip_image002#fluentassertions

Updated Wiki: Home

$
0
0

Project Description

Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.

Why?

Nothing is more annoying then a unit test that fails without clearly explaining why. More than often, you need to set a breakpoint and start up the debugger to be able to figure out what went wrong. Jeremy D. Miller once gave the advice to "keep out of the debugger hell" and I can only agree with that.

For instance, only test a single condition per test case. If you don't, and the first condition fails, the test engine will not even try to test the other conditions. But if any of the others fail, you'll be on your own to figure out which one. I often run into this problem when developers try to combine multiple related tests that test a member using different parameters into one test case. If you really need to do that, consider using aparameterized test that is being called by several clearly named test cases.

That’s why we designed Fluent Assertions to help you in this area. Not only by using clearly named assertion methods, but also by making sure the failure message provides as much information as possible. Consider this example:

"1234567890".Should().Be("0987654321");

This will be reported as:

clip_image001[6]

The fact that both strings are displayed on a separate line is on purpose and happens if any of them is longer than 8 characters. However, if that's not enough, all assertion methods take an optional formatted reason with placeholders, similarly to String.Format, that you can use to enrich the failure message. For instance, the assertion

new[] { 1, 2, 3 }.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);

will fail with:

clip_image002[6]

Examples

To verify that a string begins, ends and contains a particular phrase.

string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

To verify that a collection contains a specified number of elements and that all elements match a predicate.


IEnumerable collection = new[] { 1, 2, 3 }; collection.Should().HaveCount(4, "because we thought we put three items in the collection"))
collection.Should().Contain(i => i > 0);
The nice thing about the second failing example is that it will throw an exception with the message

"Expected <4> items because we thought we put three items in the collection, but found <3>."

To verify that a particular business rule is enforced using exceptions.

var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For("Milk").WithQuantity(200, Unit.Milliliters))
   .Build();

Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);

action
   .ShouldThrow<RuleViolationException>()
   .WithMessage("change the unit of an existing ingredient", ComparisonMode.Substring)
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);

What’s new?

 
 
March 3rd, 2013
We've released a small bugfix on Nuget and CodePlex.
October 7th, 2012
Version 2.0 is now out of beta.
August 25th, 2012
Fluent Assertions 2.0, a major new version with support for .NET 4.5, Windows Phone and Windows Store Apps is inbeta. Read all the details in this blog post.
  
January 13th, 2012
A relatively small release. Read all about it in this blog post.
 
October 31st, 2011
Another release with lots of bug fixes and small improvements and with great contributions by Martin Opdam and Urs Enzler. Download ithere or get it throughNuGet.
 

About versioning

The version numbers of Fluent Assertions releases comply to the Semantic Versioning scheme. In other words, release 1.4.0 only adds backwards-compatible functionality and bug fixes compared to 1.3.0. Release 1.4.1 should only include bug fixes. And if we ever introduce breaking changes, the number increased to 2.0.0.

Who are we?

We are a bunch of developers working for Aviva Solutions who highly value software quality, in particular

If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.

clip_image002#fluentassertions

Updated Wiki: Home

$
0
0

Project Description

Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.

Why?

Nothing is more annoying then a unit test that fails without clearly explaining why. More than often, you need to set a breakpoint and start up the debugger to be able to figure out what went wrong. Jeremy D. Miller once gave the advice to "keep out of the debugger hell" and I can only agree with that.

For instance, only test a single condition per test case. If you don't, and the first condition fails, the test engine will not even try to test the other conditions. But if any of the others fail, you'll be on your own to figure out which one. I often run into this problem when developers try to combine multiple related tests that test a member using different parameters into one test case. If you really need to do that, consider using aparameterized test that is being called by several clearly named test cases.

That’s why we designed Fluent Assertions to help you in this area. Not only by using clearly named assertion methods, but also by making sure the failure message provides as much information as possible. Consider this example:

"1234567890".Should().Be("0987654321");

This will be reported as:

clip_image001[6]

The fact that both strings are displayed on a separate line is on purpose and happens if any of them is longer than 8 characters. However, if that's not enough, all assertion methods take an optional formatted reason with placeholders, similarly to String.Format, that you can use to enrich the failure message. For instance, the assertion

new[] { 1, 2, 3 }.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);

will fail with:

clip_image002[6]

Examples

To verify that a string begins, ends and contains a particular phrase.

string actual = "ABCDEFGHI";
actual.Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);

To verify that a collection contains a specified number of elements and that all elements match a predicate.


IEnumerable collection = new[] { 1, 2, 3 }; collection.Should().HaveCount(4, "because we thought we put three items in the collection"))
collection.Should().Contain(i => i > 0);
The nice thing about the second failing example is that it will throw an exception with the message

"Expected <4> items because we thought we put three items in the collection, but found <3>."

To verify that a particular business rule is enforced using exceptions.

var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For("Milk").WithQuantity(200, Unit.Milliliters))
   .Build();

Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);

action
   .ShouldThrow<RuleViolationException>()
   .WithMessage("change the unit of an existing ingredient", ComparisonMode.Substring)
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);

What’s new?

May 20th, 2013
@ 
 
March 3rd, 2013
We've released a small bugfix on Nuget and CodePlex.
October 7th, 2012
Version 2.0 is now out of beta.
August 25th, 2012
Fluent Assertions 2.0, a major new version with support for .NET 4.5, Windows Phone and Windows Store Apps is inbeta. Read all the details in this blog post.
  
January 13th, 2012
A relatively small release. Read all about it in this blog post.
 
October 31st, 2011
Another release with lots of bug fixes and small improvements and with great contributions by Martin Opdam and Urs Enzler. Download ithere or get it throughNuGet.
 

About versioning

The version numbers of Fluent Assertions releases comply to the Semantic Versioning scheme. In other words, release 1.4.0 only adds backwards-compatible functionality and bug fixes compared to 1.3.0. Release 1.4.1 should only include bug fixes. And if we ever introduce breaking changes, the number increased to 2.0.0.

Who are we?

We are a bunch of developers working for Aviva Solutions who highly value software quality, in particular

If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.

clip_image002#fluentassertions
Viewing all 1402 articles
Browse latest View live


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