コード例 #1
0
ファイル: FilterTests.cs プロジェクト: vinodj/MimeKit
        static void TestArgumentExceptions(IMimeFilter filter)
        {
            int outputIndex, outputLength;
            var buffer = new byte[10];

            Assert.Throws <ArgumentNullException> (() => filter.Filter(null, 0, 0, out outputIndex, out outputLength));
            Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(buffer, -1, 0, out outputIndex, out outputLength));
            Assert.Throws <ArgumentOutOfRangeException> (() => filter.Filter(buffer, 0, 20, out outputIndex, out outputLength));

            Assert.Throws <ArgumentNullException> (() => filter.Flush(null, 0, 0, out outputIndex, out outputLength));
            Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(buffer, -1, 0, out outputIndex, out outputLength));
            Assert.Throws <ArgumentOutOfRangeException> (() => filter.Flush(buffer, 0, 20, out outputIndex, out outputLength));
        }
コード例 #2
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();
        }
コード例 #3
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);
		}