Skip to content

Commit ea72848

Browse files
committed
Include ninject activation errors in test faulure messages
1 parent 11401ec commit ea72848

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/FluentAssertions.Ioc.Ninject/CollectionOfTypesKernelAssertions.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using FluentAssertions.Execution;
6+
using FluentAssertions.Formatting;
67
using FluentAssertions.Ioc.Ninject.Internal;
78
using Ninject;
89

@@ -66,14 +67,26 @@ public void WithAtLeastOneInstance()
6667
.FailWith(BuildFailureMessage(failed));
6768
}
6869

69-
private string BuildFailureMessage(List<ActivationError> failed)
70+
private string BuildFailureMessage(IEnumerable<ActivationError> failed)
7071
{
7172
// Build the failure message
7273
var builder = new StringBuilder();
74+
var exceptionBuilder = new StringBuilder();
7375
builder.AppendLine("The following types could not be resolved:").AppendLine();
74-
76+
7577
foreach (var error in failed)
78+
{
7679
builder.AppendFormat(" - {0}", error.Type.FullName).AppendLine();
80+
81+
if (error.Exception != null)
82+
{
83+
exceptionBuilder.AppendLine(Formatter.ToString(error.Exception));
84+
exceptionBuilder.AppendLine();
85+
}
86+
}
87+
88+
builder.AppendLine();
89+
builder.AppendLine(exceptionBuilder.ToString());
7790

7891
return builder.ToString();
7992
}

src/FluentAssertions.Ioc.Ninject/SingleTypeKernelAssertions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Text;
23
using FluentAssertions.Execution;
4+
using FluentAssertions.Formatting;
35
using FluentAssertions.Ioc.Ninject.Internal;
46
using Ninject;
57

@@ -55,7 +57,18 @@ public void To<T>()
5557

5658
private string BuildFailureMessage(ActivationError error)
5759
{
58-
return String.Format("Unable to resolve type {0}", error.Type.FullName);
60+
var builder = new StringBuilder();
61+
62+
builder.AppendFormat("Unable to resolve type {0}.", error.Type.FullName);
63+
64+
if (error.Exception != null)
65+
{
66+
builder.AppendLine();
67+
builder.AppendLine();
68+
builder.Append(Formatter.ToString(error.Exception));
69+
}
70+
71+
return builder.ToString();
5972
}
6073
}
6174
}

0 commit comments

Comments
 (0)