protected void AssertProducesNoError(Type systemType)
        {
            Assert.DoesNotThrow(() =>
            {
                var assemblyDefinition = AssemblyDefinitionFor(systemType);
                var testSystemType     = assemblyDefinition.MainModule
                                         .GetAllTypes()
                                         .Where(TypeDefinitionExtensions.IsComponentSystem)
                                         .FirstOrDefault(t => t.Name == systemType.Name);

                foreach (var methodToAnalyze in testSystemType.Methods.ToList())
                {
                    foreach (var forEachDescriptionConstruction in LambdaJobDescriptionConstruction.FindIn(methodToAnalyze))
                    {
                        LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction, null);
                    }
                }

                // Write out assembly to memory stream
                // Missing ImportReference errors for types only happens here.
                var pe  = new MemoryStream();
                var pdb = new MemoryStream();
                var writerParameters = new WriterParameters
                {
                    SymbolWriterProvider = new PortablePdbWriterProvider(), SymbolStream = pdb, WriteSymbols = true
                };
                assemblyDefinition.Write(pe, writerParameters);
            });
        }
        protected override void AssertProducesInternal(
            Type systemType,
            DiagnosticType type,
            string[] shouldContains,
            bool useFailResolver = false)
        {
            var methodToAnalyze    = MethodDefinitionForOnlyMethodOf(systemType);
            var diagnosticMessages = new List <DiagnosticMessage>();

            try
            {
                foreach (var forEachDescriptionConstruction in LambdaJobDescriptionConstruction.FindIn(methodToAnalyze))
                {
                    var(_, rewriteMessages) = LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction);
                    diagnosticMessages.AddRange(rewriteMessages);
                }
            }
            catch (FoundErrorInUserCodeException exc)
            {
                diagnosticMessages.AddRange(exc.DiagnosticMessages);
            }

            Assert.AreEqual(1, diagnosticMessages.Count);
            Assert.AreEqual(type, diagnosticMessages[0].DiagnosticType);

            foreach (var str in shouldContains)
            {
                Assert.That(diagnosticMessages[0].MessageData.Contains(str), $"Error message \"{diagnosticMessages[0].MessageData}\" does not contain \"{str}\".");
            }

            AssertDiagnosticHasSufficientFileAndLineInfo(diagnosticMessages);
        }
Beispiel #3
0
        void AssertProducesInternal(Type systemType, DiagnosticType type, string[] shouldContains)
        {
            var methodToAnalyze = MethodDefinitionForOnlyMethodOf(systemType);
            var errors          = new List <DiagnosticMessage>();

            try
            {
                foreach (var forEachDescriptionConstruction in LambdaJobDescriptionConstruction.FindIn(methodToAnalyze))
                {
                    LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction, errors);
                }
            }
            catch (FoundErrorInUserCodeException exc)
            {
                errors.AddRange(exc.DiagnosticMessages);
            }

            Assert.AreEqual(type, errors[0].DiagnosticType);
            string diagnostic = errors.Select(dm => dm.MessageData).SeparateByComma();

            foreach (var s in shouldContains)
            {
                StringAssert.Contains(s, diagnostic);
            }

            if (!diagnostic.Contains(".cs"))
            {
                Assert.Fail("Diagnostic message had no file info: " + diagnostic);
            }

            var match = Regex.Match(diagnostic, "\\.cs:?\\((?<line>.*?),(?<column>.*?)\\)");

            if (!match.Success)
            {
                Assert.Fail("Diagnostic message had no line info: " + diagnostic);
            }


            var line = int.Parse(match.Groups["line"].Value);

            if (line > 1000)
            {
                Assert.Fail("Unreasonable line number in errormessage: " + diagnostic);
            }
        }
        void AssertProducesInternal(Type systemType, DiagnosticType type, string[] shouldContains)
        {
            var methodToAnalyze = MethodDefinitionForOnlyMethodOf(systemType);
            var errors          = new List <DiagnosticMessage>();

            try
            {
                foreach (var forEachDescriptionConstruction in LambdaJobDescriptionConstruction.FindIn(methodToAnalyze))
                {
                    LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction, errors);
                }
            }
            catch (FoundErrorInUserCodeException exc)
            {
                errors.AddRange(exc.DiagnosticMessages);
            }

            Assert.AreEqual(type, errors[0].DiagnosticType);


            AssertDiagnosticHasSufficientFileAndLineInfo(errors);
        }
Beispiel #5
0
        protected void RunTest(Type type)
        {
            var methodToAnalyze = MethodDefinitionForOnlyMethodOf(type);
            var forEachDescriptionConstructions         = LambdaJobDescriptionConstruction.FindIn(methodToAnalyze);
            JobStructForLambdaJob jobStructForLambdaJob = null;

            foreach (var forEachDescriptionConstruction in forEachDescriptionConstructions)
            {
                jobStructForLambdaJob = LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction, null);
            }

            _methodIL = new StringBuilder();
            if (methodToAnalyze != null)
            {
                foreach (var instruction in methodToAnalyze.Body.Instructions)
                {
                    _methodIL.AppendLine(instruction.ToString());
                }
            }

            RunTest(jobStructForLambdaJob.TypeDefinition.DeclaringType);
        }
Beispiel #6
0
        protected void AssertProducesError(Type systemType, params string[] shouldContains)
        {
            var methodToAnalyze   = MethodDefinitionForOnlyMethodOf(systemType);
            var userCodeException = Assert.Throws <FoundErrorInUserCodeException>(() =>
            {
                foreach (var forEachDescriptionConstruction in LambdaJobDescriptionConstruction.FindIn(methodToAnalyze))
                {
                    LambdaJobsPostProcessor.Rewrite(methodToAnalyze, forEachDescriptionConstruction);
                }
            });

            foreach (var s in shouldContains)
            {
                StringAssert.Contains(s, userCodeException.ToString());
            }

            if (!userCodeException.ToString().Contains(".cs"))
            {
                Assert.Fail("Diagnostic message had no file info: " + userCodeException);
            }

            var match = Regex.Match(userCodeException.ToString(), "\\.cs:?\\((?<line>.*?),(?<column>.*?)\\)");

            if (!match.Success)
            {
                Assert.Fail("Diagnostic message had no line info: " + userCodeException);
            }


            var line = int.Parse(match.Groups["line"].Value);

            if (line > 1000)
            {
                Assert.Fail("Unreasonable line number in errormessage: " + userCodeException);
            }
        }