예제 #1
0
        public async Task If_Package_not_valid_Sync_process_is_set_to_failed()
        {
            // Arrange
            var ar = new ArchiveRecord {
                ArchiveRecordId = "344"
            };
            var mutationId   = 999;
            var errMsg       = "Some other error message";
            var appendResult = new RepositoryPackageInfoResult {
                Valid = false, Success = true, ErrorMessage = errMsg
            };

            repositoryManager.Setup(e => e.ReadPackageMetadata(It.IsAny <string>(), It.IsAny <string>())).Returns(appendResult);

            // Act
            await InputQueueSendEndpoint.Send <IArchiveRecordAppendPackageMetadata>(new
            {
                ArchiveRecord = ar,
                MutationId    = mutationId
            });

            // Wait for the results
            await readPackageMetadataTask;
            var   context = await archiveRecordUpdatedTask;

            // Assert
            context.Message.ActionSuccessful.Should().Be(false);
            context.Message.MutationId.Should().Be(mutationId);
            context.Message.ErrorMessage.Should().Be(errMsg);
        }
예제 #2
0
        public async Task If_Package_is_valid_the_package_is_scheduled_for_sync()
        {
            // Arrange
            var ar = new ArchiveRecord {
                ArchiveRecordId = "478"
            };
            var mutationId   = 777;
            var errMsg       = string.Empty;
            var appendResult = new RepositoryPackageInfoResult
            {
                Valid = true, Success = true, ErrorMessage = errMsg, PackageDetails = new RepositoryPackage {
                    ArchiveRecordId = ar.ArchiveRecordId
                }
            };

            repositoryManager.Setup(e => e.ReadPackageMetadata(It.IsAny <string>(), It.IsAny <string>())).Returns(appendResult);

            // Act
            await InputQueueSendEndpoint.Send <IArchiveRecordAppendPackageMetadata>(new
            {
                ArchiveRecord = ar,
                MutationId    = mutationId
            });

            // Wait for the results
            await readPackageMetadataTask;
            var   context = await scheduleForPackageSyncTask;

            // Assert
            context.Message.Workload.ArchiveRecord.ArchiveRecordId.Should().Be(ar.ArchiveRecordId);
            context.Message.Workload.MutationId.Should().Be(mutationId);
        }
예제 #3
0
        public async Task If_Package_not_valid_Sync_process_is_set_to_failed()
        {
            // Arrange
            var harness = new InMemoryTestHarness();

            try
            {
                var ar = new ArchiveRecord {
                    ArchiveRecordId = "344"
                };
                var mutationId   = 999;
                var errMsg       = "Some other error message";
                var appendResult = new RepositoryPackageInfoResult {
                    Valid = false, Success = true, ErrorMessage = errMsg
                };
                repositoryManager.Setup(e => e.ReadPackageMetadata(It.IsAny <string>(), It.IsAny <string>())).Returns(appendResult);

                var readMetadataConsumer = harness.Consumer(() => readPackageMetadataConsumer.Object);
                harness.Consumer(() => new ReadPackageMetadataConsumer(repositoryManager.Object));
                harness.Consumer(() => readPackageMetadataConsumer.Object);

                await harness.Start();

                // Act
                await harness.InputQueueSendEndpoint.Send <IArchiveRecordAppendPackageMetadata>(new
                {
                    ArchiveRecord = ar,
                    MutationId    = mutationId
                });


                // Assert
                // did the endpoint consume the message
                Assert.That(await harness.Consumed.Any <IArchiveRecordAppendPackageMetadata>());

                // did the actual consumer consume the message
                Assert.That(await readMetadataConsumer.Consumed.Any <IArchiveRecordAppendPackageMetadata>());

                // the consumer publish the event
                Assert.That(await harness.Published.Any <IArchiveRecordUpdated>());

                // ensure that no faults were published by the consumer
                Assert.That(await harness.Published.Any <Fault <IArchiveRecordUpdated> >(), Is.False);

                // did the actual consumer consume the message
                var message = harness.Published.Select <IArchiveRecordUpdated>().First().Context.Message;

                // Assert
                message.ActionSuccessful.Should().Be(false);
                message.MutationId.Should().Be(mutationId);
                message.ErrorMessage.Should().Be(errMsg);
            }
            finally
            {
                await harness.Stop();
            }
        }
        public RepositoryPackageInfoResult ReadPackageMetadata(string packageId, string archiveRecordId)
        {
            // Init the return value
            var retVal = new RepositoryPackageInfoResult
            {
                Success        = false,
                Valid          = false,
                PackageDetails = new RepositoryPackage {
                    ArchiveRecordId = archiveRecordId
                }
            };

            try
            {
                var allIgnoredFiles = new List <RepositoryFile>();
                var rootFolder      = repositoryDataAccess.GetRepositoryRoot(packageId);
                if (rootFolder != null)
                {
                    // Get the metadata about the packages
                    retVal.PackageDetails.PackageId = packageId;
                    retVal.PackageDetails.Folders   = repositoryDataAccess.GetFolders(rootFolder.Id);
                    retVal.PackageDetails.Files     = repositoryDataAccess.GetFiles(rootFolder.Id, ignoredFilenameRegex, out var ignored);
                    allIgnoredFiles.AddRange(ignored);

                    // Get the sub folders of the root folders
                    foreach (var folder in retVal.PackageDetails.Folders)
                    {
                        GetFolderContent(folder, allIgnoredFiles);
                    }

                    if (allIgnoredFiles.Count > 0)
                    {
                        Log.Information("We have found {fileCount} files to ignore. These are: {files}", allIgnoredFiles.Count,
                                        JsonConvert.SerializeObject(allIgnoredFiles));
                    }

                    // additional data
                    retVal.PackageDetails.SizeInBytes = GetSizeInBytesFromMetadata(retVal.PackageDetails, false);
                    retVal.PackageDetails.FileCount   =
                        GetFileCountFromMetadata(retVal.PackageDetails, false); // Get all files according to DIR metadata


                    // all good
                    retVal.Success = true;
                    retVal.Valid   = true;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to get package metadata with id {packageId} from repository", packageId);
                retVal.ErrorMessage = "Failed to get package metadata from repository";
                throw;
            }

            return(retVal);
        }
예제 #5
0
        public async Task If_Package_is_valid_the_package_is_scheduled_for_sync()
        {
            // Arrange
            var harness = new InMemoryTestHarness();

            try
            {
                var ar = new ArchiveRecord {
                    ArchiveRecordId = "478"
                };
                var mutationId   = 777;
                var errMsg       = string.Empty;
                var appendResult = new RepositoryPackageInfoResult
                {
                    Valid = true, Success = true, ErrorMessage = errMsg, PackageDetails = new RepositoryPackage {
                        ArchiveRecordId = ar.ArchiveRecordId
                    }
                };
                repositoryManager.Setup(e => e.ReadPackageMetadata(It.IsAny <string>(), It.IsAny <string>())).Returns(appendResult);

                var readMetadataConsumer = harness.Consumer(() => readPackageMetadataConsumer.Object);
                harness.Consumer(() => new ReadPackageMetadataConsumer(repositoryManager.Object));
                harness.Consumer(() => readPackageMetadataConsumer.Object);

                await harness.Start();

                // Act
                await harness.InputQueueSendEndpoint.Send <IArchiveRecordAppendPackageMetadata>(new
                {
                    ArchiveRecord = ar,
                    MutationId    = mutationId
                });

                // Assert
                // did the endpoint consume the message
                Assert.That(await harness.Consumed.Any <IArchiveRecordAppendPackageMetadata>());

                // did the actual consumer consume the message
                Assert.That(await readMetadataConsumer.Consumed.Any <IArchiveRecordAppendPackageMetadata>());

                Assert.That(await harness.Sent.Any <IScheduleForPackageSync>());
                var message = harness.Sent.Select <IScheduleForPackageSync>().First().Context.Message;

                // Assert
                message.Workload.ArchiveRecord.ArchiveRecordId.Should().Be(ar.ArchiveRecordId);
                message.Workload.MutationId.Should().Be(mutationId);
            }
            finally
            {
                await harness.Stop();
            }
        }