|
using System;
using System.Runtime.Serialization;
using Apolyton.FastJson.Registry;
using Apolyton.FastJson.Tests.Helpers.Polymorphism;
using Apolyton.FastJson.Tests.Helpers.RegistryHelpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Apolyton.FastJson.Tests.Registry
{
[TestClass]
public class JsonRegistryTests
{
[TestMethod]
public void JsonRegistry_Constructor()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
}
[TestMethod]
public void JsonRegistry_GetPropertiesAndFields()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
registry.GetPropertiesAndFields(typeof(VisibilityScopeClass), null);
}
[TestMethod]
[ExpectedException(typeof(SerializationException))]
public void JsonRegistry_GetPropertiesAndFields_DuplicateName()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
registry.GetPropertiesAndFields(typeof(DuplicateMemberNameClass), null);
}
[TestMethod]
public void JsonRegistry_GetPropertiesAndFields_PublicGetSet()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
RegistrySection<String, JsonPropertyInfo> members = registry.GetPropertiesAndFields(typeof(VisibilityScopeClass), null);
Assert.IsTrue(members.ContainsKey("PublicGetSet"));
var member = members["PublicGetSet"];
Assert.IsNotNull(member.Getter);
Assert.IsNotNull(member.Setter);
}
[TestMethod]
public void JsonRegistry_GetPropertiesAndFields_NoGetPublicSet()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
RegistrySection<String, JsonPropertyInfo> members = registry.GetPropertiesAndFields(typeof(VisibilityScopeClass), null);
Assert.IsTrue(members.ContainsKey("NoGetPublicSet"));
var member = members["NoGetPublicSet"];
Assert.IsNull(member.Getter);
Assert.IsNotNull(member.Setter);
}
[TestMethod]
public void JsonRegistry_GetPropertiesAndFields_PublicGetInternalSet()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
RegistrySection<String, JsonPropertyInfo> members = registry.GetPropertiesAndFields(typeof(VisibilityScopeClass), null);
Assert.IsTrue(members.ContainsKey("PublicGetInternalSet"));
var member = members["PublicGetInternalSet"];
Assert.IsNotNull(member.Getter);
Assert.IsNull(member.Setter);
}
[TestMethod]
public void JsonRegistry_GetPropertiesAndFields_InternalGetSet()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
RegistrySection<String, JsonPropertyInfo> members = registry.GetPropertiesAndFields(typeof(VisibilityScopeClass), null);
Assert.IsFalse(members.ContainsKey("InternalGetSet"));
}
[TestMethod]
[ExpectedException(typeof(SerializationException))]
public void JsonRegistry_CreateInstanceFast_NoDefaultConstructor()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
registry.CreateInstanceFast(typeof(ClassWithoutDefaultConstructor));
}
[TestMethod]
[ExpectedException(typeof(SerializationException))]
public void JsonRegistry_CreateInstanceFast_AbstractClass()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
registry.CreateInstanceFast(typeof(Animal));
}
[TestMethod]
[ExpectedException(typeof(SerializationException))]
public void JsonRegistry_CreateInstanceFast_NonPublicClass()
{
JsonRegistry registry = new JsonRegistry(new JsonParameters());
registry.CreateInstanceFast(typeof(NonPublicClass));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.