Tutorial configuration tests for Windsor 3.0

35 views
Skip to first unread message

Daniel Lidström

unread,
Sep 6, 2011, 3:27:34 AM9/6/11
to castle-pro...@googlegroups.com
Hello,

I'm wondering how to change one of the tutorial configuration tests (see http://docs.castleproject.org/Windsor.Windsor-tutorial-part-three-a-testing-your-first-installer.ashx)
for Windsor 3.0. Here's the test for 2.5:

[Fact]
public void All_controllers_expose_themselves_as_service()
{
	var controllersWithWrongName = GetHandlersFor(typeof(IController), containerWithControllers)
		.Where(controller => controller.Service != controller.ComponentModel.Implementation)
		.ToArray();
 
	Assert.Empty(controllersWithWrongName);
}
With the Service property now on ComponentModel as Services, what would be the correct change?

Regards,

Daniel Lidström

Krzysztof Koźmic

unread,
Sep 6, 2011, 3:29:49 AM9/6/11
to castle-pro...@googlegroups.com
Well we can approach it twofold:

- assert that the controller class is one of the services exposed
- assert that the controller class is the only service exposed

I would actually make it the latter, mostly to keep things simple.

Krzysztof
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/Thq82umwEIwJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Daniel Lidström

unread,
Sep 6, 2011, 3:38:16 AM9/6/11
to castle-pro...@googlegroups.com
Ok, so I'm trying the second approach. Would this be correct?

[Fact]
public void AllControllersExposeThemselvesAsService()
{
	var controllersWithWrongName = InstallerTestHelper.GetHandlersFor(typeof(IController), container)
		.Where(c => c.ComponentModel.Services.Any(s => s != c.ComponentModel.Implementation))
		.ToArray();
	Assert.Empty(controllersWithWrongName);
}
/Daniel

Krzysztof Koźmic

unread,
Sep 6, 2011, 4:21:27 AM9/6/11
to castle-pro...@googlegroups.com
Looks good

Sent from my phone
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.

Daniel Lidström

unread,
Sep 6, 2011, 4:29:38 AM9/6/11
to castle-pro...@googlegroups.com
Great, thanks for a wonderful library. Keep up the good work!

Daniel Lidström

unread,
Nov 9, 2011, 5:18:18 AM11/9/11
to castle-pro...@googlegroups.com
On behalf of James Foster:

I came across the same issue with the tutorial (currently working
through it).

I don't think this is actually testing what it says it's testing.


>        var controllersWithWrongName = InstallerTestHelper.GetHandlersFor(typeof(IController), container)
>                .Where(c => c.ComponentModel.Services.Any(s => s != c.ComponentModel.Implementation))
>                .ToArray();
>        Assert.Empty(controllersWithWrongName);

all you're saying here is that the ComponentModel.Services doesn't
contain a type that isn't the Implementation.

you're NOT saying that the ComponentModel.Services actually contains
the Implementation. This test passes even if the Services list is
empty.

I think to be correct it would be something like the following...


       var controllersWithWrongName =
InstallerTestHelper.GetHandlersFor(typeof(IController), container)
               .Where(c => !
c.ComponentModel.Services.
SequenceEquals(new []
{c.ComponentModel.Implementation}))
               .ToArray();
       Assert.Empty(controllersWithWrongName);

in english: "where the ComponentModel.Services does not equal the list
containing only the Implementation"

Cheers

James

Reply all
Reply to author
Forward
0 new messages