Exemple #1
0
            public void ReturnsDefaultValueWhenValueIsNotSet()
            {
                var attributeData = CustomAttributeData.GetCustomAttributes(typeof(ClassWithoutAttributeValue)).Single(cad => cad.AttributeType == typeof(AttributeUnderTest));
                var attributeInfo = new ReflectionAttributeInfo(attributeData);

                var result = attributeInfo.GetNamedArgument <int>("IntValue");

                Assert.Equal(0, result);
            }
        public void ReturnsDefaultValueWhenValueIsNotSet()
        {
            var attributeData = CustomAttributeData.GetCustomAttributes(typeof(ClassWithoutAttributeValue)).Single(cad => cad.AttributeType == typeof(AttributeUnderTest));
            var attributeInfo = new ReflectionAttributeInfo(attributeData);

            var result = attributeInfo.GetNamedArgument<int>("IntValue");

            Assert.Equal(0, result);
        }
Exemple #3
0
            public void Throws()
            {
                var attributeData = CustomAttributeData.GetCustomAttributes(typeof(ClassWithAttribute)).Single(cad => cad.AttributeType == typeof(AttributeUnderTest));
                var attributeInfo = new ReflectionAttributeInfo(attributeData);

                var ex = Record.Exception(() => attributeInfo.GetNamedArgument <int>("IntValue"));

                var argEx = Assert.IsType <ArgumentException>(ex);

                Assert.StartsWith("Could not find property or field named 'IntValue' on instance of 'ReflectionAttributeInfoTests+GetNamedArgument+NamedValueDoesNotExist+AttributeUnderTest'", argEx.Message);
                Assert.Equal("argumentName", argEx.ParamName);
            }
            public void GivenWithValuesIsPresentWhenEnumerationIsEnabledThenReturnsMultipleTestCases()
            {
                var methodInfo = typeof(Fake).GetMethod("FakeTest");
                var customAttributes = CustomAttributeData.GetCustomAttributes(methodInfo);
                _testMethodMock.Setup(x => x.Method).Returns(new ReflectionMethodInfo(methodInfo));
                _discoveryOptionsMock.Setup(x => x.GetValue<bool?>("xunit.discovery.PreEnumerateTheories")).Returns(true);

                IEnumerable<IXunitTestCase> results = new List<IXunitTestCase>();

                var xunitAttribute = new ReflectionAttributeInfo(customAttributes.Single(x => x.AttributeType == typeof(UnitAttribute)));
                results = _testAttributesDiscoverer.Discover(_discoveryOptionsMock.Object, _testMethodMock.Object, xunitAttribute);

                Assert.True(results.Count() == customAttributes.Count(x => x.AttributeType == typeof(WithValuesAttribute)));

                foreach (var result in results)
                {
                    Assert.IsType<XunitTestCase>(result);
                    Assert.True(result.TestMethodArguments.Count() == 3);
                }
            }