Beispiel #1
0
        void exceptionTesting(IZipChecksum crcUnderTest)
        {
            var exception = false;

            try
            {
                crcUnderTest.Update(null);
            }
            catch (ArgumentNullException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(null, 0, 0).Array);
            }
            catch (ArgumentNullException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, -1, 9).Array);
            }
            catch (ArgumentOutOfRangeException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a negative offset should cause an ArgumentOutOfRangeException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 10, 0).Array);
            }
            catch (ArgumentException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing an offset greater than buffer.Length should cause an ArgumentException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 0, -1).Array);
            }
            catch (ArgumentOutOfRangeException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a negative count should cause an ArgumentOutOfRangeException");

            // reset exception
            exception = false;
            try
            {
                crcUnderTest.Update(new ArraySegment <byte>(check, 0, 10).Array);
            }
            catch (ArgumentException)
            {
                exception = true;
            }
            Assert.IsTrue(exception, "Passing a count + offset greater than buffer.Length should cause an ArgumentException");
        }