Esempio n. 1
0
        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")
                                                   );
        }
Esempio n. 3
0
        public void CSharpStringCompiles()
        {
            Stream stream = GetCSharpSample();

            using (StreamReader sr = new StreamReader(stream))
            {
                CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd());
            }
        }
Esempio n. 4
0
        public void CSharpStringNotCompiles()
        {
            Stream stream = GetCSharpSample();

            using (StreamReader sr = new StreamReader(stream))
            {
                CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, sr.ReadToEnd() + "Make me fail...");
            }
        }
Esempio n. 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);
        }
Esempio n. 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());
            }
        }
Esempio n. 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());
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public void StreamNull()
        {
            Stream stream = null;

            CompilerAssert.Compiles(CompilerAssert.CSharpCompiler, stream);
        }
Esempio n. 11
0
        public void CSharpStreamNotCompilesFail()
        {
            Stream stream = GetCSharpBadSample();

            CompilerAssert.NotCompiles(CompilerAssert.CSharpCompiler, stream);
        }
Esempio n. 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'"));
 }
Esempio n. 14
0
        public void CompilerNull()
        {
            Stream stream = GetCSharpSample();

            CompilerAssert.Compiles(null, stream);
        }