你好,
我想创建将用作的自定义属性"TestMethod"属性和类方法中,而不是编写{TestMethod]-我想使用自定义AOP属性,但是我无法做到这一点,有人可以帮忙吗?
由于在MsTest V1中-我无法继承"TestMethod" due to it's sealed
我想创建将用作的自定义属性"TestMethod"属性和类方法中,而不是编写{TestMethod]-我想使用自定义AOP属性,但是我无法做到这一点,有人可以帮忙吗?
Custom Attribute:
namespace Framework.Attributes
{
/// <summary>
/// This attribute will handle the exception
/// </summary>
[Serializable]
public class HandleException : MethodInterceptionAspect
{
public string testName = string.Empty;
public override void OnInvoke(MethodInterceptionArgs args)
{
args.Proceed();
//if (args.Exception != null)
//{
// testName = GetTestName(args);
// var logger = GetLogger();
// logger.Info($"Application has got exception in method-{args.Method.Name}");
// logger.Error($"Exception : {(!string.IsNullOrEmpty(args.Exception.Message) ? args.Exception.Message : "")}");
// logger.Error($"Inner Exception : {(!string.IsNullOrEmpty(args.Exception.InnerException.Message) ? args.Exception.InnerException.Message : "")}");
//}
}
public ExtentTest GetLogger()
{
var report = ReportSingleton.GetInstance();
var loggers = LoggersSingltons.GetInstance();
var logger = loggers.Single(x => x.Model.Name == testName);
return logger;
}
}
}
Main Class Code:
public class Scenario1_3DProduct_EndToEnd : ManualRegressionSuite.Model.Abstractions.Test.TestBaseMSTestV2.TestBase
{
public CommonMethods CommonMethods { get; set; }
public string countryName = "Austria";
[TestInitialize]
public void BeforeTest()
{
BaseSetup();
CommonMethods = new CommonMethods(shared_parameters, _logger);
}
[TestCleanup]
public void AfterTest()
{
BaseCleanUp();
}
[TestCategory("BOL")]
//[TestMethod]
[HandleException]
public void BOL_GB_3D_Product_EndToEnd_Scenario1()
{
LineSeparatorHelper lineSeparator = GetInstance<LineSeparatorHelper>();
lineSeparator.LineFormatter("Executing 3D Product End to End Scenario for BOL");
lineSeparator.LineFormatter("Execution for 3D Product End to End Scenario BOL is completed");
}
}
由于在MsTest V1中-我无法继承"TestMethod" due to it's sealed