Line data Source code
1 : using System;
2 : using cdmdotnet.Logging;
3 : using Cqrs.Domain;
4 : using Cqrs.Domain.Exceptions;
5 : using Cqrs.Domain.Factories;
6 : using Cqrs.Authentication;
7 : using Cqrs.Tests.Substitutes;
8 : using NUnit.Framework;
9 :
10 : namespace Cqrs.Tests.Domain
11 : {
12 : [TestFixture]
13 : public class When_saving_stale_data
14 0 : {
15 : private TestInMemoryEventStore _eventStore;
16 : private TestAggregate _aggregate;
17 : private TestEventPublisher _eventPublisher;
18 : private Repository<ISingleSignOnToken> _rep;
19 : private UnitOfWork<ISingleSignOnToken> _unitOfWork;
20 :
21 : [SetUp]
22 0 : public void Setup()
23 : {
24 : _eventStore = new TestInMemoryEventStore();
25 : _eventPublisher = new TestEventPublisher();
26 : var dependencyResolver = new TestDependencyResolver(null);
27 : var aggregateFactory = new AggregateFactory(dependencyResolver, dependencyResolver.Resolve<ILogger>());
28 : _rep = new Repository<ISingleSignOnToken>(aggregateFactory, _eventStore, _eventPublisher, new NullCorrelationIdHelper());
29 : _unitOfWork = new UnitOfWork<ISingleSignOnToken>(_rep);
30 :
31 : _aggregate = new TestAggregate(Guid.NewGuid());
32 : _aggregate.DoSomething();
33 : _rep.Save(_aggregate);
34 :
35 : }
36 :
37 : [Test]
38 0 : public void Should_throw_concurrency_exception_from_repository()
39 : {
40 : _aggregate.DoSomething();
41 : Assert.Throws<ConcurrencyException>(() => _rep.Save(_aggregate, 0));
42 : }
43 :
44 : [Test]
45 0 : public void Should_throw_concurrency_exception_from_session()
46 : {
47 : _unitOfWork.Add(_aggregate);
48 : _aggregate.DoSomething();
49 : _eventStore.Events.Add(new TestAggregateDidSomething { Id = _aggregate.Id, Version = 4 });
50 : Assert.Throws<ConcurrencyException>(() => _unitOfWork.Commit());
51 : }
52 : }
53 : }
|