I'd suggest it's a code smell to be using your IOC container in your test
environment. You can test parts in isolation by instantiating them
individually and mocking out their dependencies.




On 15 April 2013 09:05, David Rhys Jones <djones...@gmail.com> wrote:

> I'm trying to mock one of the classes, but I also have tests that use the
> concrete class.
>
> I could test the whole thing together but that defeats the point of unit
> testing.
>
> I don't like the "automagically" part, is there some way I can tell it to
> give me the class in the configuration I want?
>  Davy,
>
> The US Congress voted Pizza sauce a vegetable. Don't even try to convince
> me of anything in the states is sane any more!
>
>
> On Sat, Apr 13, 2013 at 3:11 AM, Stephen Price 
> <step...@perthprojects.com>wrote:
>
>> Where are you using the container to get your registered interfaces?
>> Inside or outside the using block?
>>
>> The property will automatically be populated when you ask unity for an
>> ITransactionService. Its been a while since I used unity, but with ninject
>> you have to add a [Inject] attribute on the property. There might be
>> something similar for unity... Constructor dependencies are created
>> automagically
>>
>>
>> On Apr 13, 2013 12:21 AM, "David Rhys Jones" <djones...@gmail.com> wrote:
>> >
>> > I'm having a huge problem trying to get unity to work, I've spent a
>> whole day fighting it and can't get anywhere. I've used Spring.Net for a
>> long time and have no problems.
>> >
>> > This is my class.
>> >
>> > public class TransactionService : ITransactionService
>> >
>> > {
>> >
>> > [
>> >
>> > Dependency]
>> >
>> > public ITransactionData TransactionData { get; set; }
>> >
>> > }
>> >
>> > And this is my Setup.
>> >
>> > using (var u = new UnityContainer())
>> >
>> > {
>> >
>> > u.RegisterType<IConnection, Connection>()
>> >
>> > .Configure<InjectedMembers>()
>> >
>> > .ConfigureInjectionFor<Connection>(new
>> InjectionProperty("ConnectionString",
>> "Server=waihopar11-0125;Database=Spirit;Trusted_Connection=True;"));
>> >
>> > u.RegisterType<ITransactionService, TransactionService>()
>> >
>> > u.RegisterType<ITransactionData, MockTransactionData>("mock");
>> >
>> > .Configure<
>> >
>> > InjectedMembers>()
>> >
>> > // This bit I don't know how to do. how do I set
>> the "Mock" TransactionData on the  TransactionService.
>> >
>> > // I Can't find any examples that work with Unity 2.0..
>> >
>> > .ConfigureInjectionFor<TransactionService>(new
>> InjectionProperty("TransactionData", ?????? );
>> >
>> >  Help!
>> >
>> > thanks.
>> >
>> > Davy,
>> >
>> > The US Congress voted Pizza sauce a vegetable. Don't even try to
>> convince me of anything in the states is sane any more!
>>
>
>

Reply via email to