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));
92 [NUnit.Framework.CategoryAttribute ("NotWorking")]
93 // Since ValueSerializer has moved to System.Xaml.dll while the type
94 // this test expects is in WindowsBase, there should be some additional
95 // support code in this assembly. Until someone does that job, this
98 public void CanConvertFromString ()
100 Context context = new Context ();
101 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime), context);
103 Assert.AreEqual ("DateTimeValueSerializer", serializer.GetType().Name, "1");
105 Assert.IsTrue (serializer.CanConvertFromString (null, context), "2");
106 Assert.IsTrue (serializer.CanConvertFromString ("2008-01-18T10:39:27.106426-08:00", context), "3");
107 Assert.IsTrue (serializer.CanConvertFromString ("2008-01-.106426-08:00", context), "4");
111 [NUnit.Framework.CategoryAttribute ("NotWorking")]
112 // Since ValueSerializer has moved to System.Xaml.dll while the type
113 // this test expects is in WindowsBase, there should be some additional
114 // support code in this assembly. Until someone does that job, this
118 [ExpectedException (typeof (ArgumentException))] // Expected object of type 'DateTime'.
119 public void CanConvertToString1 ()
121 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
122 Context context = new Context ();
124 serializer.CanConvertToString (null, context);
127 public void CanConvertToString2 ()
129 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
130 Context context = new Context ();
132 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
134 Assert.IsTrue (serializer.CanConvertToString (dt, context), "6");
138 public void ConvertFromString1 ()
140 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
141 Context context = new Context ();
143 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
145 Assert.AreEqual (dt, serializer.ConvertFromString ("2008-01-18T10:39:27.106426-08:00", context), "2");
149 [ExpectedException (typeof (NotSupportedException))] // 'DateTimeValueSerializer' ValueSerializer cannot convert from '(null)'
150 public void ConvertFromString2 ()
152 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
153 Context context = new Context ();
155 serializer.ConvertFromString (null, context);
159 [ExpectedException (typeof (FormatException))] // String was not recognized as a valid DateTime.
160 public void ConvertFromString3 ()
162 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
163 Context context = new Context ();
165 serializer.ConvertFromString ("2008-01-.106426-08:00", context);
169 [NUnit.Framework.CategoryAttribute ("NotWorking")]
170 public void ConvertToString1 ()
172 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
173 Context context = new Context ();
175 DateTime dt = DateTime.Parse ("2008-01-18T10:39:27.106426-08:00");
177 Assert.AreEqual ("2008-01-18T10:39:27.106426-08:00", serializer.ConvertToString (dt, context), "1");
181 [ExpectedException (typeof (NotSupportedException))]
182 public void ConvertToString2 ()
184 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
185 Context context = new Context ();
187 serializer.ConvertToString (null, context);
191 [ExpectedException (typeof (NotSupportedException))]
192 public void ConvertToString3 ()
194 ValueSerializer serializer = (ValueSerializer)ValueSerializer.GetSerializerFor (typeof (DateTime));
195 Context context = new Context ();
197 serializer.ConvertToString (1, context);