Created Issue: Misleading AllDeclaredPublicPropertiesSelectionRule class [12486]
Created Unassigned: NullReferenceException caused by AttributeBasedFormatter on Mono 3.0.6 [12487]
(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"
New Post: Adding a method to measure how many times some text repeats within a string
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
Could you provide us with the suggested syntax?
New Post: Adding a method to measure how many times some text repeats within a string
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]
[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
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
New Comment on "Documentation"
New Post: Support for C# Dynamics
Created Unassigned: string.Should().NotBeNullOrWhitespace(); [12488]
Cheers
Created Unassigned: XElement.Should().Match() [12489]
Currently I use something like this:
``` C#
XElement.As<XNode>().Should().Match<XElement>(x => x.Name == "foo")
```
Commented Unassigned: XElement.Should().Match() [12489]
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
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
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"
Updated Wiki: Home
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:
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);
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.
The nice thing about the second failing example is that it will throw an exception with the message
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);
"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?
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?
If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.
#fluentassertions |
Updated Wiki: Home
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:
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);
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.
The nice thing about the second failing example is that it will throw an exception with the message
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);
"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?
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?
If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.
#fluentassertions |
Updated Wiki: Home
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:
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);
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.
The nice thing about the second failing example is that it will throw an exception with the message
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);
"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?
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?
If you have any comments or suggestions, please let us know via twitter, through thediscussions page, or throughStackOverflow.
#fluentassertions |