Exemple #1
0
        public void CanCreatePoliciesForHandler()
        {
            ExceptionPolicyData exceptionPolicyData = new ExceptionPolicyData("policy");

            settings.ExceptionPolicies.Add(exceptionPolicyData);
            ExceptionTypeData exceptionTypeData = new ExceptionTypeData("type1", typeof(Exception), PostHandlingAction.ThrowNewException);

            exceptionPolicyData.ExceptionTypes.Add(exceptionTypeData);
            FaultContractExceptionHandlerData exceptionHandlerData = new FaultContractExceptionHandlerData("handler1",
                                                                                                           typeof(MockFaultContract).AssemblyQualifiedName);

            exceptionHandlerData.ExceptionMessage = "fault message";
            exceptionHandlerData.PropertyMappings.Add(new FaultContractExceptionHandlerMappingData("Message", "{Message}"));
            exceptionHandlerData.PropertyMappings.Add(new FaultContractExceptionHandlerMappingData("Data", "{Data}"));
            exceptionHandlerData.PropertyMappings.Add(new FaultContractExceptionHandlerMappingData("SomeNumber", "{OffendingNumber}"));
            exceptionTypeData.ExceptionHandlers.Add(exceptionHandlerData);
            container.AddExtension(new ExceptionHandlingBlockExtension());
            ExceptionPolicyImpl      policy            = container.Resolve <ExceptionPolicyImpl>("policy");
            NotFiniteNumberException originalException = new NotFiniteNumberException("MyException", 12341234123412);

            originalException.Data.Add("someKey", "someValue");
            try
            {
                policy.HandleException(originalException);
                Assert.Fail("a new exception should have been thrown");
            }
            catch (FaultContractWrapperException e)
            {
                MockFaultContract fault = (MockFaultContract)e.FaultContract;
                Assert.AreEqual(originalException.Message, fault.Message);
                Assert.AreEqual(originalException.Data.Count, fault.Data.Count);
                Assert.AreEqual(originalException.Data["someKey"], fault.Data["someKey"]);
                Assert.AreEqual(originalException.OffendingNumber, fault.SomeNumber);
            }
        }
        public void CanCreateInstanceWithFaultContract()
        {
            MockFaultContract             faultContract = new MockFaultContract();
            FaultContractWrapperException instance      = new FaultContractWrapperException(faultContract);

            Assert.IsNotNull(instance);
            Assert.AreEqual(faultContract, instance.FaultContract);
        }
        public void CanCreateInstanceWithFaultContract()
        {
            MockFaultContract faultContract = new MockFaultContract();
            FaultContractWrapperException instance = new FaultContractWrapperException(faultContract);

            Assert.IsNotNull(instance);
            Assert.AreEqual(faultContract, instance.FaultContract);
        }
        public void CanCreateInstanceWithFaultContractAndGuid()
        {
            MockFaultContract faultContract = new MockFaultContract();
            Guid guid = Guid.NewGuid();
            FaultContractWrapperException instance = new FaultContractWrapperException(faultContract, guid);

            Assert.AreEqual(faultContract, instance.FaultContract);
            Assert.IsTrue(instance.Message.Contains(guid.ToString()));
        }
        public void CanCreateInstanceWithFaultContractAndGuid()
        {
            MockFaultContract faultContract = new MockFaultContract();
            Guid guid = Guid.NewGuid();
            FaultContractWrapperException instance = new FaultContractWrapperException(faultContract, guid);

            Assert.AreEqual(faultContract, instance.FaultContract);
            Assert.IsTrue(instance.Message.Contains(guid.ToString()));
        }
        public void CanCreateInstanceWithFaultContractAndGuidAndNullMessage()
        {
            MockFaultContract faultContract = new MockFaultContract();
            Guid      guid           = Guid.NewGuid();
            Exception innerException = new Exception();
            FaultContractWrapperException instance = new FaultContractWrapperException(faultContract, guid, null);

            Assert.AreEqual(faultContract, instance.FaultContract);
            Assert.IsFalse(string.IsNullOrEmpty(instance.Message));
            Assert.IsTrue(instance.Message.Contains(guid.ToString()));
        }
        public void CanCreateInstanceWithFaultContractAndGuidAndNullMessage()
        {
            MockFaultContract faultContract = new MockFaultContract();
            Guid guid = Guid.NewGuid();
            Exception innerException = new Exception();
            FaultContractWrapperException instance = new FaultContractWrapperException(faultContract, guid, null);

            Assert.AreEqual(faultContract, instance.FaultContract);
            Assert.IsFalse(string.IsNullOrEmpty(instance.Message));
            Assert.IsTrue(instance.Message.Contains(guid.ToString()));
        }
        public void CanAssignFaultContractMessage()
        {
            MockFaultContract             mock     = new MockFaultContract("message");
            FaultContractWrapperException instance = new FaultContractWrapperException(mock);

            Assert.AreSame(mock, instance.FaultContract);
            MockFaultContract newMock = new MockFaultContract();

            instance.FaultContract = newMock;
            Assert.AreSame(newMock, instance.FaultContract);
        }
        public void CanAssignFaultContractMessage()
        {
            MockFaultContract mock = new MockFaultContract("message");
            FaultContractWrapperException instance = new FaultContractWrapperException(mock);

            Assert.AreSame(mock, instance.FaultContract);

            MockFaultContract newMock = new MockFaultContract();
            instance.FaultContract = newMock;

            Assert.AreSame(newMock, instance.FaultContract);
        }
Exemple #10
0
        public void CanProvideFaultOnCustomPolicyName()
        {
            ExceptionShieldingErrorHandler shielding = new ExceptionShieldingErrorHandler("CustomPolicy");
            Message message = GetDefaultMessage();

            shielding.ProvideFault(new ArgumentException("Arg"), MessageVersion.Default, ref message);

            MessageFault fault = GetFaultFromMessage(message);

            Assert.IsTrue(fault.HasDetail);
            Assert.IsTrue(fault.Code.IsSenderFault);
            //DataContractSerializer serializer = new DataContractSerializer(typeof(MockFaultContract));
            MockFaultContract details = fault.GetDetail <MockFaultContract>();

            Assert.IsNotNull(details);
            Assert.AreEqual("Arg", details.Message);
        }
Exemple #11
0
        public void CanProvideFaultWithMockHandler()
        {
            ExceptionShieldingErrorHandler shielding = new ExceptionShieldingErrorHandler();
            ArithmeticException            exception = new ArithmeticException("My Exception");
            Message message = GetDefaultMessage();

            shielding.ProvideFault(exception, MessageVersion.Default, ref message);

            MessageFault fault = GetFaultFromMessage(message);

            Assert.IsTrue(fault.Code.IsSenderFault);
            //DataContractSerializer serializer = new DataContractSerializer(typeof(MockFaultContract));
            MockFaultContract details = fault.GetDetail <MockFaultContract>();

            Assert.IsNotNull(details);
            Assert.AreEqual(exception.Message, details.Message);
        }
Exemple #12
0
        public void CanPopulateFaultContractFromExceptionProperties()
        {
            ExceptionShieldingErrorHandler shielding = new ExceptionShieldingErrorHandler();
            Message   message   = GetDefaultMessage();
            Exception exception = new ArgumentNullException("MyMessage");

            shielding.ProvideFault(exception, MessageVersion.Default, ref message);

            MessageFault fault = GetFaultFromMessage(message);

            Assert.IsTrue(fault.HasDetail);
            Assert.IsTrue(fault.Code.IsSenderFault);
            MockFaultContract details = fault.GetDetail <MockFaultContract>();

            Assert.IsNotNull(details);
            Assert.AreEqual(exception.Message, details.Message);
            Assert.IsTrue(details.Id != Guid.Empty);
        }
Exemple #13
0
        public void ShouldReturnSenderFault()
        {
            ExceptionShieldingErrorHandler shielding = new ExceptionShieldingErrorHandler();
            Message   message   = GetDefaultMessage();
            Exception exception = new ArithmeticException("Message");

            shielding.ProvideFault(exception, MessageVersion.Default, ref message);

            MessageFault fault = GetFaultFromMessage(message);

            Assert.IsTrue(fault.Code.IsSenderFault);
            Assert.IsFalse(string.IsNullOrEmpty(fault.Reason.ToString()));
            Assert.IsTrue(fault.HasDetail);
            MockFaultContract details = fault.GetDetail <MockFaultContract>();

            Assert.IsNotNull(details);
            Assert.AreEqual(exception.Message, details.Message);
        }
Exemple #14
0
        public void CanInjectAttributesIntoFaultContract()
        {
            NameValueCollection attributes = new NameValueCollection();

            attributes.Add("Message", "{Message}");
            attributes.Add("Data", "{Data}");
            attributes.Add("SomeNumber", "{OffendingNumber}");

            FaultContractExceptionHandler instance  = new FaultContractExceptionHandler(typeof(MockFaultContract), attributes);
            NotFiniteNumberException      exception = new NotFiniteNumberException("MyException", 12341234123412);

            exception.Data.Add("someKey", "someValue");
            FaultContractWrapperException result = (FaultContractWrapperException)instance.HandleException(exception, Guid.NewGuid());

            MockFaultContract fault = (MockFaultContract)result.FaultContract;

            Assert.AreEqual(exception.Message, fault.Message);
            Assert.AreEqual(exception.Data.Count, fault.Data.Count);
            Assert.AreEqual(exception.Data["someKey"], fault.Data["someKey"]);
            Assert.AreEqual(exception.OffendingNumber, fault.SomeNumber);
        }