1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
23 // Chris Toshok (toshok@ximian.com)
27 using System.ComponentModel;
29 using System.Windows.Converters;
30 using System.Windows.Markup;
31 using NUnit.Framework;
33 namespace MonoTests.System.Windows.Markup {
36 public class DateTimeValueSerializerTest
38 class Context : IValueSerializerContext {
39 public ValueSerializer GetValueSerializerFor (PropertyDescriptor descriptor)
44 public ValueSerializer GetValueSerializerFor (Type type)
49 public void OnComponentChanged ()
53 public bool OnComponentChanging ()
58 public IContainer Container {
62 public object Instance {
66 public PropertyDescriptor PropertyDescriptor {
70 public object GetService (Type serviceType)
77 public void CanConvertFromStringNullContext ()
79 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
80 Assert.IsTrue (serializer.CanConvertFromString (null, null));
84 public void CanConvertToStringNullContext ()
86 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
87 Assert.IsTrue (serializer.CanConvertToString (DateTime.Now, null));
91 [NUnit.Framework.CategoryAttribute ("NotWorking")]
92 // Since ValueSerializer has moved to System.Xaml.dll while the type
93 // this test expects is in WindowsBase, there should be some additional
94 // support code in this assembly. Until someone does that job, this
96 public void CanConvertFromString ()
98 Context context = new Context ();
99 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime), context);
101 Assert.AreEqual ("DateTimeValueSerializer", serializer.GetType().Name, "1");
103 Assert.IsTrue (serializer.CanConvertFromString (null, context), "2");
104 Assert.IsTrue (serializer.CanConvertFromString ("2008-01-18T10:39:27.106426-08:00", context), "3");
105 Assert.IsTrue (serializer.CanConvertFromString ("2008-01-.106426-08:00", context), "4");
108 [NUnit.Framework.CategoryAttribute ("NotWorking")]
109 // Since ValueSerializer has moved to System.Xaml.dll while the type
110 // this test expects is in WindowsBase, there should be some additional
111 // support code in this assembly. Until someone does that job, this
114 [ExpectedException (typeof (ArgumentException))] // Expected object of type 'DateTime'.
115 public void CanConvertToString1 ()
117 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
118 Context context = new Context ();
120 serializer.CanConvertToString (null, context);
123 public void CanConvertToString2 ()
125 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
126 Context context = new Context ();
128 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
130 Assert.IsTrue (serializer.CanConvertToString (dt, context), "6");
134 public void ConvertFromString1 ()
136 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
137 Context context = new Context ();
139 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
141 Assert.AreEqual (dt, serializer.ConvertFromString ("2008-01-18T10:39:27.106426-08:00", context), "2");
145 [ExpectedException (typeof (NotSupportedException))] // 'DateTimeValueSerializer' ValueSerializer cannot convert from '(null)'
146 public void ConvertFromString2 ()
148 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
149 Context context = new Context ();
151 serializer.ConvertFromString (null, context);
155 [ExpectedException (typeof (FormatException))] // String was not recognized as a valid DateTime.
156 public void ConvertFromString3 ()
158 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
159 Context context = new Context ();
161 serializer.ConvertFromString ("2008-01-.106426-08:00", context);
165 [NUnit.Framework.CategoryAttribute ("NotWorking")]
166 public void ConvertToString1 ()
168 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
169 Context context = new Context ();
171 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
173 Assert.AreEqual ("2008-01-18T10:39:27.106426-08:00", serializer.ConvertToString (dt, context), "1");
177 [ExpectedException (typeof (NotSupportedException))]
178 public void ConvertToString2 ()
180 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
181 Context context = new Context ();
183 serializer.ConvertToString (null, context);
187 [ExpectedException (typeof (NotSupportedException))]
188 public void ConvertToString3 ()
190 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
191 Context context = new Context ();
193 serializer.ConvertToString (1, context);