public void TestBehaviorFullDetails()
        {
            RpcExceptionInfo msg = RpcExceptionInfo.Create(AsThrown(new InvalidOperationException("message")),
                                                           RpcErrorDetailBehavior.FullDetails);

            Assert.IsTrue(msg.HasAssemblyName);
            Assert.IsTrue(msg.HasFullTypeName);
            Assert.IsTrue(msg.HasMessage);
            Assert.IsTrue(msg.HasSource);
            Assert.IsTrue(msg.HasStackTraceString);
            Assert.IsTrue(msg.StackTraceString.Contains(GetType().FullName + ".AsThrown(Exception e)"));
            Assert.IsFalse(msg.HasRemoteStackTraceString);

            Assert.AreEqual(typeof(string).Assembly.FullName, msg.AssemblyName);
            Assert.AreEqual(typeof(InvalidOperationException).FullName, msg.FullTypeName);
            Assert.AreEqual("message", msg.Message);

            try
            {
                msg.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception e)
            {
                Assert.AreEqual("message", e.Message);
                Assert.AreEqual(typeof(InvalidOperationException), e.GetType());
                //make sure the original stack is still there as well?
                Assert.IsTrue(e.StackTrace.Contains(GetType().FullName + ".AsThrown(Exception e)"));
                Assert.IsTrue(e.StackTrace.Contains(GetType().FullName + ".TestBehaviorFullDetails()"));
            }
        }
        public void TestBehaviorMessageOnly()
        {
            RpcExceptionInfo msg = RpcExceptionInfo.Create(AsThrown(new InvalidOperationException("message")),
                                                           RpcErrorDetailBehavior.MessageOnly);

            Assert.IsTrue(msg.HasAssemblyName);
            Assert.IsTrue(msg.HasFullTypeName);
            Assert.IsTrue(msg.HasMessage);
            Assert.IsFalse(msg.HasSource);
            Assert.IsFalse(msg.HasStackTraceString);
            Assert.IsFalse(msg.HasRemoteStackTraceString);

            Assert.AreEqual(typeof(string).Assembly.FullName, msg.AssemblyName);
            Assert.AreEqual(typeof(InvalidOperationException).FullName, msg.FullTypeName);
            Assert.AreEqual("message", msg.Message);

            try
            {
                msg.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception e)
            {
                Assert.AreEqual("message", e.Message);
                Assert.AreEqual(typeof(InvalidOperationException), e.GetType());
            }
        }
        public void TestClientLoadAnyAssemblyInvalid()
        {
            RpcExceptionInfo exInfo = RpcExceptionInfo.CreateBuilder()
                                      .SetAssemblyName(@"Me.Oh.My")
                                      .SetFullTypeName("System.ASDF.Abc123Exception")
                                      .Build();

            exInfo.ReThrow(RpcErrorTypeBehavior.LoadAnyAssembly);
        }
        public void TestClientOnlyLoadStrongNamed()
        {
            //this test expects that System.Web.dll is not already loaded.
            foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
            {
                Assert.AreNotEqual(a.GetName().Name, "System.Design");
            }

            RpcExceptionInfo exInfo = RpcExceptionInfo.CreateBuilder()
                                      .SetAssemblyName("System.Design, Version=2.0.0.0, Culture=neutral")
                                      .SetFullTypeName("System.Data.Design.TypedDataSetGeneratorException")
                                      .Build();

            Exception e = new Exception();

            try
            {
                exInfo.ReThrow(RpcErrorTypeBehavior.OnlyLoadStrongNamed);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.AreEqual(typeof(ApplicationException), e.GetType());

            //now provide a key'd assembly name:
            exInfo =
                exInfo.ToBuilder().SetAssemblyName(
                    "System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a").Build();

            try
            {
                exInfo.ReThrow(RpcErrorTypeBehavior.OnlyLoadStrongNamed);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.AreEqual("System.Data.Design.TypedDataSetGeneratorException", e.GetType().FullName);
            Assert.IsNotEmpty(e.Message);
        }
        public void TestClientOnlyUseLoadedAssemblies()
        {
            //this test expects that System.Web.dll is not already loaded.
            foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
            {
                Assert.AreNotEqual(a.GetName().Name, "System.Web");
            }

            RpcExceptionInfo exInfo = RpcExceptionInfo.CreateBuilder()
                                      .SetAssemblyName("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
                                      .SetFullTypeName("System.Web.HttpCompileException")
                                      .Build();

            Exception e = new Exception();

            try
            {
                exInfo.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.AreEqual(typeof(ApplicationException), e.GetType());
            Assembly.Load(exInfo.AssemblyName);

            try
            {
                exInfo.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.AreEqual("System.Web.HttpCompileException", e.GetType().FullName);
            Assert.IsNotEmpty(e.Message);
        }
        public void TestBehaviorNoDetails()
        {
            RpcExceptionInfo msg = RpcExceptionInfo.Create(ThrownException, RpcErrorDetailBehavior.NoDetails);

            Assert.IsFalse(msg.HasAssemblyName);
            Assert.IsFalse(msg.HasFullTypeName);
            Assert.IsFalse(msg.HasMessage);
            //basically it should be empty:
            Assert.AreEqual(new byte[0], msg.ToByteArray());

            try
            {
                msg.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ApplicationException), e.GetType());
            }
        }
        public void TestBehaviorTypeOnly()
        {
            RpcExceptionInfo msg = RpcExceptionInfo.Create(ThrownException, RpcErrorDetailBehavior.TypeOnly);

            Assert.IsTrue(msg.HasAssemblyName);
            Assert.IsTrue(msg.HasFullTypeName);
            Assert.IsFalse(msg.HasMessage);
            Assert.IsFalse(msg.HasSource);
            Assert.IsFalse(msg.HasStackTraceString);
            Assert.IsFalse(msg.HasRemoteStackTraceString);

            Assert.AreEqual(typeof(string).Assembly.FullName, msg.AssemblyName);
            Assert.AreEqual(typeof(ArgumentNullException).FullName, msg.FullTypeName);

            try
            {
                msg.ReThrow(RpcErrorTypeBehavior.OnlyUseLoadedAssemblies);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentNullException), e.GetType());
            }
        }