コード例 #1
0
        public void GenericResult_Faults()
        {
            try
            {
                GenericResult.ClearExceptions();

                GenericResult <string> result;

                result = new GenericResult <string>(new MyException1("hello"));
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a RemoteException");
                }
                catch (RemoteException)
                {
                    // Expected
                }

                GenericResult.RegisterException(typeof(MyException1));

                result = new GenericResult <string>(new MyException1("hello"));
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a MyException1");
                }
                catch (MyException1)
                {
                    // Expected
                }

                result = new GenericResult <string>(new MyException2("hello"));
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a RemoteException");
                }
                catch (RemoteException)
                {
                    // Expected
                }

                GenericResult.RegisterCommonExceptions();

                result = new GenericResult <string>(new TimeoutException("hello"));
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a TimeoutException");
                }
                catch (TimeoutException)
                {
                    // Expected
                }

                result = new GenericResult <string>(new SecurityException("hello"));
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a SecurityException");
                }
                catch (SecurityException)
                {
                    // Expected
                }

                result = new GenericResult <string>(new NotImplementedException());
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a NotImplementedException");
                }
                catch (NotImplementedException)
                {
                    // Expected
                }

                result = new GenericResult <string>(new ArgumentException());
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a ArgumentException");
                }
                catch (ArgumentException)
                {
                    // Expected
                }

                result = new GenericResult <string>(new ArgumentNullException());
                try
                {
                    GenericResult <string> .GetOrThrow(result);

                    Assert.Fail("Expected a ArgumentNullException");
                }
                catch (ArgumentNullException)
                {
                    // Expected
                }
            }
            finally
            {
                GenericResult.ClearExceptions();
            }
        }