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)); } }
public Stream NormaliseStream(MimePart mimePart) { string contentType = _contentTypeProvider.GetContentType(mimePart); switch (contentType) { case ContentType.ApplicationGzip: return(Decompress(mimePart, _gZipDecompressor, _zipDecompressor)); case ContentType.ApplicationXZipCompressed: case ContentType.ApplicationZip: return(Decompress(mimePart, _zipDecompressor, _gZipDecompressor)); case ContentType.ApplicationOctetStream: string extension = Path.GetExtension(mimePart.FileName.Split('!').LastOrDefault()); if (extension?.StartsWith(".z") ?? false) { return(Decompress(mimePart, _zipDecompressor, _gZipDecompressor)); } return(Decompress(mimePart, _gZipDecompressor, _zipDecompressor)); case ContentType.TextXml: return(mimePart.GetDecodedStream()); default: return(Stream.Null); } }