Example #1
0
        public void TestDataFromXls()
        {
            if (IntPtr.Size == 8)  // Test always fails in 64-bit; no JET engine
            {
                return;
            }

            MethodInfo      method = typeof(TestMethodCommandClass).GetMethod("TestViaXls");
            TheoryAttribute attr   = (TheoryAttribute)(method.GetCustomAttributes(typeof(TheoryAttribute), false))[0];

            List <ITestCommand> commands = new List <ITestCommand>(attr.CreateTestCommands(Reflector.Wrap(method)));

            Assert.Equal(2, commands.Count);
            TheoryCommand command1 = Assert.IsType <TheoryCommand>(commands[0]);

            Assert.Equal(3, command1.Parameters.Length);
            Assert.Equal <object>(1D, command1.Parameters[0]);
            Assert.Equal <object>("Foo", command1.Parameters[1]);
            Assert.Equal <object>("Bar", command1.Parameters[2]);
            TheoryCommand command2 = Assert.IsType <TheoryCommand>(commands[1]);

            Assert.Equal(3, command2.Parameters.Length);
            Assert.Equal <object>(14D, command2.Parameters[0]);
            Assert.Equal <object>("Biff", command2.Parameters[1]);
            Assert.Equal <object>("Baz", command2.Parameters[2]);
        }
Example #2
0
        public void TestDataFromOleDb()
        {
            if (IntPtr.Size == 8)  // Test always fails in 64-bit; no JET engine
            {
                return;
            }

            string currentDirectory = Directory.GetCurrentDirectory();

            try
            {
                string executable = Assembly.GetExecutingAssembly().GetLocalCodeBase();
                Directory.SetCurrentDirectory(Path.GetDirectoryName(executable));
                MethodInfo      method = typeof(TestMethodCommandClass).GetMethod("TestViaOleDb");
                TheoryAttribute attr   = (TheoryAttribute)(method.GetCustomAttributes(typeof(TheoryAttribute), false))[0];

                List <ITestCommand> commands = new List <ITestCommand>(attr.CreateTestCommands(Reflector.Wrap(method)));

                Assert.Equal(2, commands.Count);
                TheoryCommand command1 = Assert.IsType <TheoryCommand>(commands[0]);
                Assert.Equal(3, command1.Parameters.Length);
                Assert.Equal <object>(1D, command1.Parameters[0]);
                Assert.Equal <object>("Foo", command1.Parameters[1]);
                Assert.Equal <object>("Bar", command1.Parameters[2]);
                TheoryCommand command2 = Assert.IsType <TheoryCommand>(commands[1]);
                Assert.Equal(3, command2.Parameters.Length);
                Assert.Equal <object>(14D, command2.Parameters[0]);
                Assert.Equal <object>("Biff", command2.Parameters[1]);
                Assert.Equal <object>("Baz", command2.Parameters[2]);
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }
        }
Example #3
0
        public void TestDataFromOtherTypeProperty()
        {
            MethodInfo      method = typeof(TestMethodCommandClass).GetMethod("TestViaOtherTypeProperty");
            TheoryAttribute attr   = (TheoryAttribute)(method.GetCustomAttributes(typeof(TheoryAttribute), false))[0];

            List <ITestCommand> commands = new List <ITestCommand>(attr.CreateTestCommands(Reflector.Wrap(method)));

            ITestCommand  command       = Assert.Single(commands);
            TheoryCommand theoryCommand = Assert.IsType <TheoryCommand>(command);
            object        parameter     = Assert.Single(theoryCommand.Parameters);

            Assert.Equal(3, parameter);
        }
Example #4
0
        public static _IReflectionAttributeInfo TheoryAttribute(
            string?displayName = null,
            string?skip        = null,
            int timeout        = 0)
        {
            var attribute = new TheoryAttribute {
                DisplayName = displayName, Skip = skip, Timeout = timeout
            };

            var result = Substitute.For <_IReflectionAttributeInfo, InterfaceProxy <_IReflectionAttributeInfo> >();

            result.Attribute.Returns(attribute);
            result.GetNamedArgument <string>("DisplayName").Returns(displayName);
            result.GetNamedArgument <string>("Skip").Returns(skip);
            result.GetNamedArgument <int>("Timeout").Returns(timeout);
            return(result);
        }
Example #5
0
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: {0} <tests root path> <runtime path> <tests library path>", Path.GetFileName(Assembly.GetEntryAssembly().GetName().Name));
                return;
            }

            string       DeployPath      = Path.Combine(Path.GetFullPath(args[0]), "tests");
            string       runtimePath     = Path.GetFullPath(args[1]);
            string       dotnetTestsPath = Path.GetFullPath(args[2]);
            AssemblyName an       = new AssemblyName("DebuggerTest, Version=999.999.999.999, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            Assembly     assembly = null;

            try
            {
                assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(@"C:\dev\test\Debugger.Tests\dotnet\DebuggerTest.dll");
                //assembly = Assembly.Load(an);
            }
            catch (System.IO.FileNotFoundException)
            {
                string curAssemblyDir = Path.GetDirectoryName(new System.Uri(Assembly.GetEntryAssembly().CodeBase).AbsolutePath);
                Console.WriteLine("Error: can't find DebuggerTest.dll. Please put DebuggerTest.dll to {0}", curAssemblyDir);
                return;
            }

            var methods = assembly.GetTypes().SelectMany(t => t.GetMethods());

            foreach (var item in methods)
            {
                TheoryAttribute att = (TheoryAttribute)item.GetCustomAttribute(typeof(TheoryAttribute));
                if (att != null && att.Skip == null)
                {
                    string xunitTestMethodName = item.DeclaringType.FullName + '.' + item.Name;
                    string destDir             = Path.Combine(DeployPath, xunitTestMethodName);
                    Console.WriteLine(destDir);
                    if (!Directory.Exists(destDir))
                    {
                        Directory.CreateDirectory(destDir);
                    }

                    File.WriteAllText(Path.Combine(destDir, xunitTestMethodName + ".cmd"), string.Format(cmdTemplate, xunitTestMethodName, runtimePath, dotnetTestsPath));
                    File.WriteAllText(Path.Combine(destDir, xunitTestMethodName + ".sh"), string.Format(shTemplate, xunitTestMethodName, runtimePath, dotnetTestsPath));
                }
            }
        }
Example #6
0
        public void ResolvedGenericTypeIsIncludedInDisplayName()
        {
            MethodInfo      method = typeof(TestMethodCommandClass).GetMethod("GenericTest");
            TheoryAttribute attr   = (TheoryAttribute)(method.GetCustomAttributes(typeof(TheoryAttribute), false))[0];

            List <ITestCommand> commands = new List <ITestCommand>(attr.CreateTestCommands(Reflector.Wrap(method)));

            Assert.Equal(4, commands.Count);
            TheoryCommand command1 = Assert.IsType <TheoryCommand>(commands[0]);

            Assert.Equal(@"Xunit1.Extensions.TheoryAttributeTests+TestMethodCommandClass.GenericTest<Int32>(value: 42)", command1.DisplayName);
            TheoryCommand command2 = Assert.IsType <TheoryCommand>(commands[1]);

            Assert.Equal(@"Xunit1.Extensions.TheoryAttributeTests+TestMethodCommandClass.GenericTest<String>(value: ""Hello, world!"")", command2.DisplayName);
            TheoryCommand command3 = Assert.IsType <TheoryCommand>(commands[2]);

            Assert.Equal(@"Xunit1.Extensions.TheoryAttributeTests+TestMethodCommandClass.GenericTest<Int32[]>(value: System.Int32[])", command3.DisplayName);
            // TODO: Would like to see @"TheoryAttributeTests+TestMethodCommandClass.GenericTest<Int32[]>(value: Int32[] { 1, 2, 3 })"
            TheoryCommand command4 = Assert.IsType <TheoryCommand>(commands[3]);

            Assert.Equal(@"Xunit1.Extensions.TheoryAttributeTests+TestMethodCommandClass.GenericTest<List<String>>(value: System.Collections.Generic.List`1[System.String])", command4.DisplayName);
            // TODO: Would like to see @"TheoryAttributeTests+TestMethodCommandClass.GenericTest<List<String>>(value: List<String> { ""a"", ""b"", ""c"" })"
        }