private static TestCaseData PostconditionCase(string typeName, string attributeName, bool isValid) { return(new TestCaseData( CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers( SourceCodeFactory.PostconditionMethod(typeName, attributeName))), isValid) .SetName($"{fixture}{attributeName}_ReturnTypes_{typeName}{(isValid ? "Passes" : "Fails")}")); }
private static TestCaseData IteratorBlockCase(string attributeName, bool isValid) { return(new TestCaseData( CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers( $"[return: {attributeName}] IEnumerable<int> TestMethod() {{ yield return 1; }}")), isValid) .SetName($"{fixture}NoPostconditions_{attributeName}")); }
private static TestCaseData PreconditionTestCase(string attributeName, bool isValid) { return(new TestCaseData( CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers( $"extern void TestMethod([{attributeName}] int param1);")), isValid) .SetName($"{fixture}NoContracts_{attributeName}_Precondition")); }
private static TestCaseData PostconditionTestCase(string attributeName, bool isValid) { return(new TestCaseData( CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers(new[] { "partial" }, $"[return: {attributeName}] partial int TestMethod();")), isValid) .SetName($"{fixture}NoContracts_{attributeName}_Postcondition")); }
private static TestCaseData VoidPostconditionTestCase(string attributeName, bool isValid) { return(new TestCaseData( CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers( SourceCodeFactory.PostconditionMethod("void", attributeName))), isValid) .SetName($"{fixture}NoPostconditions_{attributeName}")); }
public void PreconditionTest(string code) { //Arrange var compilation = CompilationFactory.CompileClassFromText( SourceCodeFactory.ClassWithMembers(code)); //Act var diagnostics = TestHelper.GetDiagnostics(compilation); Assert.IsTrue(diagnostics.Any(d => d.GetMessage().StartsWith("Expanded"))); Assert.IsTrue(diagnostics.ContainsOnlyCode(RewriteConfirmed)); }