Cześć, mam problem z konwersją JSONa do stringa.
JSON ma następującą strukturę:
{
"UserConfig": {
"UserName": "user",
"Password": "password",
"WebsiteURL": "https://www.google.com/"
}
}
Zrobiłem już klasę User:
public class UserConfig
{
[JsonProperty("UserName")]
public string UserName { get; set; }
[JsonProperty("Password")]
public string Password { get; set; }
[JsonProperty("WebsiteURL")]
public string WebsiteURL { get; set; }
}
public class User
{
[JsonProperty("UserConfig")]
public UserConfig UserConfig { get; set; }
}
Teraz mam kolejną klasę która ma pobrać tego JSONa do var'a na podstawie podanego Patha do configa (domyślnie, będzie kilka UserConfigów używanych w projekcie - testy automatyczne)
public class UserConfigReader
{
public static void JsonLoad(string UserConfigPath)
{
using (StreamReader r = new StreamReader(UserConfigPath))
{
string result = string.Empty;
var json = r.ReadToEnd();
var configObj = JsonConvert.DeserializeObject<User>(json);
}
}
}
I teraz chciałbym configObj pobrać w kolejnej klasie testu jednostkowego, który by sprawdzał na podstawie
UserConfigPath
czy dane zostały prawidłowo wczytane do zmiennych typu string
string UserName
string Password
string WebsideURL