Пример #1
0
        public void CreateArchiveFromContent_WithEmptyFileContent_ReturnsNull()
        {
            var emptyContent = string.Empty;

            var resultingArchive = ZipHelper.CreateArchiveFromContent(emptyContent);

            Assert.IsNull(resultingArchive);
        }
Пример #2
0
        public void CreateArchiveFromContent_WithNullFileContent_ReturnsNull()
        {
            var nullContent = (string)null;

            var resultingArchive = ZipHelper.CreateArchiveFromContent(nullContent);

            Assert.IsNull(resultingArchive);
        }
Пример #3
0
        public void Integration_CreateArchiveFromContent_And_ExtractArchivedSingleFileToStream_WorkTogether()
        {
            var content = GetLoremIpsumContent();

            var resultingArchive       = ZipHelper.CreateArchiveFromContent(content);
            var resultingContentStream = ZipHelper.ExtractArchivedSingleFileToStream(resultingArchive);

            Assert.NotNull(resultingContentStream);
            var streamReader = new StreamReader(resultingContentStream);

            Assert.AreEqual(content, streamReader.ReadToEnd());

            resultingContentStream.Dispose();
            streamReader.Close();
        }
Пример #4
0
        public void QueueFeed(IFeedSubmissionEntryService feedSubmissionService, FeedSubmissionPropertiesContainer propertiesContainer, string targetEventId = null, Dictionary <string, object> targetEventArgs = null)
        {
            try
            {
                if (propertiesContainer == null)
                {
                    throw new ArgumentNullException();
                }

                var serializedPropertiesContainer = JsonConvert.SerializeObject(propertiesContainer);

                var feedSubmission = new FeedSubmissionEntry(serializedPropertiesContainer)
                {
                    AmazonRegion             = _region,
                    MerchantId               = _merchantId,
                    LastSubmitted            = DateTime.MinValue,
                    DateCreated              = DateTime.UtcNow,
                    IsProcessingComplete     = false,
                    HasErrors                = false,
                    SubmissionErrorData      = null,
                    FeedSubmissionRetryCount = 0,
                    FeedSubmissionId         = null,
                    FeedType          = propertiesContainer.FeedType,
                    TargetHandlerId   = targetEventId,
                    TargetHandlerArgs = targetEventArgs == null ? null : JsonConvert.SerializeObject(targetEventArgs),
                    InstanceId        = _options?.EventPublishingOptions?.RestrictInvocationToOriginatingInstance?.HashedInstanceId,
                    Details           = new FeedSubmissionDetails
                    {
                        FeedContent = ZipHelper.CreateArchiveFromContent(propertiesContainer.FeedContent)
                    }
                };

                feedSubmissionService.Unlock(feedSubmission, "Unlocking single feed submission entry - newly created, ready for processing.");
                feedSubmissionService.Create(feedSubmission);
                feedSubmissionService.SaveChanges();

                _logger.Debug($"The following feed was queued for submission to Amazon {feedSubmission.EntryIdentityDescription}.");
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);
            }
        }
Пример #5
0
        public void CreateArchiveFromContent_WithValidFileContent_ReturnsValidArchiveContainingTheCorrectContent()
        {
            var content = GetLoremIpsumContent();

            var resultingArchive = ZipHelper.CreateArchiveFromContent(content);

            Assert.NotNull(resultingArchive);

            var successfullyOpenedArchive = new ZipArchive(new MemoryStream(resultingArchive), ZipArchiveMode.Read, true);
            var successfullyReadEntry     = successfullyOpenedArchive.Entries.First().Open();

            Assert.NotNull(successfullyReadEntry);

            var streamReader = new StreamReader(successfullyReadEntry);

            Assert.AreEqual(content, streamReader.ReadToEnd());

            successfullyOpenedArchive.Dispose();
            streamReader.Close();
        }