public async Task ThrowsDistributedLockExceptionIfExistingLockIsExpiredDuringAdd() { var distributedLock = A.Fake <IRedLock>(); A.CallTo(() => distributedLock.IsAcquired).Returns(true); A.CallTo(() => distributedLock.Resource).Returns(_aggregate.Id); A.CallTo(() => _distributedLockFactory.CreateLockAsync(_aggregate.Id, A <TimeSpan> ._, A <TimeSpan> ._, A <TimeSpan> ._, null)).Returns(distributedLock); await _session.GetAsync <TestAggregateNoParameterLessConstructor>(_aggregate.Id); try { A.CallTo(() => distributedLock.Status).Returns(RedLockStatus.Expired); await _session.AddAsync(_aggregate); Assert.Fail("Should have thrown DistributedLockException"); } catch (DistributedLockException e) { Assert.AreEqual($"Existing session lock expired for aggregate '{_aggregate.Id} after {_eventStoreSettings.ExpirySeconds} seconds.", e.Message); Assert.AreEqual(0, _eventStore.Events.Count); A.CallTo(() => distributedLock.Dispose()).MustHaveHappened(); } }
public async Task AddAsync <TAggregate>(TAggregate aggregate) where TAggregate : Aggregate { _logger.Log(LogLevel.Information, $"Called method: {nameof(Repository)}.{nameof(AddAsync)}."); await _session.AddAsync(aggregate).ConfigureAwait(false); }
public Task AddAsync <TAggregate>(TAggregate aggregate) where TAggregate : AggregateRoot => _session.AddAsync(aggregate);