У меня есть VS 2012, .NET 4.5 и модульный тестовый проект с 5 ссылками на службы для служб Wcf.
Эти службы Wcf реализуют контракты с тем же именем для контракта.
У меня есть 5 методов модульного тестирования. Код тот же, за исключением новой инструкции по созданию объекта (5 разных типов)
var svc = new SvcReferenceServiceOdpNet.ServiceOdpNetClient();
var svc = new SvcReferenceServiceOdpNetx86.ServiceOdpNetClient();
var svc = new SvcReferenceServiceOdpNet_IISHosted.ServiceOdpNetClient();
var svc = new SvcReferenceServiceOdpNetx64_IISHosted.ServiceOdpNetClient();
var svc = new SvcReferenceServiceOdpNet_IISHosted_Net40.ServiceOdpNetClient();
этот код является общим
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Метод GetTestOdpNetQuery с таким же названием, svc.GetTestOdpNetQuery, учитывая, что переменная svc соответствует одному из 5 различных типов.
Есть ли способ поделиться кодом и повторно использовать его, а также избежать дублирования кода?
[TestMethod]
public void Get_Data_de_OdpNet_con_service_AnyCPU()
{
var svc = new SvcReferenceServiceOdpNet.ServiceOdpNetClient();
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Assert.IsNotNull(res, "Null Value");
TestContext.WriteLine("Result: ");
TestContext.WriteLine(res);
Assert.IsFalse(res.StartsWith("ERROR"), "Error found ERROR");
}
[TestMethod]
public void Get_Data_de_OdpNet_con_service_x86()
{
var svc = new SvcReferenceServiceOdpNetx86.ServiceOdpNetClient();
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Assert.IsNotNull(res, "Null Value");
TestContext.WriteLine("Result: ");
TestContext.WriteLine(res);
Assert.IsFalse(res.StartsWith("ERROR"), "Error found ERROR");
}
[TestMethod]
public void Get_Data_de_OdpNet_con_service_AnyCPU_hosted_en_IIS()
{
var svc = new SvcReferenceServiceOdpNet_IISHosted.ServiceOdpNetClient();
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Assert.IsNotNull(res, "Null Value");
TestContext.WriteLine("Result: ");
TestContext.WriteLine(res);
Assert.IsFalse(res.StartsWith("ERROR"), "Error found ERROR");
}
[TestMethod]
public void Get_Data_de_OdpNet_con_service_x64_hosted_en_IIS()
{
var svc = new SvcReferenceServiceOdpNetx64_IISHosted.ServiceOdpNetClient();
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Assert.IsNotNull(res, "Null Value");
TestContext.WriteLine("Result: ");
TestContext.WriteLine(res);
Assert.IsFalse(res.StartsWith("ERROR"), "Error found ERROR");
}
[TestMethod]
public void Get_Data_de_OdpNet_con_service_AnyCPU_hosted_en_IIS_Net40()
{
var svc = new SvcReferenceServiceOdpNet_IISHosted_Net40.ServiceOdpNetClient();
var res = svc.GetTestOdpNetQuery(DataUtils.Select_Sysdate);
Assert.IsNotNull(res, "Null Value");
TestContext.WriteLine("Result: ");
TestContext.WriteLine(res);
Assert.IsFalse(res.StartsWith("ERROR"), "Error found ERROR");
}