System.Threading.Tests.MonitorTests.TryEnter_Invalid C# (CSharp) Method

TryEnter_Invalid() private method

private TryEnter_Invalid ( ) : void
return void
        public static void TryEnter_Invalid()
        {
            bool lockTaken = false;
            var obj = new object();

            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null));
            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null, ref lockTaken));
            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null, 1));
            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null, 1, ref lockTaken));
            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null, TimeSpan.Zero));
            Assert.Throws<ArgumentNullException>("obj", () => Monitor.TryEnter(null, TimeSpan.Zero, ref lockTaken));

            Assert.Throws<ArgumentOutOfRangeException>("millisecondsTimeout", () => Monitor.TryEnter(null, -1));
            Assert.Throws<ArgumentOutOfRangeException>("millisecondsTimeout", () => Monitor.TryEnter(null, -1, ref lockTaken));
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => Monitor.TryEnter(null, TimeSpan.FromMilliseconds(-1)));
            Assert.Throws<ArgumentOutOfRangeException>("timeout", () => Monitor.TryEnter(null, TimeSpan.FromMilliseconds(-1), ref lockTaken));

            lockTaken = true;
            Assert.Throws<ArgumentException>("lockTaken", () => Monitor.TryEnter(obj, ref lockTaken));
            lockTaken = true;
            Assert.Throws<ArgumentException>("lockTaken", () => Monitor.TryEnter(obj, 0, ref lockTaken));
            lockTaken = true;
            Assert.Throws<ArgumentException>("lockTaken", () => Monitor.TryEnter(obj, TimeSpan.Zero, ref lockTaken));
        }