public void CompilerNull() { throw new AssertionException("Should Ignore"); Stream stream = GetCSharpSample(); CompilerAssert.Compiles(null, stream); }
[TestMethod]// [Ignore("WIP: Currently an error is not reported when one is expected.")] async public Task ReadOnlyMethod_ModifyObject_ErrorReported() { string thingCode = @" public struct Thing { public Thing(int number) { _Number = number; } int _Number; public int Number { readonly get { return _Number; } set { } } readonly public Thing Move(int number) { Number = 42; return new Thing( Number + number); } }"; await CompilerAssert.ExpectErrorsAsync(thingCode, new CompileError("CS1604", "Cannot assign to 'Number' because it is read-only") ); }
public void CSharpStringCompiles() { Stream stream = GetCSharpSample(); using (StreamReader sr = new StreamReader(stream)) { CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd()); } }
public void CSharpStringNotCompiles() { Stream stream = GetCSharpSample(); using (StreamReader sr = new StreamReader(stream)) { CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd() + "Make me fail..."); } }
public void CSharpStreamCompilerParametersNotCompiles() { Stream stream = GetCSharpBadSample(); CompilerParameters options; string[] assemblyNames = new string[] { "System.dll" }; options = new CompilerParameters(assemblyNames, "CSharpStreamCompilerParametersCompiles"); CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, options, stream); }
public void CSharpStringReferenceCollectionCompiles() { Stream stream = GetCSharpSample(); using (StreamReader sr = new StreamReader(stream)) { System.Collections.Specialized.StringCollection references = new System.Collections.Specialized.StringCollection(); references.Add("System.dll"); CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, references, sr.ReadToEnd()); } }
public void CSharpStringCompilerParametersNotCompiles() { Stream stream = GetCSharpBadSample(); using (StreamReader sr = new StreamReader(stream)) { CompilerParameters options; string[] assemblyNames = new string[] { "System.dll" }; options = new CompilerParameters(assemblyNames, "CSharpStringCompilerParametersCompiles"); CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, options, sr.ReadToEnd()); } }
public static Assembly CreateAssembly(string name) { ICodeCompiler compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler(); string source = LoadSource(name); CompilerParameters options = new CompilerParameters(); options.GenerateExecutable = false; options.GenerateInMemory = false; options.OutputAssembly = name + ".dll"; options.ReferencedAssemblies.Add("MbUnit.Framework.dll"); CompilerResults results = compiler.CompileAssemblyFromSource(options, source); if (results.Errors.HasErrors) { CompilerAssert.DisplayErrors(results, Console.Out); } Assert.IsFalse(results.Errors.HasErrors); return(results.CompiledAssembly); }
private static string CreateAssembly(string assemblyPath) { ICodeCompiler compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler(); string source = LoadSource(Path.GetFileNameWithoutExtension(assemblyPath)); CompilerParameters options = new CompilerParameters(); options.GenerateExecutable = false; options.GenerateInMemory = false; options.OutputAssembly = assemblyPath; options.ReferencedAssemblies.Add(Path.Combine(Path.GetDirectoryName(assemblyPath), "MbUnit.Framework.dll")); CompilerResults results = compiler.CompileAssemblyFromSource(options, source); if (results.Errors.HasErrors) { CompilerAssert.DisplayErrors(results, Console.Out); } Assert.IsFalse(results.Errors.HasErrors); return(results.PathToAssembly); }
public void StreamNull() { Stream stream = null; CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, stream); }
public void CSharpStreamNotCompilesFail() { Stream stream = GetCSharpBadSample(); CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, stream); }
public void CSharpStreamCompiles() { Stream stream = GetCSharpSample(); CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, stream); }
async public Task UnassignedVariableThrowsError() { CompileError[] compileErrors = await CompilerAssert.ExpectErrorsInFileAsync( "Listing03.02.DereferencingAnUnassignedVariable.cs", new CompileError("CS0165: Use of unassigned local variable 'text'")); }
public void CompilerNull() { Stream stream = GetCSharpSample(); CompilerAssert.Compiles(null, stream); }