/// <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)); }
/// <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)); }
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)); }
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)); }
/// <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); }
public bool TryGet(Guid id, out Aggregate aggregate) { return _aggregates.TryGetValue(id, out aggregate); }
public void Attach(Aggregate aggregate) { if (aggregate == null) throw new ArgumentNullException("aggregate"); _aggregates.Add(aggregate.Id, aggregate); }
/// <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; }
/// <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)); }