Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using System.Reflection;
4 : using Cqrs.Domain;
5 : using Cqrs.Events;
6 : using Cqrs.Authentication;
7 :
8 : namespace Cqrs.Tests.Substitutes
9 : {
10 : public class TestRepository : IRepository<ISingleSignOnToken>
11 0 : {
12 0 : public void Save<TAggregateRoot>(TAggregateRoot aggregate, int? expectedVersion = null)
13 : where TAggregateRoot : IAggregateRoot<ISingleSignOnToken>
14 : {
15 : Saved = aggregate;
16 : if (expectedVersion == 100)
17 : {
18 : throw new Exception();
19 : }
20 : }
21 :
22 : public IAggregateRoot<ISingleSignOnToken> Saved { get; private set; }
23 :
24 0 : public TAggregateRoot Get<TAggregateRoot>(Guid aggregateId, IList<IEvent<ISingleSignOnToken>> events = null)
25 : where TAggregateRoot : IAggregateRoot<ISingleSignOnToken>
26 : {
27 : var obj = (TAggregateRoot)Activator.CreateInstance(typeof(TAggregateRoot), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, new object[] { aggregateId }, null);
28 : obj.LoadFromHistory(new[] { new TestAggregateDidSomething { Id = aggregateId, Version = 2 } });
29 : return obj;
30 : }
31 : }
32 : }
|