/// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 /// <param name="instance">The aggregate instance to copy data from.</param>
 internal AggregateBuilder(Aggregate instance)
 {
     _identifier = instance.Identifier;
     _expectedVersion = instance.ExpectedVersion;
     _root = instance.Root;
     _partition = instance.Partition;
 }
 /// <summary>
 /// Attaches the specified aggregate.
 /// </summary>
 /// <param name="aggregate">The aggregate.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="aggregate"/> is null.</exception>
 public void Attach(Aggregate aggregate)
 {
     if (aggregate == null)
         throw new ArgumentNullException("aggregate");
     if (!_aggregates.TryAdd(aggregate.Identifier, aggregate))
         throw new ArgumentException(
             string.Format(CultureInfo.InvariantCulture,
                 Resources.ConcurrentUnitOfWork_AttachAlreadyAdded,
                 aggregate.Root.GetType().Name, aggregate.Identifier));
 }
Пример #3
0
 /// <summary>
 /// Attaches the specified aggregate.
 /// </summary>
 /// <param name="aggregate">The aggregate.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="aggregate"/> is null.</exception>
 public void Attach(Aggregate aggregate)
 {
     if (aggregate == null)
         throw new ArgumentNullException("aggregate");
     if (!_aggregates.TryAdd(aggregate.Identifier, aggregate))
         throw new ArgumentException(
             string.Format(
                 "The aggregate of type '{0}' with identifier '{1}' was already added. This could indicate there's a race condition, i.e. the same aggregate getting attached multiple times.",
                 aggregate.Root.GetType().Name, aggregate.Identifier));
 }
Пример #4
0
        public void UsingConstructorWithPartitionReturnsInstanceWithExpectedProperties(
            [ValueSource(typeof (AggregateTestsValueSource), "IdSource")] string identifier,
            [Values(Int32.MinValue, -1, 0, 1, Int32.MaxValue)] int version)
        {
            var root = new AggregateRootEntityStub();
            var sut = new Aggregate(identifier, version, root);

            Assert.That(sut.Identifier, Is.EqualTo(identifier));
            Assert.That(sut.ExpectedVersion, Is.EqualTo(version));
            Assert.That(sut.Root, Is.SameAs(root));
        }
Пример #5
0
        public void ToBuilderReturnsExpectedResult()
        {
            const string identifier = "identifier";
            const int expectedVersion = 123;
            var root = new AggregateRootEntityStub();
            var sut = new Aggregate(identifier, expectedVersion, root);

            var result = sut.ToBuilder();

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Identifier, Is.EqualTo(identifier));
            Assert.That(result.ExpectedVersion, Is.EqualTo(expectedVersion));
            Assert.That(result.Root, Is.SameAs(root));
        }
Пример #6
0
 /// <summary>
 /// Attempts to get the <see cref="Aggregate"/> using the specified aggregate identifier.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="aggregate">The aggregate if found, otherwise <c>null</c>.</param>
 /// <returns><c>true</c> if the aggregate was found, otherwise <c>false</c>.</returns>
 public bool TryGet(string identifier, out Aggregate aggregate)
 {
     return _aggregates.TryGetValue(identifier, out aggregate);
 }
Пример #7
0
 public bool TryGet(Guid id, out Aggregate aggregate)
 {
     return _aggregates.TryGetValue(id, out aggregate);
 }
Пример #8
0
 public void Attach(Aggregate aggregate)
 {
     if (aggregate == null) throw new ArgumentNullException("aggregate");
       _aggregates.Add(aggregate.Id, aggregate);
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 /// <param name="instance">The aggregate instance to copy data from.</param>
 internal AggregateBuilder(Aggregate instance)
 {
     _identifier      = instance.Identifier;
     _expectedVersion = instance.ExpectedVersion;
     _root            = instance.Root;
 }
Пример #10
0
 /// <summary>
 /// Attempts to get the <see cref="Aggregate"/> using the specified aggregate identifier.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="aggregate">The aggregate if found, otherwise <c>null</c>.</param>
 /// <returns><c>true</c> if the aggregate was found, otherwise <c>false</c>.</returns>
 public bool TryGet(string identifier, out Aggregate aggregate)
 {
     return(_aggregates.TryGetValue(identifier, out aggregate));
 }