Line data Source code
1 : using System;
2 : using cdmdotnet.Logging;
3 : using Cqrs.Domain;
4 : using Cqrs.Domain.Factories;
5 : using Cqrs.Authentication;
6 : using Cqrs.Domain.Exceptions;
7 : using Cqrs.Tests.Substitutes;
8 : using NUnit.Framework;
9 :
10 : namespace Cqrs.Tests.Domain
11 : {
12 : [TestFixture]
13 : public class When_adding_aggregates_to_repository
14 0 : {
15 : private UnitOfWork<ISingleSignOnToken> _unitOfWork;
16 :
17 : [SetUp]
18 0 : public void SetUp()
19 : {
20 : var eventStore = new TestEventStore();
21 : var dependencyResolver = new TestDependencyResolver(eventStore);
22 : var aggregateFactory = new AggregateFactory(dependencyResolver, dependencyResolver.Resolve<ILogger>());
23 : var eventPublisher = new TestEventPublisher();
24 : _unitOfWork = new UnitOfWork<ISingleSignOnToken>(new Repository<ISingleSignOnToken>(aggregateFactory, eventStore, eventPublisher, new NullCorrelationIdHelper()));
25 : }
26 :
27 : [Test]
28 0 : public void Should_throw_if_different_object_with_tracked_guid_is_added()
29 : {
30 : var aggregate = new TestAggregate(Guid.NewGuid());
31 : var aggregate2 = new TestAggregate(aggregate.Id);
32 : _unitOfWork.Add(aggregate);
33 : Assert.Throws<ConcurrencyException>(() => _unitOfWork.Add(aggregate2));
34 : }
35 :
36 : [Test]
37 0 : public void Should_not_throw_if_object_already_tracked()
38 : {
39 : var aggregate = new TestAggregate(Guid.NewGuid());
40 : _unitOfWork.Add(aggregate);
41 : _unitOfWork.Add(aggregate);
42 : }
43 : }
44 : }
|