System.Security.Tests.SecureStringTests.Dispose_AllOtherOperationsThrow C# (CSharp) Method

Dispose_AllOtherOperationsThrow() private method

private Dispose_AllOtherOperationsThrow ( ) : void
return void
        public static void Dispose_AllOtherOperationsThrow()
        {
            SecureString ss = CreateSecureString("test");
            ss.Dispose();

            Assert.Throws<ObjectDisposedException>(() => ss.AppendChar('a'));
            Assert.Throws<ObjectDisposedException>(() => ss.Clear());
            Assert.Throws<ObjectDisposedException>(() => ss.Copy());
            Assert.Throws<ObjectDisposedException>(() => ss.InsertAt(0, 'a'));
            Assert.Throws<ObjectDisposedException>(() => ss.IsReadOnly());
            Assert.Throws<ObjectDisposedException>(() => ss.Length);
            Assert.Throws<ObjectDisposedException>(() => ss.MakeReadOnly());
            Assert.Throws<ObjectDisposedException>(() => ss.RemoveAt(0));
            Assert.Throws<ObjectDisposedException>(() => ss.SetAt(0, 'a'));
            Assert.Throws<ObjectDisposedException>(() => SecureStringMarshal.SecureStringToCoTaskMemAnsi(ss));
            Assert.Throws<ObjectDisposedException>(() => SecureStringMarshal.SecureStringToCoTaskMemUnicode(ss));
            Assert.Throws<ObjectDisposedException>(() => SecureStringMarshal.SecureStringToGlobalAllocAnsi(ss));
            Assert.Throws<ObjectDisposedException>(() => SecureStringMarshal.SecureStringToGlobalAllocUnicode(ss));

            ss.Dispose(); // ok to call again
        }