Permalink
Browse files

Lots of reflection fixes for WinRT + moved to MSTest

  • Loading branch information...
1 parent d3caeea commit bebc42c3bbbc931db248947b070ae7c390a1d682 @activa activa committed Jun 5, 2012
Showing with 4,293 additions and 3,678 deletions.
  1. +1 −0 .gitignore
  2. +59 −6 Library/CoreExtensions.cs
  3. +2 −2 Library/EasyConfig/ConfigManager.cs
  4. +10 −1 Library/MethodInspector.cs
  5. +1 −1 Library/Parser/ExpressionParser/Expression/IndexExpression.cs
  6. +1 −0 Library/Properties/AssemblyInfo.cs
  7. +9 −3 Library/SmartConverter/ObjectConverter.cs
  8. +15 −8 Library/TypeInspector.cs
  9. +0 −1 Library/Vici.Core.Metro.csproj
  10. +17 −17 {Tests → Test}/App.config
  11. +8 −8 {Tests → Test/Data}/Config.xml
  12. BIN Test/Images/UnitTestLogo.png
  13. BIN Test/Images/UnitTestSmallLogo.png
  14. BIN Test/Images/UnitTestSplashScreen.png
  15. BIN Test/Images/UnitTestStoreLogo.png
  16. +54 −0 Test/Package.appxmanifest
  17. +36 −36 {Tests → Test}/Properties/AssemblyInfo.cs
  18. +57 −56 { → Test}/Tests/BinaryExtensionsTest.cs
  19. +198 −198 { → Test}/Tests/ConfigTest.cs
  20. +145 −145 { → Test}/Tests/DynamicObjectTest.cs
  21. +52 −52 { → Test}/Tests/ExpressionWithContext.cs
  22. +183 −183 { → Test}/Tests/Json/JSONParserFixture.cs
  23. +181 −181 { → Test}/Tests/Json/JsonSeralizerTestFixture.cs
  24. +40 −40 { → Test}/Tests/MockTimeProvider.cs
  25. +115 −115 { → Test}/Tests/NotifierTest.cs
  26. +323 −318 { → Test}/Tests/ObjectConverter/ObjectConverterTest.cs
  27. +633 −598 { → Test}/Tests/Parser/CSharpParserFixture.cs
  28. +399 −393 { → Test}/Tests/Parser/TemplateParser_Fixture.cs
  29. +225 −223 { → Test}/Tests/SchedulerTest.cs
  30. +382 −378 { → Test}/Tests/SmartCache_Fixture.cs
  31. +113 −113 { → Test}/Tests/StringConverter/StringConverterPluginTest.cs
  32. +148 −148 { → Test}/Tests/StringConverter/StringConverterTest.cs
  33. +53 −53 { → Test}/Tests/StringExtensionsTest.cs
  34. +212 −200 { → Test}/Tests/Tokenizer_Fixture.cs
  35. +70 −70 { → Test}/Tests/TypeExtensionsTest.cs
  36. +167 −0 Test/Vici.Core.Metro.Test.csproj
  37. BIN Test/Vici.Core.Metro.Test/Images/UnitTestLogo.png
  38. BIN Test/Vici.Core.Metro.Test/Images/UnitTestSmallLogo.png
  39. BIN Test/Vici.Core.Metro.Test/Images/UnitTestSplashScreen.png
  40. BIN Test/Vici.Core.Metro.Test/Images/UnitTestStoreLogo.png
  41. +54 −0 Test/Vici.Core.Metro.Test/Package.appxmanifest
  42. +28 −0 Test/Vici.Core.Metro.Test/Properties/AssemblyInfo.cs
  43. +145 −0 Test/Vici.Core.Metro.Test/Vici.Core.Metro.Test.csproj
  44. BIN Test/Vici.Core.Metro.Test/Vici.Core.Metro.Test_TemporaryKey.pfx
  45. BIN Test/Vici.Core.Metro.Test_TemporaryKey.pfx
  46. +131 −131 {Tests → Test}/Vici.Core.Test.csproj
  47. +26 −0 Vici.Core.Metro.sln
View
1 .gitignore
@@ -2,6 +2,7 @@ bin
obj
Bin
Obj
+TestResults
*.user
*.suo
*.bak
View
65 Library/CoreExtensions.cs
@@ -64,11 +64,12 @@ public static void ForEach<T>(this IEnumerable<T> list, Action<T> action)
[Flags]
public enum BindingFlags
{
- Public,
- Static,
- Instance,
- DeclaredOnly,
- Default
+ Public = 16,
+ NonPublic = 32,
+ Static = 8,
+ Instance = 4,
+ DeclaredOnly = 2,
+ Default = 0
}
public class Binder
@@ -79,13 +80,65 @@ public class Binder
*/
public virtual MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
- return match.FirstOrDefault(method => LazyBinder.ParametersMatch(types, method.GetParameters()));
+ return BestMatch(match, types);
+ //return match.FirstOrDefault(method => LazyBinder.ParametersMatch(types, method.GetParameters()));
}
/*
public abstract PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers);
public abstract object ChangeType(object value, Type type, CultureInfo culture);
public abstract void ReorderArgumentArray(ref object[] args, object state);
*/
+
+
+ private enum ParameterCompareType
+ {
+ Exact,
+ Assignable,
+ Implicit
+ }
+
+ private class ParameterComparer : IEqualityComparer<Type>
+ {
+ private ParameterCompareType _compareType;
+
+ public ParameterComparer(ParameterCompareType compareType)
+ {
+ _compareType = compareType;
+ }
+
+ public bool Equals(Type x, Type y)
+ {
+ switch (_compareType)
+ {
+ case ParameterCompareType.Exact:
+ return x == y;
+ case ParameterCompareType.Assignable:
+ return y.GetTypeInfo().IsAssignableFrom(x.GetTypeInfo());
+ case ParameterCompareType.Implicit:
+ return y.Inspector().GetMethod("op_Implicit", new[] { x }) != null;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
+ public int GetHashCode(Type obj)
+ {
+ return obj.GetHashCode();
+ }
+ }
+
+
+ private bool IsMatch(Type[] parameterTypes, ParameterInfo[] parameters, ParameterCompareType compareType)
+ {
+ return parameterTypes.SequenceEqual(parameters.Select(p => p.ParameterType), new ParameterComparer(compareType));
+ }
+
+ internal MethodBase BestMatch(IEnumerable<MethodBase> methods, Type[] parameterTypes)
+ {
+ var compareTypes = new[] {ParameterCompareType.Exact, ParameterCompareType.Assignable, ParameterCompareType.Implicit};
+
+ return compareTypes.Select(compareType => methods.FirstOrDefault(m => IsMatch(parameterTypes, m.GetParameters(), compareType))).FirstOrDefault(match => match != null);
+ }
}
public class ParameterModifier
View
4 Library/EasyConfig/ConfigManager.cs
@@ -105,14 +105,14 @@ public bool Update()
private void Fill(Type type)
{
- ConfigKeyAttribute[] attributes = (ConfigKeyAttribute[]) type.Inspector().GetCustomAttributes(typeof (ConfigKeyAttribute), false);
+ ConfigKeyAttribute[] attributes = type.Inspector().GetCustomAttributes<ConfigKeyAttribute>(false);
Fill(type, null, attributes.Length > 0 ? attributes[0].BaseKey : null);
}
private void Fill(object obj)
{
- ConfigKeyAttribute[] attributes = (ConfigKeyAttribute[]) obj.GetType().Inspector().GetCustomAttributes(typeof (ConfigKeyAttribute), false);
+ ConfigKeyAttribute[] attributes = obj.GetType().Inspector().GetCustomAttributes<ConfigKeyAttribute>(false);
Fill(null, obj, attributes.Length > 0 ? attributes[0].BaseKey : null);
}
View
11 Library/MethodInspector.cs
@@ -18,7 +18,16 @@ public MethodInspector(MethodBase method)
public object Invoke(object o, object[] parameters)
{
#if NETFX_CORE
- return _m.Invoke(o, parameters);
+ var parameterTypes = _m.GetParameters();
+
+ object[] newParameters = new object[parameters.Length];
+
+ for (int i = 0; i < parameters.Length;i++ )
+ {
+ newParameters[i] = parameters[i].Convert(parameterTypes[i].ParameterType);
+ }
+
+ return _m.Invoke(o, newParameters);
#else
return _m.Invoke(o, BindingFlags.Default, LazyBinder.Default, parameters, null);
#endif
View
2 Library/Parser/ExpressionParser/Expression/IndexExpression.cs
@@ -91,7 +91,7 @@ public override ValueExpression Evaluate(IParserContext context)
}
else
{
- DefaultMemberAttribute[] att = (DefaultMemberAttribute[]) targetType.Inspector().GetCustomAttributes(typeof(DefaultMemberAttribute), true);
+ DefaultMemberAttribute[] att = targetType.Inspector().GetCustomAttributes<DefaultMemberAttribute>(true);
MethodInfo methodInfo = targetType.Inspector().GetPropertyGetter(att[0].MemberName, parameterTypes);
View
1 Library/Properties/AssemblyInfo.cs
@@ -13,5 +13,6 @@
[assembly: ComVisible(false)]
[assembly:InternalsVisibleTo("Vici.Core.Test")]
+[assembly: InternalsVisibleTo("Vici.Core.Metro.Test")]
[assembly: Guid("85cfa949-a3df-4f38-bb53-a2d992d0adc1")]
View
12 Library/SmartConverter/ObjectConverter.cs
@@ -41,14 +41,20 @@ public static object Convert(this object value, Type targetType)
if (value == null)
return targetType.Inspector().DefaultValue();
- if (value is string)
- return StringConverter.Convert((string) value, targetType);
-
Type type = targetType.Inspector().RealType;
if (value.GetType() == type)
return value;
+
+ var implicitOperator = type.Inspector().GetMethod("op_Implicit", new Type[] {value.GetType()});
+
+ if (implicitOperator != null)
+ return implicitOperator.Invoke(null, new object[] {value});
+
+ if (value is string)
+ return StringConverter.Convert((string) value, targetType);
+
if (type == typeof (Guid) && value is byte[])
return new Guid((byte[]) value);
View
23 Library/TypeInspector.cs
@@ -126,9 +126,7 @@ public MethodInfo GetMethod(string name, Type[] types)
public T GetAttribute<T>(bool inherit) where T : Attribute
{
- T[] attributes = (T[]) _t.GetTypeInfo().GetCustomAttributes(typeof(T), inherit).ToArray();
-
- return attributes.Length > 0 ? attributes[0] : null;
+ return _t.GetTypeInfo().GetCustomAttributes<T>(inherit).FirstOrDefault();
}
public T[] GetAttributes<T>(bool inherit) where T : Attribute
@@ -153,7 +151,7 @@ public ConstructorInfo[] GetConstructors()
public MemberInfo[] GetMember(string propertyName)
{
#if NETFX_CORE
- return WalkAndFindMultiple(t => t.GetTypeInfo().DeclaredMembers);
+ return WalkAndFindMultiple(t => t.GetTypeInfo().DeclaredMembers.Where(m => m.Name == propertyName));
#else
return _t.GetMember(propertyName);
#endif
@@ -168,12 +166,13 @@ public PropertyInfo GetIndexer(Type[] types)
#endif
}
- public object[] GetCustomAttributes(Type type, bool inherit)
+ public T[] GetCustomAttributes<T>(bool inherit) where T:Attribute
{
#if NETFX_CORE
- return _t.GetTypeInfo().GetCustomAttributes(type, inherit).ToArray();
+ var attributes = _t.GetTypeInfo().GetCustomAttributes<T>(inherit).ToArray();
+ return attributes;
#else
- return _t.GetCustomAttributes(type, inherit);
+ return (T[]) _t.GetCustomAttributes(type, inherit);
#endif
}
@@ -223,7 +222,9 @@ public bool ImplementsOrInherits<T>()
public MethodInfo GetMethod(string methodName, BindingFlags bindingFlags, Type[] parameterTypes, ParameterModifier[] modifiers)
{
#if NETFX_CORE
- return WalkAndFindSingle(t => t.GetTypeInfo().GetDeclaredMethods(methodName).FirstOrDefault(mi => LazyBinder.ParametersMatch(parameterTypes, mi.GetParameters())));
+ Binder binder = new Binder();
+
+ return (MethodInfo) WalkAndFindSingle(t => binder.BestMatch(t.GetTypeInfo().GetDeclaredMethods(methodName),parameterTypes));
#else
return _t.GetMethod(methodName, bindingFlags, LazyBinder.Default, parameterTypes, modifiers);
#endif
@@ -247,6 +248,12 @@ private bool MatchBindingFlags(FieldInfo fieldInfo, BindingFlags flags)
if ((flags & BindingFlags.Instance) == 0 && !fieldInfo.IsStatic)
return false;
+ if ((flags & BindingFlags.Public) != 0 && !fieldInfo.IsPublic)
+ return false;
+
+ if ((flags & BindingFlags.NonPublic) != 0 && !fieldInfo.IsPrivate)
+ return false;
+
return true;
}
View
1 Library/Vici.Core.Metro.csproj
@@ -131,7 +131,6 @@
<Compile Include="Scheduler\ScheduleWeekDays.cs" />
<Compile Include="Scheduler\TimeOfDayScheduler.cs" />
<Compile Include="SmartConverter\EnumConverter.cs" />
- <Compile Include="Tuple.cs" />
<Compile Include="EasyConfig\Attributes\ConfigIgnoreAttribute.cs" />
<Compile Include="EasyConfig\Attributes\ConfigKeyAttribute.cs" />
<Compile Include="EasyConfig\Attributes\ConfigObjectAttribute.cs" />
View
34 Tests/App.config → Test/App.config
@@ -1,18 +1,18 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<configuration>
- <appSettings>
- <add key="Test1" value="xx1" />
- <add key="SubObject1.TestInt1" value="99"/>
- <add key="StringValues.ValX" value="x"/>
- <add key="StringValues.ValY" value="y"/>
- <add key="StringValues.ValZ" value="z"/>
-
- <add key="IntValues.Val1" value="1"/>
- <add key="IntValues.Val2" value="2"/>
- <add key="IntValues.Val3" value="3"/>
-
- <add key="Cfg.Test1" value="xx2" />
- <add key="Cfg.SubObject1.TestInt1" value="88"/>
-
- </appSettings>
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="Test1" value="xx1" />
+ <add key="SubObject1.TestInt1" value="99"/>
+ <add key="StringValues.ValX" value="x"/>
+ <add key="StringValues.ValY" value="y"/>
+ <add key="StringValues.ValZ" value="z"/>
+
+ <add key="IntValues.Val1" value="1"/>
+ <add key="IntValues.Val2" value="2"/>
+ <add key="IntValues.Val3" value="3"/>
+
+ <add key="Cfg.Test1" value="xx2" />
+ <add key="Cfg.SubObject1.TestInt1" value="88"/>
+
+ </appSettings>
</configuration>
View
16 Tests/Config.xml → Test/Data/Config.xml
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<Config version="2">
- <Prop1>21</Prop1>
- <Prop2></Prop2>
- <SubGroupProp1>
- <SubProp2>22</SubProp2>
- <SubProp4>yeah</SubProp4>
- </SubGroupProp1>
+<?xml version="1.0" encoding="utf-8" ?>
+<Config version="2">
+ <Prop1>21</Prop1>
+ <Prop2></Prop2>
+ <SubGroupProp1>
+ <SubProp2>22</SubProp2>
+ <SubProp4>yeah</SubProp4>
+ </SubGroupProp1>
</Config>
View
BIN Test/Images/UnitTestLogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Test/Images/UnitTestSmallLogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Test/Images/UnitTestSplashScreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Test/Images/UnitTestStoreLogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
54 Test/Package.appxmanifest
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
+
+ <Identity Name="fbc6af52-ee3d-4935-9b82-cb4ee419fd4c"
+ Publisher="CN=Philippe"
+ Version="1.0.0.0" />
+
+ <Properties>
+ <DisplayName>Vici.Core.Metro.Test</DisplayName>
+ <PublisherDisplayName>Philippe</PublisherDisplayName>
+ <Logo>Images\UnitTestStoreLogo.png</Logo>
+ <Description>Vici.Core.Metro.Test</Description>
+ </Properties>
+
+ <Prerequisites>
+ <OSMinVersion>6.2</OSMinVersion>
+ <OSMaxVersionTested>6.2</OSMaxVersionTested>
+ </Prerequisites>
+
+ <Resources>
+ <Resource Language="x-generate"/>
+ </Resources>
+
+ <Applications>
+ <Application Id="vstest.executionengine.App"
+ Executable="vstest.executionengine.appcontainer.exe"
+ EntryPoint="vstest.executionengine.App">
+ <VisualElements
+ DisplayName="NoUIEntryPoints"
+ Logo="Images\UnitTestLogo.png"
+ SmallLogo="Images\UnitTestSmallLogo.png"
+ Description="vstest.executionengine.App"
+ ForegroundText="light"
+ BackgroundColor="#0084FF">
+ <SplashScreen Image="Images\UnitTestSplashScreen.png" />
+ </VisualElements>
+ </Application>
+
+ <Application Id="vstest.executionengine.x86.App"
+ Executable="vstest.executionengine.appcontainer.x86.exe"
+ EntryPoint="vstest.executionengine.x86.App">
+ <VisualElements
+ DisplayName="NoUIEntryPoints"
+ Logo="Images\UnitTestLogo.png"
+ SmallLogo="Images\UnitTestSmallLogo.png"
+ Description="vstest.executionengine.x86.App"
+ ForegroundText="light"
+ BackgroundColor="#0084FF">
+ <SplashScreen Image="Images\UnitTestSplashScreen.png" />
+ </VisualElements>
+ </Application>
+ </Applications>
+
+</Package>
View
72 Tests/Properties/AssemblyInfo.cs → Test/Properties/AssemblyInfo.cs
@@ -1,36 +1,36 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Tests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("Tests")]
-[assembly: AssemblyCopyright("Copyright © 2008-2012")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("9b681cdf-6645-4480-85ba-d57902ce0943")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Tests")]
+[assembly: AssemblyCopyright("Copyright © 2008-2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9b681cdf-6645-4480-85ba-d57902ce0943")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
113 Tests/BinaryExtensionsTest.cs → Test/Tests/BinaryExtensionsTest.cs
@@ -1,56 +1,57 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class BinaryExtensionsTest
- {
- [Test]
- public void ToHex()
- {
- byte[] bytes = new byte[] {0x12, 0xAB, 0xF1};
-
- Assert.AreEqual("12abf1", bytes.ToHex());
- Assert.AreEqual("12abf1", bytes.ToHex(false));
- Assert.AreEqual("12ABF1", bytes.ToHex(true));
- }
-
- [Test]
- public void BinarySerializerTest()
- {
- string x = "ABC";
-
- byte[] bytes = BinarySerializer.Serialize(x);
-
- Assert.AreEqual("ABC",BinarySerializer.Deserialize<string>(bytes));
- }
- }
-}
+#region License
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+
+namespace Vici.Core.Test
+{
+ [TestClass]
+ public class BinaryExtensionsTest
+ {
+ [TestMethod]
+ public void ToHex()
+ {
+ byte[] bytes = new byte[] {0x12, 0xAB, 0xF1};
+
+ Assert.AreEqual("12abf1", bytes.ToHex());
+ Assert.AreEqual("12abf1", bytes.ToHex(false));
+ Assert.AreEqual("12ABF1", bytes.ToHex(true));
+ }
+
+ [TestMethod]
+ public void BinarySerializerTest()
+ {
+ string x = "ABC";
+
+ byte[] bytes = BinarySerializer.Serialize(x);
+
+ Assert.AreEqual("ABC",BinarySerializer.Deserialize<string>(bytes));
+ }
+ }
+}
View
396 Tests/ConfigTest.cs → Test/Tests/ConfigTest.cs
@@ -1,199 +1,199 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System;
-using System.Collections.Generic;
-using NUnit.Framework;
-using Vici.Core.Config;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class ConfigTest
- {
- class StaticConfig
- {
- public static string Test1 { get; set; }
- public static ConfigurableClass1 SubObject1;
- public static Dictionary<string, string> StringValues;
- public static Dictionary<string, int> IntValues;
- }
-
- [ConfigKey("Cfg")]
- class StaticConfig2
- {
- public static string Test1;
- public static ConfigurableClass1 SubObject1;
- }
-
- class InstanceConfig
- {
- public string Test1;
- public ConfigurableClass1 SubObject1;
- public Dictionary<string, string> StringValues;
- public Dictionary<string, int> IntValues;
- }
-
- class ConfigurableClass1 : IConfigObject
- {
- public int TestInt1;
- }
-
- class InstanceXmlConfig
- {
- public int Prop1;
- public int Prop2;
- public InstanceXmlSubConfig SubGroupProp1;
- public Dictionary<string, string> StringValues;
- public Dictionary<string, int> IntValues;
- }
-
- class InstanceXmlSubConfig : IConfigObject
- {
- public string SubProp2;
- public string SubProp3 = "test";
- public string SubProp4 = "test";
- }
-
-
- [Test]
- public void TestStaticClassWithoutKey()
- {
- InstanceConfig config = new InstanceConfig();
-
- ConfigManager configManager = new ConfigManager();
-
- configManager.Register(config);
- configManager.Register<StaticConfig>();
- configManager.Register<StaticConfig2>();
-
- configManager.RegisterProvider(new ConfigurationProviderAppConfig());
- configManager.Update();
-
- Assert.AreEqual("xx1",StaticConfig.Test1);
- Assert.AreEqual(99, StaticConfig.SubObject1.TestInt1);
-
- Assert.AreEqual("xx2", StaticConfig2.Test1);
- Assert.AreEqual(88, StaticConfig2.SubObject1.TestInt1);
-
- Assert.AreEqual("xx1", config.Test1);
- Assert.AreEqual(99, config.SubObject1.TestInt1);
-
- Assert.IsNotNull(StaticConfig.IntValues);
- Assert.IsNotNull(StaticConfig.StringValues);
-
- Assert.AreEqual("x", StaticConfig.StringValues["ValX"]);
- Assert.AreEqual("y", StaticConfig.StringValues["ValY"]);
- Assert.AreEqual("z", StaticConfig.StringValues["ValZ"]);
-
- Assert.AreEqual(3, StaticConfig.StringValues.Count);
-
- Assert.AreEqual(1, StaticConfig.IntValues["Val1"]);
- Assert.AreEqual(2, StaticConfig.IntValues["Val2"]);
- Assert.AreEqual(3, StaticConfig.IntValues["Val3"]);
-
- Assert.AreEqual(3, StaticConfig.IntValues.Count);
- }
-
- [Test]
- public void TestStaticClassWithKey()
- {
- ConfigManager configManager = new ConfigManager();
-
- configManager.Register<StaticConfig2>();
- configManager.RegisterProvider(new ConfigurationProviderAppConfig());
- configManager.Update();
-
- Assert.AreEqual("xx2", StaticConfig2.Test1);
- Assert.AreEqual(88, StaticConfig2.SubObject1.TestInt1);
-
- }
-
- [Test]
- public void TestInstanceClassWithoutKey()
- {
- InstanceConfig config = new InstanceConfig();
-
- ConfigManager configManager = new ConfigManager();
-
- configManager.Register(config);
- configManager.RegisterProvider(new ConfigurationProviderAppConfig());
- configManager.Update();
-
- Assert.AreEqual("xx1", config.Test1);
- Assert.AreEqual(99, config.SubObject1.TestInt1);
-
- Assert.IsNotNull(config.IntValues);
- Assert.IsNotNull(config.StringValues);
-
- Assert.AreEqual("x", config.StringValues["ValX"]);
- Assert.AreEqual("y", config.StringValues["ValY"]);
- Assert.AreEqual("z", config.StringValues["ValZ"]);
-
- Assert.AreEqual(3, config.StringValues.Count);
-
- Assert.AreEqual(1, config.IntValues["Val1"]);
- Assert.AreEqual(2, config.IntValues["Val2"]);
- Assert.AreEqual(3, config.IntValues["Val3"]);
-
- Assert.AreEqual(3, config.IntValues.Count);
-
- }
-
- [Test]
- public void TestXmlConfigFile()
- {
- InstanceXmlConfig config = new InstanceXmlConfig();
-
- ConfigManager configManager = new ConfigManager();
-
- configManager.Register(config);
- configManager.RegisterProvider(new ConfigurationProviderXmlConfig(Environment.CurrentDirectory + "\\Config.xml"));
- configManager.Update();
-
- Assert.AreEqual(21, config.Prop1);
- Assert.AreEqual(0, config.Prop2);
- Assert.AreEqual("22", config.SubGroupProp1.SubProp2);
- Assert.AreEqual("test", config.SubGroupProp1.SubProp3);
- }
-
- [Test]
- public void TestDefaults()
- {
- InstanceXmlConfig config = new InstanceXmlConfig();
-
- ConfigManager configManager = new ConfigManager();
-
- configManager.Register(config);
- configManager.RegisterProvider(new ConfigurationProviderXmlConfig(Environment.CurrentDirectory + "\\Config.xml"));
- configManager.Update();
-
- Assert.AreEqual("test", config.SubGroupProp1.SubProp3);
- Assert.AreEqual("yeah", config.SubGroupProp1.SubProp4);
- }
-
- }
+#region License
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+#endregion
+
+using System;
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Vici.Core.Config;
+
+namespace Vici.Core.Test
+{
+ [TestClass]
+ public class ConfigTest
+ {
+ class StaticConfig
+ {
+ public static string Test1 { get; set; }
+ public static ConfigurableClass1 SubObject1;
+ public static Dictionary<string, string> StringValues;
+ public static Dictionary<string, int> IntValues;
+ }
+
+ [ConfigKey("Cfg")]
+ class StaticConfig2
+ {
+ public static string Test1;
+ public static ConfigurableClass1 SubObject1;
+ }
+
+ class InstanceConfig
+ {
+ public string Test1;
+ public ConfigurableClass1 SubObject1;
+ public Dictionary<string, string> StringValues;
+ public Dictionary<string, int> IntValues;
+ }
+
+ class ConfigurableClass1 : IConfigObject
+ {
+ public int TestInt1;
+ }
+
+ class InstanceXmlConfig
+ {
+ public int Prop1;
+ public int Prop2;
+ public InstanceXmlSubConfig SubGroupProp1;
+ public Dictionary<string, string> StringValues;
+ public Dictionary<string, int> IntValues;
+ }
+
+ class InstanceXmlSubConfig : IConfigObject
+ {
+ public string SubProp2;
+ public string SubProp3 = "test";
+ public string SubProp4 = "test";
+ }
+
+
+ [TestMethod]
+ public void TestStaticClassWithoutKey()
+ {
+ InstanceConfig config = new InstanceConfig();
+
+ ConfigManager configManager = new ConfigManager();
+
+ configManager.Register(config);
+ configManager.Register<StaticConfig>();
+ configManager.Register<StaticConfig2>();
+
+ configManager.RegisterProvider(new ConfigurationProviderAppConfig());
+ configManager.Update();
+
+ Assert.AreEqual("xx1",StaticConfig.Test1);
+ Assert.AreEqual(99, StaticConfig.SubObject1.TestInt1);
+
+ Assert.AreEqual("xx2", StaticConfig2.Test1);
+ Assert.AreEqual(88, StaticConfig2.SubObject1.TestInt1);
+
+ Assert.AreEqual("xx1", config.Test1);
+ Assert.AreEqual(99, config.SubObject1.TestInt1);
+
+ Assert.IsNotNull(StaticConfig.IntValues);
+ Assert.IsNotNull(StaticConfig.StringValues);
+
+ Assert.AreEqual("x", StaticConfig.StringValues["ValX"]);
+ Assert.AreEqual("y", StaticConfig.StringValues["ValY"]);
+ Assert.AreEqual("z", StaticConfig.StringValues["ValZ"]);
+
+ Assert.AreEqual(3, StaticConfig.StringValues.Count);
+
+ Assert.AreEqual(1, StaticConfig.IntValues["Val1"]);
+ Assert.AreEqual(2, StaticConfig.IntValues["Val2"]);
+ Assert.AreEqual(3, StaticConfig.IntValues["Val3"]);
+
+ Assert.AreEqual(3, StaticConfig.IntValues.Count);
+ }
+
+ [TestMethod]
+ public void TestStaticClassWithKey()
+ {
+ ConfigManager configManager = new ConfigManager();
+
+ configManager.Register<StaticConfig2>();
+ configManager.RegisterProvider(new ConfigurationProviderAppConfig());
+ configManager.Update();
+
+ Assert.AreEqual("xx2", StaticConfig2.Test1);
+ Assert.AreEqual(88, StaticConfig2.SubObject1.TestInt1);
+
+ }
+
+ [TestMethod]
+ public void TestInstanceClassWithoutKey()
+ {
+ InstanceConfig config = new InstanceConfig();
+
+ ConfigManager configManager = new ConfigManager();
+
+ configManager.Register(config);
+ configManager.RegisterProvider(new ConfigurationProviderAppConfig());
+ configManager.Update();
+
+ Assert.AreEqual("xx1", config.Test1);
+ Assert.AreEqual(99, config.SubObject1.TestInt1);
+
+ Assert.IsNotNull(config.IntValues);
+ Assert.IsNotNull(config.StringValues);
+
+ Assert.AreEqual("x", config.StringValues["ValX"]);
+ Assert.AreEqual("y", config.StringValues["ValY"]);
+ Assert.AreEqual("z", config.StringValues["ValZ"]);
+
+ Assert.AreEqual(3, config.StringValues.Count);
+
+ Assert.AreEqual(1, config.IntValues["Val1"]);
+ Assert.AreEqual(2, config.IntValues["Val2"]);
+ Assert.AreEqual(3, config.IntValues["Val3"]);
+
+ Assert.AreEqual(3, config.IntValues.Count);
+
+ }
+
+ [TestMethod]
+ public void TestXmlConfigFile()
+ {
+ InstanceXmlConfig config = new InstanceXmlConfig();
+
+ ConfigManager configManager = new ConfigManager();
+
+ configManager.Register(config);
+ configManager.RegisterProvider(new ConfigurationProviderXmlConfig(Environment.CurrentDirectory + "\\Config.xml"));
+ configManager.Update();
+
+ Assert.AreEqual(21, config.Prop1);
+ Assert.AreEqual(0, config.Prop2);
+ Assert.AreEqual("22", config.SubGroupProp1.SubProp2);
+ Assert.AreEqual("test", config.SubGroupProp1.SubProp3);
+ }
+
+ [TestMethod]
+ public void TestDefaults()
+ {
+ InstanceXmlConfig config = new InstanceXmlConfig();
+
+ ConfigManager configManager = new ConfigManager();
+
+ configManager.Register(config);
+ configManager.RegisterProvider(new ConfigurationProviderXmlConfig(Environment.CurrentDirectory + "\\Config.xml"));
+ configManager.Update();
+
+ Assert.AreEqual("test", config.SubGroupProp1.SubProp3);
+ Assert.AreEqual("yeah", config.SubGroupProp1.SubProp4);
+ }
+
+ }
}
View
290 Tests/DynamicObjectTest.cs → Test/Tests/DynamicObjectTest.cs
@@ -1,146 +1,146 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System;
-using NUnit.Framework;
-using Vici.Core.Parser;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class DynamicObjectTest
- {
- [Test]
- public void TestPropertyOfLinkedObject()
- {
- var obj = new {Test = "XXX"};
-
- DynamicObject viewData = new DynamicObject(obj);
-
- object value;
- Type type;
-
- Assert.AreEqual("XXX", viewData["Test"]);
- Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
-
- Assert.IsInstanceOfType(typeof(string),value);
- Assert.AreEqual(typeof(string), type);
- Assert.AreEqual("XXX",value);
-
- Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
-
- }
-
- [Test]
- public void TestPropertyOfMultipleLinkedObject()
- {
- var obj1 = new { Test = "XXX" };
- var obj2 = new { Value = 15.5m };
-
- DynamicObject viewData = new DynamicObject(obj1,obj2);
-
- object value;
- Type type;
-
- Assert.AreEqual("XXX", viewData["Test"]);
- Assert.AreEqual(15.5m, viewData["Value"]);
- Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
-
- Assert.IsInstanceOfType(typeof(string), value);
- Assert.AreEqual(typeof(string), type);
- Assert.AreEqual("XXX", value);
-
- Assert.IsTrue(viewData.TryGetValue("Value", out value, out type));
-
- Assert.IsInstanceOfType(typeof(decimal), value);
- Assert.AreEqual(typeof(decimal), type);
- Assert.AreEqual(15.5m, value);
-
- Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
- Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type));
-
- }
-
- [Test]
- public void TestPropertyOfDictionaryEntry()
- {
- DynamicObject viewData = new DynamicObject();
-
- viewData["Test"] = "XXX";
-
- object value;
- Type type;
-
- Assert.AreEqual("XXX", viewData["Test"]);
- Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
-
- Assert.IsInstanceOfType(typeof(string), value);
- Assert.AreEqual(typeof(string), type);
- Assert.AreEqual("XXX", value);
-
- Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
-
- }
-
- [Test]
- public void TestApply()
- {
- var obj1 = new { Test = "XXX" };
- var obj2 = new { Value = 15.5m };
-
- DynamicObject viewData1 = new DynamicObject(obj1);
- DynamicObject viewData2 = new DynamicObject(obj2);
-
- DynamicObject viewData = new DynamicObject();
-
- viewData.Apply(viewData1);
- viewData.Apply(viewData2);
-
- object value;
- Type type;
-
-
- Assert.AreEqual("XXX", viewData["Test"]);
- Assert.AreEqual(15.5m, viewData["Value"]);
- Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
-
- Assert.IsInstanceOfType(typeof(string), value);
- Assert.AreEqual(typeof(string), type);
- Assert.AreEqual("XXX", value);
-
- Assert.IsTrue(viewData.TryGetValue("Value", out value, out type));
-
- Assert.IsInstanceOfType(typeof(decimal), value);
- Assert.AreEqual(typeof(decimal), type);
- Assert.AreEqual(15.5m, value);
-
- Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
- Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type));
-
- }
-
- }
+#region License
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+#endregion
+
+using System;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Vici.Core.Parser;
+
+namespace Vici.Core.Test
+{
+ [TestClass]
+ public class DynamicObjectTest
+ {
+ [TestMethod]
+ public void TestPropertyOfLinkedObject()
+ {
+ var obj = new {Test = "XXX"};
+
+ DynamicObject viewData = new DynamicObject(obj);
+
+ object value;
+ Type type;
+
+ Assert.AreEqual("XXX", viewData["Test"]);
+ Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof(string));
+ Assert.AreEqual(typeof(string), type);
+ Assert.AreEqual("XXX",value);
+
+ Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
+
+ }
+
+ [TestMethod]
+ public void TestPropertyOfMultipleLinkedObject()
+ {
+ var obj1 = new { Test = "XXX" };
+ var obj2 = new { Value = 15.5m };
+
+ DynamicObject viewData = new DynamicObject(obj1,obj2);
+
+ object value;
+ Type type;
+
+ Assert.AreEqual("XXX", viewData["Test"]);
+ Assert.AreEqual(15.5m, viewData["Value"]);
+ Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof (string));
+ Assert.AreEqual(typeof(string), type);
+ Assert.AreEqual("XXX", value);
+
+ Assert.IsTrue(viewData.TryGetValue("Value", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof(decimal));
+ Assert.AreEqual(typeof(decimal), type);
+ Assert.AreEqual(15.5m, value);
+
+ Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
+ Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type));
+
+ }
+
+ [TestMethod]
+ public void TestPropertyOfDictionaryEntry()
+ {
+ DynamicObject viewData = new DynamicObject();
+
+ viewData["Test"] = "XXX";
+
+ object value;
+ Type type;
+
+ Assert.AreEqual("XXX", viewData["Test"]);
+ Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof(string));
+ Assert.AreEqual(typeof(string), type);
+ Assert.AreEqual("XXX", value);
+
+ Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
+
+ }
+
+ [TestMethod]
+ public void TestApply()
+ {
+ var obj1 = new { Test = "XXX" };
+ var obj2 = new { Value = 15.5m };
+
+ DynamicObject viewData1 = new DynamicObject(obj1);
+ DynamicObject viewData2 = new DynamicObject(obj2);
+
+ DynamicObject viewData = new DynamicObject();
+
+ viewData.Apply(viewData1);
+ viewData.Apply(viewData2);
+
+ object value;
+ Type type;
+
+
+ Assert.AreEqual("XXX", viewData["Test"]);
+ Assert.AreEqual(15.5m, viewData["Value"]);
+ Assert.IsTrue(viewData.TryGetValue("Test", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof(string));
+ Assert.AreEqual(typeof(string), type);
+ Assert.AreEqual("XXX", value);
+
+ Assert.IsTrue(viewData.TryGetValue("Value", out value, out type));
+
+ Assert.IsInstanceOfType(value, typeof(decimal));
+ Assert.AreEqual(typeof(decimal), type);
+ Assert.AreEqual(15.5m, value);
+
+ Assert.IsFalse(viewData.TryGetValue("Test2", out value, out type));
+ Assert.IsFalse(viewData.TryGetValue("Value2", out value, out type));
+
+ }
+
+ }
}
View
104 Tests/ExpressionWithContext.cs → Test/Tests/ExpressionWithContext.cs
@@ -1,53 +1,53 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System;
-using Vici.Core.Parser;
-
-namespace Vici.Core.Test
-{
- class ExpressionWithContext
- {
- public Expression Expression { get; set; }
- public IParserContext Context { get; set; }
-
- public ExpressionWithContext(IParserContext context)
- {
- Context = context;
- }
-
- public ExpressionWithContext(IParserContext context, Expression expr)
- {
- Context = context;
- Expression = expr;
- }
-
- public ValueExpression Evaluate()
- {
- return Expression.Evaluate(Context);
- }
- }
+#region License
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+#endregion
+
+using System;
+using Vici.Core.Parser;
+
+namespace Vici.Core.Test
+{
+ class ExpressionWithContext
+ {
+ public Expression Expression { get; set; }
+ public IParserContext Context { get; set; }
+
+ public ExpressionWithContext(IParserContext context)
+ {
+ Context = context;
+ }
+
+ public ExpressionWithContext(IParserContext context, Expression expr)
+ {
+ Context = context;
+ Expression = expr;
+ }
+
+ public ValueExpression Evaluate()
+ {
+ return Expression.Evaluate(Context);
+ }
+ }
}
View
366 Tests/Json/JSONParserFixture.cs → Test/Tests/Json/JSONParserFixture.cs
@@ -1,183 +1,183 @@
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-
-using System.Collections.Generic;
-using NUnit.Framework;
-using Vici.Core.Json;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class JSONParserFixture
- {
- private const string _json1 = @"
-{
- ""name"" :""John Doe"" ,
- ""salary"" : 4500.50
-}
-";
-
- private const string _json = @"
-{
- ""name"" :""John Doe"" ,
- ""salary"" : 4500.20 ,
- ""children"" : [ ""Sarah"", ""Jessica"" ]
-}
-";
-
- private const string _json2 = @"
-
-{
- ""glossary"": {
- ""title"": ""example glossary"",
- ""GlossDiv"": {
- ""title"": ""S"",
- ""GlossList"": {
- ""GlossEntry"": {
- ""ID"": ""SGML"",
- ""SortAs"": ""SGML"",
- ""GlossTerm"": ""Standard Generalized Markup Language"",
- ""Acronym"": ""SGML"",
- ""Abbrev"": ""ISO 8879:1986"",
- ""GlossDef"": {
- ""para"": ""A meta-markup language, used to create markup languages such as DocBook."",
- ""GlossSeeAlso"": [""GML"", ""XML""]
- },
- ""GlossSee"": ""markup""
- }
- }
- }
- }
-}
-";
-
- private const string _json3 = @"
-{""menu"": {
- ""header"": ""SVG Viewer"",
- ""items"": [
- {""id"": ""Open""},
- {""id"": ""OpenNew"", ""label"": ""Open New""},
- null,
- {""id"": ""ZoomIn"", ""label"": ""Zoom In""},
- {""id"": ""ZoomOut"", ""label"": ""Zoom Out""},
- {""id"": ""OriginalView"", ""label"": ""Original View""},
- null,
- {""id"": ""Quality""},
- {""id"": ""Pause""},
- {""id"": ""Mute""},
- null,
- {""id"": ""Find"", ""label"": ""Find...""},
- {""id"": ""FindAgain"", ""label"": ""Find Again""},
- {""id"": ""Copy""},
- {""id"": ""CopyAgain"", ""label"": ""Copy Again""},
- {""id"": ""CopySVG"", ""label"": ""Copy SVG""},
- {""id"": ""ViewSVG"", ""label"": ""View SVG""},
- {""id"": ""ViewSource"", ""label"": ""View Source""},
- {""id"": ""SaveAs"", ""label"": ""Save As""},
- null,
- {""id"": ""Help""},
- {""id"": ""About"", ""label"": ""About Adobe CVG Viewer...""}
- ]
-}}
-";
-
- private class Person
- {
- public string name;
- public decimal salary;
- public string[] children;
- }
-
- [Test]
- public void SimpleTypedObject()
- {
- JsonParser jsonParser = new JsonParser();
-
- Person person = jsonParser.Parse<Person>(_json);
-
- Assert.AreEqual("John Doe",person.name);
- Assert.AreEqual(4500.20,person.salary);
- Assert.AreEqual(2,person.children.Length);
- Assert.AreEqual("Sarah", person.children[0]);
- Assert.AreEqual("Jessica", person.children[1]);
- }
-
- [Test]
- public void ComplexDictionary()
- {
- JsonParser jsonParser = new JsonParser();
-
- object obj = jsonParser.Parse(_json3);
-
- Assert.IsInstanceOfType(typeof(Dictionary<string,object>),obj);
-
- Dictionary<string, object> dic = (Dictionary<string, object>) obj;
-
- Assert.AreEqual(1, dic.Count);
-
- Assert.IsInstanceOfType(typeof(Dictionary<string, object>), dic["menu"]);
-
- Assert.AreEqual(2, ((Dictionary<string, object>)dic["menu"]).Count);
-
- }
-
- [Test]
- public void EmptyArray()
- {
- JsonParser parser = new JsonParser();
-
- object items = ((Dictionary<string,object>) parser.Parse(@"{ ""array"" : [] }"))["array"];
-
- Assert.IsInstanceOfType(typeof(object[]),items);
- Assert.AreEqual(0,((object[])items).Length);
- }
-
- [Test]
- public void TestEscapes()
- {
- JsonParser parser = new JsonParser();
-
- object item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\n"" }"))["obj"];
-
- Assert.IsInstanceOfType(typeof(string), item);
- Assert.AreEqual("\n", item);
-
- item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\t"" }"))["obj"];
-
- Assert.IsInstanceOfType(typeof(string), item);
- Assert.AreEqual("\t", item);
-
- item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\\"" }"))["obj"];
-
- Assert.IsInstanceOfType(typeof(string), item);
- Assert.AreEqual(@"\", item);
-
- item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\u00aa"" }"))["obj"];
-
- Assert.IsInstanceOfType(typeof(string), item);
- Assert.AreEqual("\u00aa", item);
-
- }
- }
-}
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+
+using System.Collections.Generic;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Vici.Core.Json;
+
+namespace Vici.Core.Test
+{
+ [TestClass]
+ public class JSONParserFixture
+ {
+ private const string _json1 = @"
+{
+ ""name"" :""John Doe"" ,
+ ""salary"" : 4500.50
+}
+";
+
+ private const string _json = @"
+{
+ ""name"" :""John Doe"" ,
+ ""salary"" : 4500.20 ,
+ ""children"" : [ ""Sarah"", ""Jessica"" ]
+}
+";
+
+ private const string _json2 = @"
+
+{
+ ""glossary"": {
+ ""title"": ""example glossary"",
+ ""GlossDiv"": {
+ ""title"": ""S"",
+ ""GlossList"": {
+ ""GlossEntry"": {
+ ""ID"": ""SGML"",
+ ""SortAs"": ""SGML"",
+ ""GlossTerm"": ""Standard Generalized Markup Language"",
+ ""Acronym"": ""SGML"",
+ ""Abbrev"": ""ISO 8879:1986"",
+ ""GlossDef"": {
+ ""para"": ""A meta-markup language, used to create markup languages such as DocBook."",
+ ""GlossSeeAlso"": [""GML"", ""XML""]
+ },
+ ""GlossSee"": ""markup""
+ }
+ }
+ }
+ }
+}
+";
+
+ private const string _json3 = @"
+{""menu"": {
+ ""header"": ""SVG Viewer"",
+ ""items"": [
+ {""id"": ""Open""},
+ {""id"": ""OpenNew"", ""label"": ""Open New""},
+ null,
+ {""id"": ""ZoomIn"", ""label"": ""Zoom In""},
+ {""id"": ""ZoomOut"", ""label"": ""Zoom Out""},
+ {""id"": ""OriginalView"", ""label"": ""Original View""},
+ null,
+ {""id"": ""Quality""},
+ {""id"": ""Pause""},
+ {""id"": ""Mute""},
+ null,
+ {""id"": ""Find"", ""label"": ""Find...""},
+ {""id"": ""FindAgain"", ""label"": ""Find Again""},
+ {""id"": ""Copy""},
+ {""id"": ""CopyAgain"", ""label"": ""Copy Again""},
+ {""id"": ""CopySVG"", ""label"": ""Copy SVG""},
+ {""id"": ""ViewSVG"", ""label"": ""View SVG""},
+ {""id"": ""ViewSource"", ""label"": ""View Source""},
+ {""id"": ""SaveAs"", ""label"": ""Save As""},
+ null,
+ {""id"": ""Help""},
+ {""id"": ""About"", ""label"": ""About Adobe CVG Viewer...""}
+ ]
+}}
+";
+
+ private class Person
+ {
+ public string name;
+ public decimal salary;
+ public string[] children;
+ }
+
+ [TestMethod]
+ public void SimpleTypedObject()
+ {
+ JsonParser jsonParser = new JsonParser();
+
+ Person person = jsonParser.Parse<Person>(_json);
+
+ Assert.AreEqual("John Doe",person.name);
+ Assert.AreEqual(4500.20m,person.salary);
+ Assert.AreEqual(2,person.children.Length);
+ Assert.AreEqual("Sarah", person.children[0]);
+ Assert.AreEqual("Jessica", person.children[1]);
+ }
+
+ [TestMethod]
+ public void ComplexDictionary()
+ {
+ JsonParser jsonParser = new JsonParser();
+
+ object obj = jsonParser.Parse(_json3);
+
+ Assert.IsInstanceOfType(obj,typeof(Dictionary<string,object>));
+
+ Dictionary<string, object> dic = (Dictionary<string, object>) obj;
+
+ Assert.AreEqual(1, dic.Count);
+
+ Assert.IsInstanceOfType(dic["menu"], typeof(Dictionary<string, object>));
+
+ Assert.AreEqual(2, ((Dictionary<string, object>)dic["menu"]).Count);
+
+ }
+
+ [TestMethod]
+ public void EmptyArray()
+ {
+ JsonParser parser = new JsonParser();
+
+ object items = ((Dictionary<string,object>) parser.Parse(@"{ ""array"" : [] }"))["array"];
+
+ Assert.IsInstanceOfType(items,typeof(object[]));
+ Assert.AreEqual(0,((object[])items).Length);
+ }
+
+ [TestMethod]
+ public void TestEscapes()
+ {
+ JsonParser parser = new JsonParser();
+
+ object item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\n"" }"))["obj"];
+
+ Assert.IsInstanceOfType(item,typeof(string));
+ Assert.AreEqual("\n", item);
+
+ item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\t"" }"))["obj"];
+
+ Assert.IsInstanceOfType(item,typeof(string));
+ Assert.AreEqual("\t", item);
+
+ item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\\"" }"))["obj"];
+
+ Assert.IsInstanceOfType(item,typeof(string));
+ Assert.AreEqual(@"\", item);
+
+ item = ((Dictionary<string, object>)parser.Parse(@"{ ""obj"" : ""\u00aa"" }"))["obj"];
+
+ Assert.IsInstanceOfType(item,typeof(string));
+ Assert.AreEqual("\u00aa", item);
+
+ }
+ }
+}
View
362 Tests/Json/JsonSeralizerTestFixture.cs → Test/Tests/Json/JsonSeralizerTestFixture.cs
@@ -1,182 +1,182 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using Vici.Core.Json;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class JsonSeralizerTestFixture
- {
- [Test]
- public void TestArray()
- {
- string json = JsonSerializer.ToJson(new[] { 1, 2, 3 });
-
- Assert.AreEqual("[1,2,3]", json);
- }
-
- [Test]
- public void TestList()
- {
- string json = JsonSerializer.ToJson(new List<int>(new[] { 1, 2, 3 }));
-
- Assert.AreEqual("[1,2,3]", json);
- }
-
- [Test]
- public void TestInt()
- {
- Assert.AreEqual("123", JsonSerializer.ToJson(123));
- }
-
- [Test]
- public void TestSring()
- {
- Assert.AreEqual("\"abc\"", JsonSerializer.ToJson("abc"));
- }
-
- [Test]
- public void TestDouble()
- {
- Assert.AreEqual("12.34", JsonSerializer.ToJson(12.34));
- }
-
- [Test]
- public void TestBool()
- {
- Assert.AreEqual("true", JsonSerializer.ToJson(true));
- Assert.AreEqual("false", JsonSerializer.ToJson(false));
- }
-
- [Test]
- public void TestDictionary()
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
-
- dic["a"] = 1;
- dic["b"] = 2;
-
- Assert.AreEqual("{\"a\":1,\"b\":2}", JsonSerializer.ToJson(dic));
- }
-
- private class TestClass
- {
- public string field1 = "A";
- public int field2 = 123;
- public string field3 { get { return "B"; } }
- private string field4 = "C";
- }
-
- [Test]
- public void TestObject()
- {
- Assert.AreEqual("{\"field1\":\"A\",\"field2\":123,\"field3\":\"B\"}", JsonSerializer.ToJson(new TestClass()));
- }
-
- [Test]
- public void TestDate()
- {
- DateTime date = DateTime.Now;
-
- DateTime utcBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-
- long utcMs = (long)(date.ToUniversalTime() - utcBase).TotalMilliseconds;
-
- Assert.AreEqual("new Date(" + utcMs + ")", JsonSerializer.ToJson(date, JsonDateFormat.NewDate));
- Assert.AreEqual("\"Date(" + utcMs + ")\"", JsonSerializer.ToJson(date, JsonDateFormat.Date));
- Assert.AreEqual("\"/Date(" + utcMs + ")/\"", JsonSerializer.ToJson(date, JsonDateFormat.SlashDate));
- Assert.AreEqual("\"\\/Date(" + utcMs + ")\\/\"", JsonSerializer.ToJson(date, JsonDateFormat.EscapedSlashDate));
- Assert.AreEqual("\"" + date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") + "\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
-
-
- date = new DateTime(1999, 12, 1, 10, 0, 0, DateTimeKind.Utc);
-
- utcMs = (long)(date.ToUniversalTime() - utcBase).TotalMilliseconds;
-
- Assert.AreEqual("new Date(" + utcMs + ")", JsonSerializer.ToJson(date,JsonDateFormat.NewDate));
- Assert.AreEqual("\"1999-12-01T10:00:00Z\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
-
- date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-
- Assert.AreEqual("new Date(0)", JsonSerializer.ToJson(date,JsonDateFormat.NewDate));
- Assert.AreEqual("\"1970-01-01T00:00:00Z\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
- }
-
- [Test]
- public void TestNull()
- {
- Assert.AreEqual("null", JsonSerializer.ToJson(null));
- }
-
- [Test]
- public void TestChar()
- {
- Assert.AreEqual("\"x\"", JsonSerializer.ToJson('x'));
- }
-
- private enum TestEnumeration
- {
- FirstValue,
- SecondValue
- }
-
- [Test]
- public void TestEnum()
- {
- Assert.AreEqual("\"FirstValue\"", JsonSerializer.ToJson(TestEnumeration.FirstValue));
- Assert.AreEqual("\"SecondValue\"", JsonSerializer.ToJson(TestEnumeration.SecondValue));
- }
-
- private class TestClass2
- {
- public string Field1 = "abc";
- public int[] Field2 = new[] { 1, 2, 3 };
- }
-
- [Test]
- public void TestArrayInObject()
- {
- Assert.AreEqual("{\"Field1\":\"abc\",\"Field2\":[1,2,3]}", JsonSerializer.ToJson(new TestClass2()));
- }
-
- [Test]
- public void TestCircularReferences()
- {
- json_ParentClass obj1 = new json_ParentClass();
- json_ParentClass obj2 = new json_ParentClass();
-
- obj1.Id = "A";
- obj2.Id = "B";
-
- obj1.Children = new List<json_ChildClass>()
- {
- new json_ChildClass
- {
- Id = "A1",
- Parent = obj1,
- Others = new List<json_ParentClass>() { obj1,obj2 }
- }
- };
-
- string json = JsonSerializer.ToJson(obj1);
-
- Assert.AreEqual("{\"Id\":\"A\",\"Children\":[{\"Id\":\"A1\",\"Parent\":null,\"Others\":[null,{\"Id\":\"B\",\"Children\":null}]}]}",json);
-
- }
-
- private class json_ParentClass
- {
- public string Id;
- public List<json_ChildClass> Children;
- }
-
- private class json_ChildClass
- {
- public string Id;
- public json_ParentClass Parent;
- public List<json_ParentClass> Others;
- }
- }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Vici.Core.Json;
+
+namespace Vici.Core.Test
+{
+ [TestClass]
+ public class JsonSeralizerTestFixture
+ {
+ [TestMethod]
+ public void TestArray()
+ {
+ string json = JsonSerializer.ToJson(new[] { 1, 2, 3 });
+
+ Assert.AreEqual("[1,2,3]", json);
+ }
+
+ [TestMethod]
+ public void TestList()
+ {
+ string json = JsonSerializer.ToJson(new List<int>(new[] { 1, 2, 3 }));
+
+ Assert.AreEqual("[1,2,3]", json);
+ }
+
+ [TestMethod]
+ public void TestInt()
+ {
+ Assert.AreEqual("123", JsonSerializer.ToJson(123));
+ }
+
+ [TestMethod]
+ public void TestSring()
+ {
+ Assert.AreEqual("\"abc\"", JsonSerializer.ToJson("abc"));
+ }
+
+ [TestMethod]
+ public void TestDouble()
+ {
+ Assert.AreEqual("12.34", JsonSerializer.ToJson(12.34));
+ }
+
+ [TestMethod]
+ public void TestBool()
+ {
+ Assert.AreEqual("true", JsonSerializer.ToJson(true));
+ Assert.AreEqual("false", JsonSerializer.ToJson(false));
+ }
+
+ [TestMethod]
+ public void TestDictionary()
+ {
+ Dictionary<string, int> dic = new Dictionary<string, int>();
+
+ dic["a"] = 1;
+ dic["b"] = 2;
+
+ Assert.AreEqual("{\"a\":1,\"b\":2}", JsonSerializer.ToJson(dic));
+ }
+
+ private class TestClass
+ {
+ public string field1 = "A";
+ public int field2 = 123;
+ public string field3 { get { return "B"; } }
+ private string field4 = "C";
+ }
+
+ [TestMethod]
+ public void TestObject()
+ {
+ Assert.AreEqual("{\"field1\":\"A\",\"field2\":123,\"field3\":\"B\"}", JsonSerializer.ToJson(new TestClass()));
+ }
+
+ [TestMethod]
+ public void TestDate()
+ {
+ DateTime date = DateTime.Now;
+
+ DateTime utcBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+
+ long utcMs = (long)(date.ToUniversalTime() - utcBase).TotalMilliseconds;
+
+ Assert.AreEqual("new Date(" + utcMs + ")", JsonSerializer.ToJson(date, JsonDateFormat.NewDate));
+ Assert.AreEqual("\"Date(" + utcMs + ")\"", JsonSerializer.ToJson(date, JsonDateFormat.Date));
+ Assert.AreEqual("\"/Date(" + utcMs + ")/\"", JsonSerializer.ToJson(date, JsonDateFormat.SlashDate));
+ Assert.AreEqual("\"\\/Date(" + utcMs + ")\\/\"", JsonSerializer.ToJson(date, JsonDateFormat.EscapedSlashDate));
+ Assert.AreEqual("\"" + date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") + "\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
+
+
+ date = new DateTime(1999, 12, 1, 10, 0, 0, DateTimeKind.Utc);
+
+ utcMs = (long)(date.ToUniversalTime() - utcBase).TotalMilliseconds;
+
+ Assert.AreEqual("new Date(" + utcMs + ")", JsonSerializer.ToJson(date,JsonDateFormat.NewDate));
+ Assert.AreEqual("\"1999-12-01T10:00:00Z\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
+
+ date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+
+ Assert.AreEqual("new Date(0)", JsonSerializer.ToJson(date,JsonDateFormat.NewDate));
+ Assert.AreEqual("\"1970-01-01T00:00:00Z\"", JsonSerializer.ToJson(date, JsonDateFormat.UtcISO));
+ }
+
+ [TestMethod]
+ public void TestNull()
+ {
+ Assert.AreEqual("null", JsonSerializer.ToJson(null));
+ }
+
+ [TestMethod]
+ public void TestChar()
+ {
+ Assert.AreEqual("\"x\"", JsonSerializer.ToJson('x'));
+ }
+
+ private enum TestEnumeration
+ {
+ FirstValue,
+ SecondValue
+ }
+
+ [TestMethod]
+ public void TestEnum()
+ {
+ Assert.AreEqual("\"FirstValue\"", JsonSerializer.ToJson(TestEnumeration.FirstValue));
+ Assert.AreEqual("\"SecondValue\"", JsonSerializer.ToJson(TestEnumeration.SecondValue));
+ }
+
+ private class TestClass2
+ {
+ public string Field1 = "abc";
+ public int[] Field2 = new[] { 1, 2, 3 };
+ }
+
+ [TestMethod]
+ public void TestArrayInObject()
+ {
+ Assert.AreEqual("{\"Field1\":\"abc\",\"Field2\":[1,2,3]}", JsonSerializer.ToJson(new TestClass2()));
+ }
+
+ [TestMethod]
+ public void TestCircularReferences()
+ {
+ json_ParentClass obj1 = new json_ParentClass();
+ json_ParentClass obj2 = new json_ParentClass();
+
+ obj1.Id = "A";
+ obj2.Id = "B";
+
+ obj1.Children = new List<json_ChildClass>()
+ {
+ new json_ChildClass
+ {
+ Id = "A1",
+ Parent = obj1,
+ Others = new List<json_ParentClass>() { obj1,obj2 }
+ }
+ };
+
+ string json = JsonSerializer.ToJson(obj1);
+
+ Assert.AreEqual("{\"Id\":\"A\",\"Children\":[{\"Id\":\"A1\",\"Parent\":null,\"Others\":[null,{\"Id\":\"B\",\"Children\":null}]}]}",json);
+
+ }
+
+ private class json_ParentClass
+ {
+ public string Id;
+ public List<json_ChildClass> Children;
+ }
+
+ private class json_ChildClass
+ {
+ public string Id;
+ public json_ParentClass Parent;
+ public List<json_ParentClass> Others;
+ }
+ }
}
View
80 Tests/MockTimeProvider.cs → Test/Tests/MockTimeProvider.cs
@@ -1,41 +1,41 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System;
-
-namespace Vici.Core.Test
-{
- public class MockTimeProvider : ITimeProvider
- {
- private DateTime _dateTime = DateTime.Now;
-
- public DateTime Now
- {
- get { return _dateTime; }
- set { _dateTime = value; }
- }
- }
+#region License
+//=============================================================================
+// Vici Core - Productivity Library for .NET 3.5
+//
+// Copyright (c) 2008-2012 Philippe Leybaert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//=============================================================================
+#endregion
+
+using System;
+
+namespace Vici.Core.Test
+{
+ public class MockTimeProvider : ITimeProvider
+ {
+ private DateTime _dateTime = DateTime.Now;
+
+ public DateTime Now
+ {
+ get { return _dateTime; }
+ set { _dateTime = value; }
+ }
+ }
}
View
230 Tests/NotifierTest.cs → Test/Tests/NotifierTest.cs
@@ -1,116 +1,116 @@
-#region License
-//=============================================================================
-// Vici Core - Productivity Library for .NET 3.5
-//
-// Copyright (c) 2008-2012 Philippe Leybaert
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-// IN THE SOFTWARE.
-//=============================================================================
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using Vici.Core.Notifications;
-
-namespace Vici.Core.Test
-{
- [TestFixture]
- public class NotifierTest
- {
- private string _notificationResult;
-
- private Notifier CreateNotifierWithTypedSubscriptions()
- {
- _notificationResult = "";
-
- Notifier notifier = new Notifier();
-
- notifier.Subscribe(delegate(Notification<string> notification) { _notificationResult += notification.Payload + "A"; });
- notifier.Subscribe("x", delegate(Notificatio