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

Edited Issue: System.IO.FileLoadException in AttributeBasedFormatter.AllTypes [12476]

$
0
0
I don't know how to reproduce this in simple project, but I am getting this exception on a test project that uses StackExchange's MiniProfiler


```
Test(s) failed. System.IO.FileLoadException : Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at FluentAssertions.Formatting.AttributeBasedFormatter.get_AllTypes() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 119
at FluentAssertions.Formatting.AttributeBasedFormatter.FindCustomFormatters() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 63
at FluentAssertions.Formatting.AttributeBasedFormatter.get_Formatters() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 58
at FluentAssertions.Formatting.AttributeBasedFormatter.GetFormatter(Object value) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 0
at FluentAssertions.Formatting.AttributeBasedFormatter.CanHandle(Object value) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 27
at FluentAssertions.Formatting.Formatter.<>c__DisplayClass1.<ToString>b__0(IValueFormatter f) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\Formatter.cs:line 54
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at FluentAssertions.Formatting.Formatter.ToString(Object value, Boolean useLineBreaks, IList`1 processedObjects, Int32 nestedPropertyLevel) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\Formatter.cs:line 54
at FluentAssertions.Execution.Verification.<BuildExceptionMessage>b__3(Object a) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 217
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at FluentAssertions.Execution.Verification.BuildExceptionMessage(String failureMessage, Object[] failureArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 217
at FluentAssertions.Execution.Verification.FailWith(String failureMessage, Object[] failureArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 158
at FluentAssertions.Numeric.NumericAssertions`1.Be(T expected, String reason, Object[] reasonArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Numeric\NumericAssertions.cs:line 44
```

IMHO, it would be Ok to handle FileLoadException the same way other exceptions are handled in GetExportedTypes.

Thanks.


Commented Issue: System.IO.FileLoadException in AttributeBasedFormatter.AllTypes [12476]

$
0
0
I don't know how to reproduce this in simple project, but I am getting this exception on a test project that uses StackExchange's MiniProfiler


```
Test(s) failed. System.IO.FileLoadException : Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at FluentAssertions.Formatting.AttributeBasedFormatter.get_AllTypes() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 119
at FluentAssertions.Formatting.AttributeBasedFormatter.FindCustomFormatters() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 63
at FluentAssertions.Formatting.AttributeBasedFormatter.get_Formatters() in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 58
at FluentAssertions.Formatting.AttributeBasedFormatter.GetFormatter(Object value) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 0
at FluentAssertions.Formatting.AttributeBasedFormatter.CanHandle(Object value) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 27
at FluentAssertions.Formatting.Formatter.<>c__DisplayClass1.<ToString>b__0(IValueFormatter f) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\Formatter.cs:line 54
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at FluentAssertions.Formatting.Formatter.ToString(Object value, Boolean useLineBreaks, IList`1 processedObjects, Int32 nestedPropertyLevel) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\Formatter.cs:line 54
at FluentAssertions.Execution.Verification.<BuildExceptionMessage>b__3(Object a) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 217
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at FluentAssertions.Execution.Verification.BuildExceptionMessage(String failureMessage, Object[] failureArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 217
at FluentAssertions.Execution.Verification.FailWith(String failureMessage, Object[] failureArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Execution\Verification.cs:line 158
at FluentAssertions.Numeric.NumericAssertions`1.Be(T expected, String reason, Object[] reasonArgs) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Numeric\NumericAssertions.cs:line 44
```

IMHO, it would be Ok to handle FileLoadException the same way other exceptions are handled in GetExportedTypes.

Thanks.

Comments: Hi, Thanks for taking the time to report this issue. Fortunately it is already fixed in the upcoming 2.1 release. We've just started the work on 2.1, so it might take a while before we deliver that one. Is it an option for you to take the latest sources and build your own version? Dennis

New Post: Why so many negation methods?

$
0
0

I'm really curious about this too. What would it take to implement it.Should().Not().BeWhatever()?

New Post: Generating documentation from fluent assertions

$
0
0

I'm interested in a way to generate test documentation from assertions to build a report.

public class FooSpec() {
   public void WhenInitialized() {
      var foo = new Foo();
      Foo.Bar.Should().NotBeNull();
      Foo.Baz.Should().BeNull();
    }
}

This could yield pretty nice documentation and reports.

FooSpec:
When Initialized:
Foo Bar should not be null - passed
Foo Baz should be null - failed

Is there a way to get this as meta data and feed it to a formatter which can output? I'm new here but I'd love to implement it.

New Post: Why so many negation methods?

$
0
0

I remember that at the time we started this project, there were similar libraries that did support that, but also that we felt they were a bit too noisy. In retrospect, it might have been a good solution after all, although it wouldn't have saved us any work. We still need to generate a specific message for the negated assertions.

Adding it right now could still be possible, but that alle depends on how many folks vote for that feature. We cannot simply remove the old NotXXX methods since that would be a breaking chance.

New Post: Generating documentation from fluent assertions

$
0
0

That would require parsing IL code, so that should be pretty difficult. We're just using C#'s support for extension methods, so there's nothing to extract metadata from.

Edited Issue: PropertyAssertion does not throw if a class overwrites Equals(object obj) [12475]

$
0
0
PropertyAssertions do not work properly if a class overwrites the Equals-method:

```
class ClassThatOverwritesEquals
{
public int Age { get; set; }

public override bool Equals(object obj) {
return true;
}
}
```

This will never throw if you compare two instances of the same type:

```
var subject = new ClassThatOverwritesEquals {
Age = 36,
};

var expectation = new ClassThatOverwritesEquals {
Age = 37,
};

Action act = () => subject
.ShouldHave()
.AllProperties()
.EqualTo(expectation, "because {0} are the same", "they");
```

I would guess the problem is in ReferenceEqualityEquivalencyStep.cs line 43:

```
return !ReferenceEquals(context.Subject, null) && context.Subject.Equals(context.Expectation);
```

The Equals(..) should be replaced by object.ReferenceEquals(..).


Commented Issue: PropertyAssertion does not throw if a class overwrites Equals(object obj) [12475]

$
0
0
PropertyAssertions do not work properly if a class overwrites the Equals-method:

```
class ClassThatOverwritesEquals
{
public int Age { get; set; }

public override bool Equals(object obj) {
return true;
}
}
```

This will never throw if you compare two instances of the same type:

```
var subject = new ClassThatOverwritesEquals {
Age = 36,
};

var expectation = new ClassThatOverwritesEquals {
Age = 37,
};

Action act = () => subject
.ShouldHave()
.AllProperties()
.EqualTo(expectation, "because {0} are the same", "they");
```

I would guess the problem is in ReferenceEqualityEquivalencyStep.cs line 43:

```
return !ReferenceEquals(context.Subject, null) && context.Subject.Equals(context.Expectation);
```

The Equals(..) should be replaced by object.ReferenceEquals(..).


Comments: Fixed with commit http://fluentassertions.codeplex.com/SourceControl/changeset/1644f7a0afff

Created Issue: Add BeApproximately to decimal [12477]

$
0
0
When asserting on floats and doubles you should use the BeApproximately assertion, the same is the case for decimals, but here BeApproximately aren't allowed, and you are forced to use BeInRange assertion instead.

Commented Issue: Add BeApproximately to decimal [12477]

$
0
0
When asserting on floats and doubles you should use the BeApproximately assertion, the same is the case for decimals, but here BeApproximately aren't allowed, and you are forced to use BeInRange assertion instead.
Comments: I've always thought that decimals didn't suffer from the same inaccuracy as floats and doubles do. But after reading [this StackOverflow](http://stackoverflow.com/questions/618535/what-is-the-difference-between-decimal-float-and-double-in-c) discussion, I must admit you're right. I'll need to add the BeApproximately after all.

Created Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```

Commented Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```
Comments: A bit more stack trace maybe helpful: ``` mscorlib.dll!System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes() + 0x39 bytes FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(System.Reflection.Assembly assembly) Line 126 + 0xb bytes C# System.Core.dll!System.Linq.Enumerable.SelectManyIterator<System.Reflection.Assembly,System.Type>.MoveNext() + 0xeb bytes System.Core.dll!System.Linq.Buffer<System.Type>.Buffer(System.Collections.Generic.IEnumerable<System.Type> source) + 0x150 bytes System.Core.dll!System.Linq.Enumerable.ToArray<System.Type>(System.Collections.Generic.IEnumerable<System.Type> source) + 0x4e bytes FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.AllTypes.get() Line 119 + 0x58 bytes C# FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.FindCustomFormatters() Line 63 + 0x6 bytes C# FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.Formatters.get() Line 58 + 0x24 bytes C# FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.GetFormatter(object value) Line 53 + 0x9 bytes C# FluentAssertions.dll!FluentAssertions.Formatting.AttributeBasedFormatter.CanHandle(object value) Line 27 + 0x12 bytes C# FluentAssertions.dll!FluentAssertions.Formatting.Formatter.ToString.AnonymousMethod__0(FluentAssertions.Formatting.IValueFormatter f) Line 54 + 0xf bytes C# System.Core.dll!System.Linq.Enumerable.First<FluentAssertions.Formatting.IValueFormatter>(System.Collections.Generic.IEnumerable<FluentAssertions.Formatting.IValueFormatter> source, System.Func<FluentAssertions.Formatting.IValueFormatter,bool> predicate) + 0x8f bytes FluentAssertions.dll!FluentAssertions.Formatting.Formatter.ToString(object value, bool useLineBreaks, System.Collections.Generic.IList<object> processedObjects, int nestedPropertyLevel) Line 54 + 0x36 bytes C# FluentAssertions.dll!FluentAssertions.Execution.Verification.BuildExceptionMessage.AnonymousMethod__3(object a) Line 217 + 0x1a bytes C# System.Core.dll!System.Linq.Enumerable.WhereSelectArrayIterator<System.__Canon,System.__Canon>.MoveNext() + 0x43 bytes mscorlib.dll!System.Collections.Generic.List<string>.InsertRange(int index, System.Collections.Generic.IEnumerable<string> collection) + 0x189 bytes mscorlib.dll!System.Collections.Generic.List<System.__Canon>.AddRange(System.Collections.Generic.IEnumerable<System.__Canon> collection) + 0xb bytes FluentAssertions.dll!FluentAssertions.Execution.Verification.BuildExceptionMessage(string failureMessage, object[] failureArgs) Line 219 C# FluentAssertions.dll!FluentAssertions.Execution.Verification.FailWith(string failureMessage, object[] failureArgs) Line 158 + 0xf bytes C# FluentAssertions.dll!FluentAssertions.Numeric.ComparableTypeAssertions<ushort>.Be(ushort expected, string reason, object[] reasonArgs) Line 45 C# > BlueLabelMexicoService.Test.dll!BlueLabelMexicoService.Test.BlueLabelMexicoHandlerTest.ProcessCashCollection_ExpectSuccess.AnonymousMethod__1(Bps.Hermes.EtuProtocol.EtuApolloRsp etuResponse) Line 133 + 0x6d bytes C# ... ```

Commented Issue: Issue with normal Should Be call [12478]

$
0
0
Hi

I receive an exception when i make a call like this:

```
etuResponse.Header.RspCode.Should().Be(0);

```

Thats all. I am doing nothing else.
RspCode has the value 234.
I am using MSTest, Visual Studio 2012, .Net 4.5
FluentAssertion Version: 2.0.0.0

```
System.NotSupportedException occurred
HResult=-2146233067
Message=The invoked member is not supported in a dynamic assembly.
Source=mscorlib
StackTrace:
at System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
at FluentAssertions.Formatting.AttributeBasedFormatter.GetExportedTypes(Assembly assembly) in c:\Workspaces\codeplex\fluentassertions\Main\FluentAssertions.Net35\Formatting\AttributeBasedFormatter.cs:line 126
InnerException:
```
Comments: I think I know what's going on. The AttributeBasedFormatter is trying to dynamically find methods that are annotated with [ValueFormatter], but apparently it is trying to scan a dynamic assembly. I need to add the NotSupportedException to exceptions to intercept.

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: Further to the fix suggested by RolfWessels above, if you are using the new VS2012 unit test framework for WP8, then the fix should be as follows: ``` internal class WindowsPhoneTestFramework : LateBoundTestFramework { protected override string AssemblyName { get { return "Microsoft.VisualStudio.TestPlatform.UnitTestFramework"; } } protected override string ExceptionFullName { get { return "Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException"; } } } ```

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: What new unit test framework?

Edited Issue: Add BeApproximately to decimal [12477]

$
0
0
When asserting on floats and doubles you should use the BeApproximately assertion, the same is the case for decimals, but here BeApproximately aren't allowed, and you are forced to use BeInRange assertion instead.

Edited Issue: Add BeApproximately to decimal [12477]

$
0
0
When asserting on floats and doubles you should use the BeApproximately assertion, the same is the case for decimals, but here BeApproximately aren't allowed, and you are forced to use BeInRange assertion instead.

Created Issue: False positive with Should().BeApproximatively and float.NaN value [12479]

$
0
0
Hi,

The method BeApproximatively does not fail if the actual value is float.NaN.
Here is the test :
```
[Fact]
public void Test_ShouldFail()
{
var actual = float.NaN;
var expected = 5f;
actual.Should().BeApproximately(expected, 0.01f);
}
```

Note that the test fails as expected with a double.

Commented Issue: False positive with Should().BeApproximatively and float.NaN value [12479]

$
0
0
Hi,

The method BeApproximatively does not fail if the actual value is float.NaN.
Here is the test :
```
[Fact]
public void Test_ShouldFail()
{
var actual = float.NaN;
var expected = 5f;
actual.Should().BeApproximately(expected, 0.01f);
}
```

Note that the test fails as expected with a double.
Comments: We will fix this for 2.1. Is it blocking your work?

Edited Issue: False positive with Should().BeApproximatively and float.NaN value [12479]

$
0
0
Hi,

The method BeApproximatively does not fail if the actual value is float.NaN.
Here is the test :
```
[Fact]
public void Test_ShouldFail()
{
var actual = float.NaN;
var expected = 5f;
actual.Should().BeApproximately(expected, 0.01f);
}
```

Note that the test fails as expected with a double.
Viewing all 1402 articles
Browse latest View live


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