5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc.
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections.Generic;
31 using System.Globalization;
32 using System.ServiceModel;
33 using NUnit.Framework;
35 namespace MonoTests.System.ServiceModel
38 public class FaultReasonTest
41 [ExpectedException (typeof (ArgumentNullException))]
42 public void CtorNullFaultReasonText ()
44 new FaultReason ((FaultReasonText) null);
48 [ExpectedException (typeof (ArgumentNullException))]
49 public void CtorNullEnumerable ()
51 new FaultReason ((IEnumerable<FaultReasonText>) null);
55 [ExpectedException (typeof (ArgumentException))]
56 public void CtorEmptyEnumerable ()
58 new FaultReason (new List<FaultReasonText> ());
64 FaultReason r = new FaultReason ("testing");
65 FaultReasonText t = r.GetMatchingTranslation ();
67 Assert.AreEqual ("testing", t.Text, "#1");
68 Assert.AreEqual (CultureInfo.CurrentCulture.Name,
73 public void MultipleLanguages ()
75 string current = CultureInfo.CurrentCulture.Name;
77 FaultReason r = new FaultReason (new FaultReasonText [] {
78 new FaultReasonText ("hello"),
79 new FaultReasonText ("hola", "es-ES"),
80 new FaultReasonText ("bonjour", "fr")});
83 FaultReasonText t = r.GetMatchingTranslation (
84 CultureInfo.CurrentCulture);
86 Assert.AreEqual ("hello", t.Text, "#1");
87 Assert.AreEqual (current, t.XmlLang, "#2");
89 // non-neutral name, get by non-neutral culture
90 t = r.GetMatchingTranslation (
91 new CultureInfo ("es-ES"));
93 Assert.AreEqual ("hola", t.Text, "#3");
94 Assert.AreEqual ("es-ES", t.XmlLang, "#4");
96 // .ctor(non-neutral name), get by neutral culture
97 t = r.GetMatchingTranslation (new CultureInfo ("es"));
99 Assert.AreEqual ("hello", t.Text, "#5");
100 Assert.AreEqual (current, t.XmlLang, "#6");
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");
111 public void NoCurrentCulture ()
113 string current = CultureInfo.CurrentCulture.Name;
115 FaultReason r = new FaultReason (new FaultReasonText [] {
116 new FaultReasonText ("hola", "es-ES"),
117 new FaultReasonText ("bonjour", "fr")});
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");
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");