Exemple #1
0
        public static Stream GetVulnerabilities(CxRestContext ctx,
                                                CancellationToken token, String reportId)
        {
            return(WebOperation.ExecuteGet <Stream>(
                       ctx.Xml.CreateSastClient
                       , (response) =>
            {
                var report = response.Content.ReadAsStreamAsync().Result;
                var mem = new SharedMemoryStream(response.Content.Headers.ContentLength.Value);

                int readAmount = 0;
                byte[] buffer = new byte[BUFFER_SIZE];

                do
                {
                    readAmount = report.Read(buffer, 0, BUFFER_SIZE);

                    mem.Write(buffer, 0, readAmount);

                    if (readAmount < BUFFER_SIZE)
                    {
                        mem.Seek(0, SeekOrigin.Begin);
                    }
                } while (readAmount == BUFFER_SIZE);

                return mem;
            }
                       , CxRestContext.MakeUrl(ctx.Url, String.Format(URL_SUFFIX, reportId))
                       , ctx
                       , token));
        }
Exemple #2
0
 public void SeekEndZeroOffsetDoesMovesToEnd()
 {
     using (var sms = new SharedMemoryStream(buffer1.Length * 2))
     {
         sms.Write(buffer1, 0, buffer1.Length);
         sms.Seek(0, System.IO.SeekOrigin.End);
         Assert.Equal(buffer1.Length, sms.Position);
     }
 }
Exemple #3
0
        public void Write_ShouldThrowNotSupportedExceptionAsStreamIsReadOnly()
        {
            // Arrange
            var bytes = GetRandomBytes();
            var sharedMemoryStream = new SharedMemoryStream(bytes);

            // Act
            // Assert
            Assert.That(() => sharedMemoryStream.Write(new byte[100], 0, 100), Throws.TypeOf <NotSupportedException>());
        }
Exemple #4
0
        public void NoReadUnwritten()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length * 2))
            {
                sms.Write(buffer1, 0, buffer1.Length);

                byte[] one = new byte[] { 5 };

                sms.Write(one, 0, one.Length);
                sms.Seek(0, System.IO.SeekOrigin.Begin);


                byte[] outData = new byte[buffer1.Length + one.Length];

                int read = sms.Read(outData, 0, buffer1.Length + one.Length);

                Assert.Equal(read, buffer1.Length + one.Length);
            }
        }
Exemple #5
0
        public void WriteMovesPositionSameAmountDefault()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length))
            {
                var posBefore = sms.Position;

                sms.Write(buffer1, 0, buffer1.Length);

                Assert.Equal(buffer1.Length, sms.Position - posBefore);
            }
        }
Exemple #6
0
 public void NoReadBeyondCapacity()
 {
     using (var sms = new SharedMemoryStream(buffer1.Length))
     {
         sms.Write(buffer1, 0, buffer1.Length);
         sms.Seek(0, System.IO.SeekOrigin.Begin);
         byte[] localBuf = new byte[buffer1.Length * 2];
         int    amount   = sms.Read(localBuf, 0, localBuf.Length);
         Assert.Equal(buffer1.Length, amount);
     }
 }
Exemple #7
0
        public void WriteMovesPositionSameAmountAfterPositionChange()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length * 2))
            {
                sms.Position++;

                var posBefore = sms.Position;

                sms.Write(buffer1, 0, buffer1.Length);

                Assert.Equal(buffer1.Length, sms.Position - posBefore);
            }
        }
        public void BasicTest()
        {
            var data = new byte[0x1000];

            var buffer = new byte[0x1000];

            var oStream = new SharedMemoryStream();
            var reader = oStream.GetReader();

            var evt = new AutoResetEvent(false);

            Action a = () =>
            {
                evt.WaitOne();
                oStream.Write(data, 0, 16);
                evt.WaitOne();
                oStream.Write(data, 0, 16);
            };

            var t = new Thread(new ThreadStart(a));
            t.Start();

            var task = reader.ReadAsync(buffer, 0, 1000);
            evt.Set();
            task.Wait();
            var s = task.Result;
            log.WriteLine(s.ToString());

            task = reader.ReadAsync(buffer, 0, 1000);

            evt.Set();

            task.Wait();
            s = task.Result;
            log.WriteLine(s.ToString());
            t.Join();
        }
Exemple #9
0
        public void ReadAfterWriteResultsInSameData()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length))
            {
                sms.Write(buffer1, 0, buffer1.Length);
                sms.Seek(0, System.IO.SeekOrigin.Begin);

                byte[] readBack = new byte[buffer1.Length];

                int amount = sms.Read(readBack, 0, readBack.Length);

                Assert.Equal(buffer1.Length, amount);
                Assert.Equal(buffer1, readBack);
            }
        }
Exemple #10
0
        public void NoWriteNullArray()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length - 1))
                try
                {
                    sms.Write(null, 0, 10);
                }
                catch (ArgumentException)
                {
                    Assert.True(true);
                    return;
                }

            Assert.True(false);
        }
Exemple #11
0
        public void NoWriteNegative()
        {
            using (var sms = new SharedMemoryStream(buffer1.Length - 1))
                try
                {
                    sms.Write(buffer1, 0, -1);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Assert.True(true);
                    return;
                }

            Assert.True(false);
        }
        public void ReadTest()
        {
            var stream = new SharedMemoryStream();

            var buffer = new byte[10000];

            stream.Write(buffer, 0, 10000);
            Assert.Equal(10000, stream.Length);

            var reader = stream.GetReader();
            var b = new byte[1];
            while (reader.Read(b, 0, 1) != 0) {

            }

            Assert.Equal(10000, reader.Position);
        }
        public void WriteTest()
        {
            var stream = new SharedMemoryStream();

            var buffer = new byte[1];
            for(int i = 0; i < 10000;i++)
            {
                stream.Write(buffer, 0, 1);
            }
            Assert.Equal(10000, stream.Length);
        }