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