FaultExceptionTest.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.ServiceModel.Channels;
  7. using System.Text;
  8. using System.Xml;
  9. using NUnit.Framework;
  10. namespace MonoTests.System.ServiceModel
  11. {
  12. [TestFixture]
  13. public class FaultExceptionTest
  14. {
  15. [Test]
  16. public void TestDefaults ()
  17. {
  18. FaultException<int> e = new FaultException<int> (0);
  19. Assert.AreEqual (0, e.Detail, "#1");
  20. Assert.IsNull (e.Action, "#2");
  21. }
  22. [Test]
  23. public void TestMessage ()
  24. {
  25. FaultException<int> e = new FaultException<int> (0);
  26. Assert.AreEqual (e.Message, e.Reason.GetMatchingTranslation ().Text);
  27. }
  28. [Test]
  29. public void TestCode ()
  30. {
  31. // default Code is a SenderFault with a null SubCode
  32. FaultException<int> e = new FaultException<int> (0);
  33. Assert.IsTrue (e.Code.IsSenderFault);
  34. Assert.IsNull (e.Code.SubCode);
  35. }
  36. [Test]
  37. public void TestAction ()
  38. {
  39. FaultException<int> e = new FaultException<int> (0);
  40. Assert.IsNull (e.Action);
  41. }
  42. static void AreMessageFaultEqual (MessageFault a, MessageFault b, string label)
  43. {
  44. Assert.AreEqual (a.Actor, b.Actor, label + ".Actor");
  45. Assert.AreEqual (a.Code, b.Code, label + ".Code");
  46. Assert.AreEqual (a.HasDetail, b.HasDetail, label + ".HasDetail");
  47. Assert.AreEqual (a.Node, b.Node, label + ".Node");
  48. Assert.AreEqual (a.Reason, b.Reason, label + ".Reason");
  49. }
  50. [Test]
  51. public void TestCreateMessageFault ()
  52. {
  53. FaultException<int> e = new FaultException<int> (0); Assert.IsFalse (
  54. (object) MessageFault.CreateFault (e.Code, e.Reason, e.Detail)
  55. == e.CreateMessageFault (), "#1");
  56. AreMessageFaultEqual (
  57. MessageFault.CreateFault (e.Code, e.Reason, e.Detail),
  58. e.CreateMessageFault (), "#2");
  59. }
  60. [Test]
  61. [Ignore ("this test is old")]
  62. public void TestGetObjectData ()
  63. {
  64. FaultException<int> e = new FaultException<int> (0);
  65. if (true) {
  66. XmlWriterSettings s = new XmlWriterSettings ();
  67. s.Indent = true;
  68. s.ConformanceLevel = ConformanceLevel.Fragment;
  69. XmlWriter w = XmlWriter.Create (TextWriter.Null, s);
  70. XmlObjectSerializer formatter = new DataContractSerializer (typeof (int));
  71. formatter.WriteObject (w, e);
  72. w.Close ();
  73. }
  74. }
  75. [Test]
  76. [Ignore ("This test premises English.")]
  77. public void TestToString ()
  78. {
  79. FaultException<int> e = new FaultException<int> (0);
  80. Assert.AreEqual (
  81. String.Format ("{0}: {1} (Fault Detail is equal to {2}).", e.GetType (), e.Message, e.Detail),
  82. e.ToString ());
  83. }
  84. }
  85. }