Issue #AR-3_IEnumerable_support: added compound model regression tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Archetype.Umbraco.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
@@ -19,13 +20,7 @@ namespace Archetype.Tests.Serialization.Base
|
||||
var result = ConvertModelToArchetypeAndBack(model);
|
||||
|
||||
Assert.IsInstanceOf<T>(result);
|
||||
|
||||
foreach (var propInfo in model.GetSerialiazableProperties())
|
||||
{
|
||||
Assert.AreEqual(propInfo.GetValue(model, null),
|
||||
result.GetSerialiazableProperties().Single(pinfo => pinfo.Name.Equals(propInfo.Name))
|
||||
.GetValue(result, null));
|
||||
}
|
||||
AssertAreEqual(model, result);
|
||||
}
|
||||
|
||||
protected void SimpleModels_Regression_Battery<T>(T model)
|
||||
@@ -44,14 +39,49 @@ namespace Archetype.Tests.Serialization.Base
|
||||
foreach (var resultItem in result)
|
||||
{
|
||||
var index = result.IndexOf(resultItem);
|
||||
|
||||
foreach (var propInfo in model[index].GetSerialiazableProperties())
|
||||
{
|
||||
Assert.AreEqual(propInfo.GetValue(model[index], null),
|
||||
resultItem.GetSerialiazableProperties().Single(pinfo => pinfo.Name.Equals(propInfo.Name))
|
||||
.GetValue(resultItem, null));
|
||||
}
|
||||
AssertAreEqual(model[index], resultItem);
|
||||
}
|
||||
}
|
||||
|
||||
protected void CompoundModel_Regression_Battery<T>(T model)
|
||||
{
|
||||
Assert.IsNotNull(ConvertModelToArchetype(model));
|
||||
|
||||
var json = ConvertModelToArchetypeJson(model, Formatting.Indented);
|
||||
Assert.IsNotNullOrEmpty(json);
|
||||
|
||||
var result = ConvertModelToArchetypeAndBack(model);
|
||||
|
||||
Assert.IsInstanceOf<T>(result);
|
||||
AssertAreEqual(model, result);
|
||||
}
|
||||
|
||||
private static void AssertAreEqual<T>(T model, T result)
|
||||
{
|
||||
foreach (var propInfo in model.GetSerialiazableProperties())
|
||||
{
|
||||
if (!propInfo.PropertyType.Namespace.Equals("System"))
|
||||
{
|
||||
AssertAreEqual(GetExpectedValue(model, propInfo),
|
||||
GetActualValue(result, propInfo));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Assert.AreEqual(GetExpectedValue(model, propInfo),
|
||||
GetActualValue(result, propInfo));
|
||||
}
|
||||
}
|
||||
|
||||
private static object GetExpectedValue<T>(T expected, PropertyInfo propInfo)
|
||||
{
|
||||
return propInfo.GetValue(expected, null);
|
||||
}
|
||||
|
||||
private static object GetActualValue<T>(T actual, PropertyInfo propInfo)
|
||||
{
|
||||
return actual.GetSerialiazableProperties().Single(pinfo => pinfo.Name.Equals(propInfo.Name))
|
||||
.GetValue(actual, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,46 @@ namespace Archetype.Tests.Serialization.Regression
|
||||
SimpleModels_Regression_Battery(simpleModels);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimpleModelsWithFieldsets_Regression_Battery()
|
||||
{
|
||||
var simpleModels = _testHelper.GetModel<SimpleModelsWithFieldsets>();
|
||||
SimpleModels_Regression_Battery(simpleModels);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SimpleModelsWithMixedFieldsets_Regression_Battery()
|
||||
{
|
||||
var simpleModels = _testHelper.GetModel<SimpleModelsWithMixedFieldsets>();
|
||||
SimpleModels_Regression_Battery(simpleModels);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompoundModel_Regression_Battery()
|
||||
{
|
||||
var compoundModel = _testHelper.GetModel<CompoundModel>();
|
||||
CompoundModel_Regression_Battery(compoundModel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompoundModelWithMixedFieldsetVariant1_Regression_Battery()
|
||||
{
|
||||
var compoundModel = _testHelper.GetModel<CompoundModelWithMixedFieldsetVariant1>();
|
||||
CompoundModel_Regression_Battery(compoundModel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompoundModelWithMixedFieldsetVariant2_Regression_Battery()
|
||||
{
|
||||
var compoundModel = _testHelper.GetModel<CompoundModelWithMixedFieldsetVariant2>();
|
||||
CompoundModel_Regression_Battery(compoundModel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompoundModelWithFieldset_Regression_Battery()
|
||||
{
|
||||
var compoundModel = _testHelper.GetModel<CompoundModelWithFieldset>();
|
||||
CompoundModel_Regression_Battery(compoundModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,4 +81,81 @@ namespace Archetype.Tests.Serialization.Regression
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("simpleModels")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class SimpleModelsWithFieldsets : List<SimpleModelWithFieldsets>
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("simpleModels")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class SimpleModelsWithMixedFieldsets : List<SimpleModelWithMixedFieldsets>
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("compoundModel")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompoundModel
|
||||
{
|
||||
[JsonProperty("simpleModel")]
|
||||
public SimpleModel SimpleModel { get; set; }
|
||||
[JsonProperty("text")]
|
||||
public String Text { get; set; }
|
||||
[JsonProperty("integer")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("compoundModelWithMixedFieldset")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompoundModelWithMixedFieldsetVariant1
|
||||
{
|
||||
[AsFieldset]
|
||||
[JsonProperty("simpleModel")]
|
||||
public SimpleModel SimpleModel { get; set; }
|
||||
[JsonProperty("text")]
|
||||
public String Text { get; set; }
|
||||
[JsonProperty("integer")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("compoundModelWithMixedFieldset")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompoundModelWithMixedFieldsetVariant2
|
||||
{
|
||||
[JsonProperty("simpleModel")]
|
||||
public SimpleModel SimpleModel { get; set; }
|
||||
[AsFieldset]
|
||||
[JsonProperty("text")]
|
||||
public String Text { get; set; }
|
||||
[AsFieldset]
|
||||
[JsonProperty("integer")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("compoundModel")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompoundModelWithFieldset
|
||||
{
|
||||
[AsFieldset]
|
||||
[JsonProperty("simpleModel")]
|
||||
public SimpleModel SimpleModel { get; set; }
|
||||
[AsFieldset]
|
||||
[JsonProperty("text")]
|
||||
public String Text { get; set; }
|
||||
[AsFieldset]
|
||||
[JsonProperty("integer")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("compoundModelWithList")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompoundModelWithList
|
||||
{
|
||||
[JsonProperty("simpleModelList")]
|
||||
public List<SimpleModel> SimpleModelList { get; set; }
|
||||
[JsonProperty("text")]
|
||||
public String Text { get; set; }
|
||||
[JsonProperty("integer")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,5 +67,75 @@ namespace Archetype.Tests.Serialization.Regression
|
||||
GetSimpleModel()
|
||||
};
|
||||
}
|
||||
|
||||
public SimpleModelsWithFieldsets GetSimpleModelsWithFieldsets()
|
||||
{
|
||||
return new SimpleModelsWithFieldsets
|
||||
{
|
||||
GetSimpleModelWithFieldsets(),
|
||||
GetSimpleModelWithFieldsets(),
|
||||
GetSimpleModelWithFieldsets()
|
||||
};
|
||||
}
|
||||
|
||||
public SimpleModelsWithMixedFieldsets GetSimpleModelsWithMixedFieldsets()
|
||||
{
|
||||
return new SimpleModelsWithMixedFieldsets
|
||||
{
|
||||
GetSimpleModelWithMixedFieldsets(),
|
||||
GetSimpleModelWithMixedFieldsets(),
|
||||
GetSimpleModelWithMixedFieldsets()
|
||||
};
|
||||
}
|
||||
|
||||
public CompoundModel GetCompoundModel()
|
||||
{
|
||||
return new CompoundModel
|
||||
{
|
||||
Id = -1,
|
||||
SimpleModel = GetModel<SimpleModel>(),
|
||||
Text = typeof(CompoundModel).Name
|
||||
};
|
||||
}
|
||||
|
||||
public CompoundModelWithMixedFieldsetVariant1 GetCompoundModelWithMixedFieldsetVariant1()
|
||||
{
|
||||
return new CompoundModelWithMixedFieldsetVariant1
|
||||
{
|
||||
Id = -1,
|
||||
SimpleModel = GetModel<SimpleModel>(),
|
||||
Text = typeof(CompoundModelWithMixedFieldsetVariant1).Name
|
||||
};
|
||||
}
|
||||
|
||||
public CompoundModelWithMixedFieldsetVariant2 GetCompoundModelWithMixedFieldsetVariant2()
|
||||
{
|
||||
return new CompoundModelWithMixedFieldsetVariant2
|
||||
{
|
||||
Id = -1,
|
||||
SimpleModel = GetModel<SimpleModel>(),
|
||||
Text = typeof(CompoundModelWithMixedFieldsetVariant2).Name
|
||||
};
|
||||
}
|
||||
|
||||
public CompoundModelWithFieldset GetCompoundModelWithFieldset()
|
||||
{
|
||||
return new CompoundModelWithFieldset
|
||||
{
|
||||
Id = -1,
|
||||
SimpleModel = GetModel<SimpleModel>(),
|
||||
Text = typeof(CompoundModelWithFieldset).Name
|
||||
};
|
||||
}
|
||||
|
||||
public CompoundModelWithList GetCompoundModelWithList()
|
||||
{
|
||||
return new CompoundModelWithList
|
||||
{
|
||||
Id = -1,
|
||||
SimpleModelList = GetSimpleModels(),
|
||||
Text = typeof(CompoundModelWithList).Name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user