예제 #1
0
 public static void SetupFactSkipIfAdmin(FactAttribute attribute)
 {
     if (!UserHelper.IsAdministrator() && Environment.GetEnvironmentVariable(EnableSkipVariableName) != null)
     {
         attribute.Skip = "Test will not run unless executed as Administrator";
     }
 }
예제 #2
0
파일: TempTests.cs 프로젝트: d18zj/qim
        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);
        }
예제 #3
0
 public static void SkipIfNoLocalRedis(FactAttribute fact)
 {
     try
     {
         TestRedisConfig.SkipLiveRedisBasedTests();
     }
     catch (Exception ex)
     {
         fact.Skip = $"Skipped: {ex.Message}";
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #7
0
        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 }).";
     }
 }
예제 #9
0
        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;
 }
예제 #11
0
 public static void SkipInRelease(FactAttribute fact, string message)
 {
     #if !DEBUG
     fact.Skip = message;
     #endif
 }
예제 #12
0
 public static void SkipInRelease(FactAttribute fact) =>
 SkipInRelease(fact, "Only running in debug mode.");