I have to test the below generic method which is internal class of another assembly.
internal class JsonSerializationUtility
{
public static string SerializeJson<T>(T obj)
{
string jsonFormattedString = string.Empty;
try {
MemoryStream memStreamObj = new MemoryStream();
DataContractJsonSerializer jsonSerObj = new DataContractJsonSerializer(typeof(T));
jsonSerObj.WriteObject(memStreamObj, obj);
memStreamObj.Position = 0; StreamReader sr = new StreamReader(memStreamObj);
jsonFormattedString = sr.ReadToEnd();
}
catch (Exception ex) {
Log.Error("Exception details: ", ex);
}
return jsonFormattedString;
}
}
and i have tried in this way:
[TestMethod]
public void SerializeJson()
{
PrivateType privateObj = new PrivateType(typeof(JsonSerializationUtility));
string input= "WorldCup2015";
string output = privateObj.InvokeStatic("SerializeJson<objectType>", input).ToString();
Assert.IsNotNull(output);
}
But i am getting the missing method reference. Can anyone suggest how should have to test for Generic method.
I had done same procedure of writing test code for simple static method, but unable for generic method.
Aucun commentaire:
Enregistrer un commentaire