private void TestInvalidTypes(InvalidTypeTestCase invalidType)
        {
            IEnumerable <VerificationResult> results = null;

            try
            {
                results = Verify(invalidType);
            }
            catch
            {
                //in some cases ILVerify throws exceptions when things look too wrong to continue
                //currently these are not caught. In tests we just catch these and do the asserts.
                //Once these exceptions are better handled and ILVerify instead of crashing aborts the verification
                //gracefully we can remove this empty catch block.
            }
            finally
            {
                Assert.NotNull(results);
                Assert.Equal(invalidType.ExpectedVerifierErrors.Count, results.Count());

                foreach (VerifierError item in invalidType.ExpectedVerifierErrors)
                {
                    IEnumerable <string> actual = results.Select(e => e.Code.ToString());
                    Assert.True(results.Where(r => r.Code == item).Count() > 0, $"Actual errors where: {string.Join(",", actual)}");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///  Returns all class doesn't correctly implement based on following naming convention
        ///  [FriendlyName]_InvalidType_[ExpectedVerifierError1]@[ExpectedVerifierError2]....[ExpectedVerifierErrorN]
        /// </summary>
        /// <returns></returns>
        public static TheoryData <TestCase> GetTypesWithInvalidType()
        {
            var typeSelector = new Func <string[], TypeDefinitionHandle, TestCase>((mparams, typeDefinitionHandle) =>
            {
                if (mparams[1] == "InvalidType")
                {
                    var verificationErros = new List <VerifierError>();
                    foreach (var expectedError in mparams[2].Split('@'))
                    {
                        verificationErros.Add((VerifierError)Enum.Parse(typeof(VerifierError), expectedError));
                    }
                    var newItem = new InvalidTypeTestCase {
                        MetadataToken = MetadataTokens.GetToken(typeDefinitionHandle)
                    };
                    newItem.ExpectedVerifierErrors = verificationErros;
                    return(newItem);
                }
                return(null);
            });

            return(GetTestTypeFromDll(typeSelector));
        }