Merge pull request #2820 from kumpera/license-change-rebased
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel / FaultReasonTest.cs
1 //
2 // FaultReasonTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections.Generic;
31 using System.Globalization;
32 using System.ServiceModel;
33 using NUnit.Framework;
34
35 namespace MonoTests.System.ServiceModel
36 {
37         [TestFixture]
38         public class FaultReasonTest
39         {
40                 [Test]
41                 [ExpectedException (typeof (ArgumentNullException))]
42                 public void CtorNullFaultReasonText ()
43                 {
44                         new FaultReason ((FaultReasonText) null);
45                 }
46
47                 [Test]
48                 [ExpectedException (typeof (ArgumentNullException))]
49                 public void CtorNullEnumerable ()
50                 {
51                         new FaultReason ((IEnumerable<FaultReasonText>) null);
52                 }
53
54                 [Test]
55                 [ExpectedException (typeof (ArgumentException))]
56                 public void CtorEmptyEnumerable ()
57                 {
58                         new FaultReason (new List<FaultReasonText> ());
59                 }
60
61                 [Test]
62                 public void Simple ()
63                 {
64                         FaultReason r = new FaultReason ("testing");
65                         FaultReasonText t = r.GetMatchingTranslation ();
66                         Assert.IsNotNull (t);
67                         Assert.AreEqual ("testing", t.Text, "#1");
68                         Assert.AreEqual (CultureInfo.CurrentCulture.Name,
69                                 t.XmlLang, "#2");
70                 }
71
72                 [Test]
73                 public void MultipleLanguages ()
74                 {
75                         string current = CultureInfo.CurrentCulture.Name;
76
77                         FaultReason r = new FaultReason (new FaultReasonText [] {
78                                 new FaultReasonText ("hello"),
79                                 new FaultReasonText ("hola", "es-ES"),
80                                 new FaultReasonText ("bonjour", "fr")});
81
82                         // CurrentCulture
83                         FaultReasonText t = r.GetMatchingTranslation (
84                                 CultureInfo.CurrentCulture);
85                         Assert.IsNotNull (t);
86                         Assert.AreEqual ("hello", t.Text, "#1");
87                         Assert.AreEqual (current, t.XmlLang, "#2");
88
89                         // non-neutral name, get by non-neutral culture
90                         t = r.GetMatchingTranslation (
91                                 new CultureInfo ("es-ES"));
92                         Assert.IsNotNull (t);
93                         Assert.AreEqual ("hola", t.Text, "#3");
94                         Assert.AreEqual ("es-ES", t.XmlLang, "#4");
95
96                         // .ctor(non-neutral name), get by neutral culture
97                         t = r.GetMatchingTranslation (new CultureInfo ("es"));
98                         Assert.IsNotNull (t);
99                         Assert.AreEqual ("hello", t.Text, "#5");
100                         Assert.AreEqual (current, t.XmlLang, "#6");
101
102                         // .ctor(neutral name), get by non-neutral culture
103                         t = r.GetMatchingTranslation (
104                                 new CultureInfo ("fr-FR"));
105                         Assert.IsNotNull (t);
106                         Assert.AreEqual ("bonjour", t.Text, "#7");
107                         Assert.AreEqual ("fr", t.XmlLang, "#8");
108                 }
109
110                 [Test]
111                 public void NoCurrentCulture ()
112                 {
113                         string current = CultureInfo.CurrentCulture.Name;
114
115                         FaultReason r = new FaultReason (new FaultReasonText [] {
116                                 new FaultReasonText ("hola", "es-ES"),
117                                 new FaultReasonText ("bonjour", "fr")});
118
119                         // CurrentCulture
120                         FaultReasonText t = r.GetMatchingTranslation (
121                                 CultureInfo.CurrentCulture);
122                         Assert.IsNotNull (t);
123                         // seems like the first item is used.
124                         Assert.AreEqual ("hola", t.Text, "#1");
125                         Assert.AreEqual ("es-ES", t.XmlLang, "#2");
126
127                         // InvariantCulture
128                         t = r.GetMatchingTranslation (
129                                 CultureInfo.InvariantCulture);
130                         Assert.IsNotNull (t);
131                         // seems like the first item is used.
132                         Assert.AreEqual ("hola", t.Text, "#3");
133                         Assert.AreEqual ("es-ES", t.XmlLang, "#4");
134                 }
135         }
136 }