예제 #1
0
        static void AssertFilterArguments(IMimeFilter filter)
        {
            int outputIndex, outputLength;
            var input = new byte[1024];
            ArgumentException ex;

            // Filter
            Assert.Throws <ArgumentNullException> (() => filter.Filter(null, 0, 0, out outputIndex, out outputLength),
                                                   "{0}.Filter did not throw ArgumentNullException when input was null.", filter.GetType().Name);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(input, -1, 0, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when startIndex was -1.", filter.GetType().Name);
            Assert.AreEqual("startIndex", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(input, 0, -1, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when length was -1.", filter.GetType().Name);
            Assert.AreEqual("length", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(input, 1025, 0, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when startIndex was > 1024.", filter.GetType().Name);
            Assert.AreEqual("startIndex", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(input, 0, 1025, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when length was > 1024.", filter.GetType().Name);
            Assert.AreEqual("length", ex.ParamName);

            // Flush
            Assert.Throws <ArgumentNullException> (() => filter.Flush(null, 0, 0, out outputIndex, out outputLength),
                                                   "{0}.Filter did not throw ArgumentNullException when input was null.", filter.GetType().Name);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(input, -1, 0, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when startIndex was -1.", filter.GetType().Name);
            Assert.AreEqual("startIndex", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(input, 0, -1, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when length was -1.", filter.GetType().Name);
            Assert.AreEqual("length", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(input, 1025, 0, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when startIndex was > 1024.", filter.GetType().Name);
            Assert.AreEqual("startIndex", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(input, 0, 1025, out outputIndex, out outputLength),
                                                              "{0}.Filter did not throw ArgumentOutOfRangeException when length was > 1024.", filter.GetType().Name);
            Assert.AreEqual("length", ex.ParamName);

            filter.Reset();
        }