Exemple #1
0
 public FactDiscovererTests()
 {
     aggregator = new ExceptionAggregator();
     cancellationTokenSource = new CancellationTokenSource();
     factAttribute           = Mocks.FactAttribute();
     messageBus = new SpyMessageBus();
     options    = TestFrameworkOptions.ForDiscovery();
 }
        public static void Timeout()
        {
            var factAttribute = Mocks.FactAttribute(timeout: 42);
            var testMethod    = Mocks.TestMethod(methodAttributes: new[] { factAttribute });

            var testCase = new TestableXunitTestCase(testMethod);

            Assert.Equal(42, testCase.Timeout);
        }
        public static void SkipReason()
        {
            var factAttribute = Mocks.FactAttribute(skip: "Skip Reason");
            var testMethod    = Mocks.TestMethod(methodAttributes: new[] { factAttribute });

            var testCase = new TestableXunitTestCase(testMethod);

            Assert.Equal("Skip Reason", testCase.SkipReason);
        }
        public static void DisplayName()
        {
            var factAttribute = Mocks.FactAttribute(displayName: "Custom Display Name");
            var testMethod    = Mocks.TestMethod(methodAttributes: new[] { factAttribute });

            var testCase = new TestableXunitTestCase(testMethod);

            Assert.Equal("Custom Display Name", testCase.DisplayName);
        }
            public static TestableXunitTheoryTestCase Create(Action <IMessageBus> callback = null)
            {
                var fact     = Mocks.FactAttribute();
                var method   = Mocks.MethodInfo();
                var type     = Mocks.TypeInfo(methods: new[] { method });
                var assmInfo = Mocks.AssemblyInfo(types: new[] { type });

                return(new TestableXunitTheoryTestCase(assmInfo, type, method, fact, callback ?? (sink => sink.QueueMessage(new SpyMessage()))));
            }
        public static void DisplayNameWithArguments()
        {
            var factAttribute = Mocks.FactAttribute(displayName: "Custom Display Name");
            var param1        = Mocks.ParameterInfo("p1");
            var param2        = Mocks.ParameterInfo("p2");
            var param3        = Mocks.ParameterInfo("p3");
            var testMethod    = Mocks.TestMethod(methodAttributes: new[] { factAttribute }, parameters: new[] { param1, param2, param3 });
            var arguments     = new object[] { 42, "Hello, world!", 'A' };

            var testCase = new TestableXunitTestCase(testMethod, arguments);

            Assert.Equal("Custom Display Name(p1: 42, p2: \"Hello, world!\", p3: 'A')", testCase.DisplayName);
        }
Exemple #7
0
    public static ITestMethod TestMethod(string typeName    = "MockType",
                                         string methodName  = "MockMethod",
                                         string displayName = null,
                                         string skip        = null,
                                         IEnumerable <IParameterInfo> parameters = null,
                                         IEnumerable <IReflectionAttributeInfo> classAttributes  = null,
                                         IEnumerable <IReflectionAttributeInfo> methodAttributes = null)
    {
        if (classAttributes == null)
        {
            classAttributes = Enumerable.Empty <IReflectionAttributeInfo>();
        }
        if (methodAttributes == null)
        {
            methodAttributes = Enumerable.Empty <IReflectionAttributeInfo>();
        }
        if (parameters == null)
        {
            parameters = Enumerable.Empty <IParameterInfo>();
        }

        var factAttribute = methodAttributes.FirstOrDefault(attr => typeof(FactAttribute).IsAssignableFrom(attr.Attribute.GetType()));

        if (factAttribute == null)
        {
            factAttribute    = Mocks.FactAttribute(displayName, skip);
            methodAttributes = methodAttributes.Concat(new[] { factAttribute });
        }

        var testClass  = Mocks.TestClass(typeName, attributes: classAttributes.ToArray());
        var methodInfo = Mocks.MethodInfo(methodName, methodAttributes.ToArray(), parameters.ToArray(), testClass.Class);

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

        result.Method.Returns(methodInfo);
        result.TestClass.Returns(testClass);
        return(result);
    }