コード例 #1
0
        public void CompilerNull()
        {
            throw new AssertionException("Should Ignore");
            Stream stream = GetCSharpSample();

            CompilerAssert.Compiles(null, stream);
        }
コード例 #2
0
        [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")
                                                   );
        }
コード例 #3
0
        public void CSharpStringCompiles()
        {
            Stream stream = GetCSharpSample();

            using (StreamReader sr = new StreamReader(stream))
            {
                CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd());
            }
        }
コード例 #4
0
        public void CSharpStringNotCompiles()
        {
            Stream stream = GetCSharpSample();

            using (StreamReader sr = new StreamReader(stream))
            {
                CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd() + "Make me fail...");
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
            }
        }
コード例 #7
0
        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());
            }
        }
コード例 #8
0
ファイル: AssemblyCompiler.cs プロジェクト: tmauldin/mb-unit
        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);
        }
コード例 #9
0
ファイル: AssemblyCompiler.cs プロジェクト: tmauldin/mb-unit
        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);
        }
コード例 #10
0
        public void StreamNull()
        {
            Stream stream = null;

            CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, stream);
        }
コード例 #11
0
        public void CSharpStreamNotCompilesFail()
        {
            Stream stream = GetCSharpBadSample();

            CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, stream);
        }
コード例 #12
0
        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'"));
 }
コード例 #14
0
        public void CompilerNull()
        {
            Stream stream = GetCSharpSample();

            CompilerAssert.Compiles(null, stream);
        }