Sto imparando i test unitari in C #. Languages_Service
e PlaceOfWork_Service
sono classi per servizi SOAP generati da Microsoft Navision. Esistono diversi metodi molto simili (vedi i due esempi sotto).
[TestMethod]
public void Languages()
{
string serviceUrl = Helper.GetBaseUrl() + "Languages";
Languages_Service service = new Languages_Service();
service.Credentials = Helper.GetCredentials();
service.Url = serviceUrl;
Languages_Filter[] filter = { new Languages_Filter() };
service.ReadMultiple(filter, null, 0);
}
[TestMethod]
public void PlaceOfWork()
{
string serviceUrl = Helper.GetBaseUrl() + "PlaceOfWork";
PlaceOfWork_Service service = new PlaceOfWork_Service();
service.Credentials = Helper.GetCredentials();
service.Url = serviceUrl;
PlaceOfWork_Filter[] filter = { new PlaceOfWork_Filter() };
service.ReadMultiple(filter, null, 0);
}
Il metodo ReadMultiple di Language_Service ha il seguente aspetto:
public Languages[] ReadMultiple([System.Xml.Serialization.XmlElementAttribute("filter")] Languages_Filter[] filter, string bookmarkKey, int setSize)
{
object[] results = this.Invoke("ReadMultiple", new object[] {
filter,
bookmarkKey,
setSize});
return ((Languages[])(results[0]));}
Metodo ReadMultiple di PlaceOfWork_Service ha il seguente aspetto:
public PlaceOfWork[] ReadMultiple([System.Xml.Serialization.XmlElementAttribute("filter")] PlaceOfWork_Filter[] filter, string bookmarkKey, int setSize) {
object[] results = this.Invoke("ReadMultiple", new object[] {
filter,
bookmarkKey,
setSize});
return ((PlaceOfWork[])(results[0]));
}
Come si potrebbe scrivere qualcosa come il (pseudo) codice qui sotto?
[TestMethod]
public void GunAndSmokeTestAllSerivces()
{
Dictionary<String, List<Type>> servicesToTest = new Dictionary<String, List<Type>>();
servicesToTest.Add("Languages", new List<Type>(new Type[] { typeof(Languages_Service), typeof(Languages_Filter) }));
servicesToTest.Add("PlaceOfWork", new List<Type>(new Type[] { typeof(PlaceOfWork_Service), typeof(PlaceOfWork_Filter) }));
foreach (KeyValuePair<String, List<Type>> entry in servicesToTest)
{
var t1 = entry.Value.ToArray()[0];
var t2 = entry.Value.ToArray()[1];
SoapHttpClientProtocol service = (SoapHttpClientProtocol)Activator.CreateInstance(t1);
service.Credentials = Helper.GetCredentials();
service.Url = Helper.GetBaseUrl() + entry.Key;
object[] filter = { (object)Activator.CreateInstance(t2) };
service.ReadMultiple(filter, null, 0);
}
}
Languages_Service
e PlaceOfWork_Service
sono sottoclassi di System.Web.Services.Protocols.SoapHttpClientProtocol
.