public static void SetupFactSkipIfAdmin(FactAttribute attribute) { if (!UserHelper.IsAdministrator() && Environment.GetEnvironmentVariable(EnableSkipVariableName) != null) { attribute.Skip = "Test will not run unless executed as Administrator"; } }
public void Attribute_Equal_Test() { var attribute1 = new FactAttribute() { Skip = "1" }; var attribute2 = new FactAttribute() { Skip = "1" }; var attribute3 = new FactAttribute(); var list = new List <object>() { attribute1 }; Assert.Contains(attribute2, list); Assert.DoesNotContain(attribute3, list); Assert.Equal(attribute1, attribute2); Assert.NotEqual(attribute3, attribute1); }
public static void SkipIfNoLocalRedis(FactAttribute fact) { try { TestRedisConfig.SkipLiveRedisBasedTests(); } catch (Exception ex) { fact.Skip = $"Skipped: {ex.Message}"; } }
public void FactAttributeGeneratesFactCommand() { MethodInfo method = typeof(FactAttributeTests).GetMethod("DummyFactMethod"); FactAttribute attribute = new FactAttribute(); List <ITestCommand> results = new List <ITestCommand>(attribute.CreateTestCommands(Reflector.Wrap(method))); ITestCommand result = Assert.Single(results); Assert.IsType <FactCommand>(result); }
public void NameOnFactAttributeOverridesDisplayName() { MethodInfo method = typeof(FactAttributeTests).GetMethod("CustomNamedFactMethod"); FactAttribute attrib = method.GetCustomAttributes(true).OfType <FactAttribute>().Single(); var commands = new List <ITestCommand>(attrib.CreateTestCommands(Reflector.Wrap(method))); ITestCommand command = Assert.Single(commands); FactCommand factCommand = Assert.IsType <FactCommand>(command); Assert.Equal("Custom display name", factCommand.DisplayName); }
private static bool IsStaTestAttribute(FactAttribute testAttribute) { var genericTestAttribute = testAttribute as GenericTheoryAttribute; if (genericTestAttribute != null) { return(genericTestAttribute.UseStaThread); } return(testAttribute is StaFactAttribute || testAttribute is StaTheoryAttribute); }
public void DefaultFactAttributeValues() { FactAttribute attrib = new FactAttribute(); MethodInfo method = typeof(FactAttributeTests).GetMethod("DummyFactMethod"); var commands = new List <ITestCommand>(attrib.CreateTestCommands(Reflector.Wrap(method))); ITestCommand command = Assert.Single(commands); FactCommand factCommand = Assert.IsType <FactCommand>(command); Assert.Equal("Xunit1.FactAttributeTests", factCommand.TypeName); Assert.Equal("DummyFactMethod", factCommand.MethodName); Assert.Equal("Xunit1.FactAttributeTests.DummyFactMethod", factCommand.DisplayName); }
public static void CheckForRequiredMSBuildVersion(FactAttribute attribute, string version) { if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) { attribute.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; return; } if (!Version.TryParse(version, out Version requiredVersion)) { attribute.Skip = $"Failed to determine the version required by this test ({ version })."; return; } if (requiredVersion > msbuildVersion) { attribute.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; } }
public void Intercept(IInvocation invocation) { MethodInfo methodInfo = invocation.MethodInvocationTarget; if (methodInfo == null) { methodInfo = invocation.Method; } FactAttribute transaction = methodInfo.GetCustomAttributes <FactAttribute>(true).FirstOrDefault(); if (transaction != null) { //开启事务 invocation.Proceed(); //提交事务 } else { // 没有事务时直接执行方法 invocation.Proceed(); } }
public Initialization(ILogger logger, FactAttribute skipOnLinuxEngine) { TestcontainersSettings.ResourceReaperEnabled = skipOnLinuxEngine.Skip != null; TestcontainersSettings.Logger = logger; }
public static void SkipInRelease(FactAttribute fact, string message) { #if !DEBUG fact.Skip = message; #endif }
public static void SkipInRelease(FactAttribute fact) => SkipInRelease(fact, "Only running in debug mode.");