public async Task ArchiveGroup_skips_over_empty_batches_but_still_completes()
        {
            // Arrange
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var groupId = "TestGroup";
                var previousArchiveBatchId = ArchiveBatch.MakeId(groupId, ArchiveType.FailureGroup, 1);

                using (var session = documentStore.OpenAsyncSession())
                {
                    var previousArchiveBatch = new ArchiveBatch {
                        Id = previousArchiveBatchId
                    };
                    await session.StoreAsync(previousArchiveBatch)
                    .ConfigureAwait(false);

                    var previousArchiveOperation = new ArchiveOperation
                    {
                        Id                       = ArchiveOperation.MakeId(groupId, ArchiveType.FailureGroup),
                        RequestId                = groupId,
                        ArchiveType              = ArchiveType.FailureGroup,
                        TotalNumberOfMessages    = 2,
                        NumberOfMessagesArchived = 0,
                        Started                  = DateTime.Now,
                        GroupName                = "Test Group",
                        NumberOfBatches          = 3,
                        CurrentBatch             = 0
                    };
                    await session.StoreAsync(previousArchiveOperation)
                    .ConfigureAwait(false);

                    await session.SaveChangesAsync()
                    .ConfigureAwait(false);
                }

                var domainEvents = new DomainEvents();
                var handler      = new ArchiveAllInGroupHandler(documentStore,
                                                                new FakeDomainEvents(),
                                                                new ArchiveDocumentManager(),
                                                                new ArchivingManager(domainEvents),
                                                                new RetryingManager(domainEvents));

                var context = new TestableMessageHandlerContext();
                var message = new ArchiveAllInGroup {
                    GroupId = groupId
                };

                // Act
                await handler.Handle(message, context)
                .ConfigureAwait(false);

                // Assert
                using (var session = documentStore.OpenSession())
                {
                    var loadedBatch = session.Load <ArchiveBatch>(previousArchiveBatchId);
                    Assert.IsNull(loadedBatch);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MfcArchive"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="archiveOperation">The archive operation.</param>
 public MfcArchive(Stream stream, ArchiveOperation archiveOperation)
     : base(stream, archiveOperation)
 {
     if (archiveOperation == ArchiveOperation.Store)
     {
         throw new NotImplementedException("Writing to MFC compatible serialization is not supported.");
     }
 }
示例#3
0
        public void ArchiveGroup_skips_over_empty_batches_but_still_completes()
        {
            // Arrange
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var groupId = "TestGroup";
                var previousArchiveBatchId = ArchiveBatch.MakeId(groupId, ArchiveType.FailureGroup, 1);

                using (var session = documentStore.OpenSession())
                {
                    var previousAchiveBatch = new ArchiveBatch {
                        Id = previousArchiveBatchId
                    };
                    session.Store(previousAchiveBatch);

                    var previousArchiveOperation = new ArchiveOperation
                    {
                        Id                       = ArchiveOperation.MakeId(groupId, ArchiveType.FailureGroup),
                        RequestId                = groupId,
                        ArchiveType              = ArchiveType.FailureGroup,
                        TotalNumberOfMessages    = 2,
                        NumberOfMessagesArchived = 0,
                        Started                  = DateTime.Now,
                        GroupName                = "Test Group",
                        NumberOfBatches          = 3,
                        CurrentBatch             = 0
                    };
                    session.Store(previousArchiveOperation);

                    session.SaveChanges();
                }

                var documentManager  = new ArchiveDocumentManager();
                var domainEvents     = new FakeDomainEvents();
                var archivingManager = new ArchivingManager(domainEvents);
                var retryingManager  = new RetryingManager(domainEvents);
                var handler          = new ArchiveAllInGroupHandler(documentStore, domainEvents, documentManager, archivingManager, retryingManager);

                var message = new ArchiveAllInGroup {
                    GroupId = groupId
                };

                // Act
                handler.Handle(message);

                // Assert
                using (var session = documentStore.OpenSession())
                {
                    var loadedBatch = session.Load <ArchiveBatch>(previousArchiveBatchId);
                    Assert.IsNull(loadedBatch);
                }
            }
        }
示例#4
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Archive"/> class.
    /// </summary>
    /// <param name="stream">The stream.</param>
    /// <param name="archiveOperation">The archive operator.</param>
    public Archive(Stream stream, ArchiveOperation archiveOperation)
    {
        this.archiveOperation = archiveOperation;

        if (archiveOperation == ArchiveOperation.Load)
        {
            this.Reader = new BinaryReader(stream);
        }
        else
        {
            this.writer = new BinaryWriter(stream);
        }
    }
        public async Task ArchiveGroup_GetGroupDetails_doesnt_fail_with_invalid_groupId()
        {
            // Arrange
            using (var documentStore = InMemoryStoreBuilder.GetInMemoryStore())
            {
                var failureGroupsViewIndex = new FailureGroupsViewIndex();
                await failureGroupsViewIndex.ExecuteAsync(documentStore);

                var groupId = "TestGroup";
                var previousArchiveBatchId = ArchiveBatch.MakeId(groupId, ArchiveType.FailureGroup, 1);

                using (var session = documentStore.OpenAsyncSession())
                {
                    var previousArchiveBatch = new ArchiveBatch {
                        Id = previousArchiveBatchId
                    };
                    await session.StoreAsync(previousArchiveBatch)
                    .ConfigureAwait(false);

                    var previousArchiveOperation = new ArchiveOperation
                    {
                        Id                       = ArchiveOperation.MakeId(groupId, ArchiveType.FailureGroup),
                        RequestId                = groupId,
                        ArchiveType              = ArchiveType.FailureGroup,
                        TotalNumberOfMessages    = 2,
                        NumberOfMessagesArchived = 0,
                        Started                  = DateTime.Now,
                        GroupName                = "Test Group",
                        NumberOfBatches          = 3,
                        CurrentBatch             = 0
                    };
                    await session.StoreAsync(previousArchiveOperation)
                    .ConfigureAwait(false);

                    await session.SaveChangesAsync()
                    .ConfigureAwait(false);
                }

                var domainEvents = new DomainEvents();
                var handler      = new ArchiveAllInGroupHandler(documentStore,
                                                                new FakeDomainEvents(),
                                                                new ArchiveDocumentManager(),
                                                                new ArchivingManager(domainEvents),
                                                                new RetryingManager(domainEvents));

                var context = new TestableMessageHandlerContext();
                var message = new ArchiveAllInGroup {
                    GroupId = groupId + "Invalid"
                };

                // Act


                // Assert
                Assert.DoesNotThrowAsync(async() =>
                {
                    // Act
                    await handler.Handle(message, context).ConfigureAwait(false);
                });
            }
        }