Пример #1
0
        public void ContentTypeApplicationGzipDecompressesAsGzip()
        {
            MimePart mimePart = CreateMimePart("application", "gzip", "test.gz");

            AttachmentInfo attachment = _attachmentStreamNormaliser.Normalise(mimePart);

            A.CallTo(() => _gZipDecompressor.Decompress(A <Stream> ._)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.That(attachment, Is.Not.Null);
            Assert.That(attachment.AttachmentMetadata.Filename, Is.EqualTo(mimePart.FileName));
        }
Пример #2
0
        public void Test(string mediaType, string mediaSubType, string fileName, bool gZipCalled, bool zipCalled, bool gzipSuccess = true, bool zipSuccess = true, bool success = true)
        {
            MimePart mimePart = CreateMimePart(mediaType, mediaSubType, fileName);

            A.CallTo(() => _contentTypeProvider.GetContentType(A <MimePart> ._)).Returns($@"{mediaType}/{mediaSubType}");

            if (!gzipSuccess)
            {
                A.CallTo(() => _gZipDecompressor.Decompress(A <Stream> ._)).Throws <Exception>();
            }

            if (!zipSuccess)
            {
                A.CallTo(() => _zipDecompressor.Decompress(A <Stream> ._)).Throws <Exception>();
            }

            AttachmentInfo attachment = _attachmentStreamNormaliser.Normalise(mimePart);

            A.CallTo(() => _gZipDecompressor.Decompress(A <Stream> ._)).MustHaveHappened(gZipCalled ? Repeated.Exactly.Once : Repeated.Never);
            A.CallTo(() => _zipDecompressor.Decompress(A <Stream> ._)).MustHaveHappened(zipCalled ? Repeated.Exactly.Once : Repeated.Never);

            if (success)
            {
                Assert.That(attachment, Is.Not.Null);
                Assert.That(attachment.AttachmentMetadata.Filename, Is.EqualTo(mimePart.FileName));
            }
            else
            {
                Assert.That(attachment, Is.EqualTo(AttachmentInfo.EmptyAttachmentInfo));
            }
        }