コード例 #1
0
        public void WriteFileCopiesProvidedStreamToOutputStream()
        {
            // Arrange
            int byteLen = 0x1234;

            byte[]       originalBytes  = GetRandomByteArray(byteLen);
            MemoryStream originalStream = new MemoryStream(originalBytes);
            MemoryStream outStream      = new MemoryStream();

            Mock <HttpResponseBase> mockResponse = new Mock <HttpResponseBase>();

            mockResponse.Setup(r => r.OutputStream).Returns(outStream);

            FileStreamResultHelper helper = new FileStreamResultHelper(
                originalStream,
                "application/octet-stream"
                );

            // Act
            helper.PublicWriteFile(mockResponse.Object);

            // Assert
            byte[] outBytes = outStream.ToArray();
            Assert.True(originalBytes.SequenceEqual(outBytes));
            mockResponse.Verify();
        }
コード例 #2
0
        public void WriteFileCopiesProvidedStreamToOutputStream() {
            // Arrange
            int byteLen = 0x1234;
            byte[] originalBytes = GetRandomByteArray(byteLen);
            MemoryStream originalStream = new MemoryStream(originalBytes);
            MemoryStream outStream = new MemoryStream();

            Mock<HttpResponseBase> mockResponse = new Mock<HttpResponseBase>();
            mockResponse.Expect(r => r.OutputStream).Returns(outStream);

            FileStreamResultHelper helper = new FileStreamResultHelper(originalStream, "application/octet-stream");

            // Act
            helper.PublicWriteFile(mockResponse.Object);

            // Assert
            byte[] outBytes = outStream.ToArray();
            Assert.IsTrue(originalBytes.SequenceEqual(outBytes), "Output stream does not match input stream.");
            mockResponse.Verify();
        }