Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using cdmdotnet.Logging;
4 : using cdmdotnet.Logging.Configuration;
5 : using Cqrs.Bus;
6 : using Cqrs.Configuration;
7 :
8 : namespace Cqrs.Tests.Substitutes
9 : {
10 : public class TestDependencyResolver : IDependencyResolver
11 0 : {
12 : protected TestEventStore TestEventStore { get; private set; }
13 :
14 : public bool UseTestEventStoreGuid { get; set; }
15 :
16 : public Guid? NewAggregateGuid { get; set; }
17 :
18 : public readonly List<dynamic> Handlers = new List<dynamic>();
19 :
20 0 : public TestDependencyResolver(TestEventStore testEventStore)
21 : {
22 : TestEventStore = testEventStore;
23 : }
24 :
25 0 : public T Resolve<T>()
26 : {
27 : return (T)Resolve(typeof(T));
28 : }
29 :
30 0 : public object Resolve(Type type)
31 : {
32 : if (type == typeof(IHandlerRegistrar) || type == typeof(IEventHandlerRegistrar) || type == typeof(ICommandHandlerRegistrar))
33 : return new TestHandleRegistrar();
34 : if (type == typeof(ILogger))
35 : return new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper());
36 : if (type == typeof (IConfigurationManager))
37 : return new ConfigurationManager();
38 : if (type == typeof(TestAggregate))
39 : return new TestAggregate(TestEventStore == null || !UseTestEventStoreGuid ? NewAggregateGuid ?? Guid.NewGuid() : TestEventStore.EmptyGuid);
40 : if (type == typeof(TestSnapshotAggregate))
41 : return new TestSnapshotAggregate(TestEventStore == null || !UseTestEventStoreGuid ? NewAggregateGuid ?? Guid.NewGuid() : TestEventStore.EmptyGuid);
42 : if (type == typeof(TestAggregateDidSomethingHandler))
43 : {
44 : var handler = new TestAggregateDidSomethingHandler();
45 : Handlers.Add(handler);
46 : return handler;
47 : }
48 : else
49 : {
50 : var handler = new TestAggregateDoSomethingHandler();
51 : Handlers.Add(handler);
52 : return handler;
53 : }
54 : }
55 : }
56 : }
|