Beispiel #1
0
        public static DirectoryTypeScanner CreateDefaultDirectoryTypeScanner()
        {
            var tempDirectoryPath =
                Path.Combine(Path.GetTempPath(),
                             Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            var directory =
                Directory.CreateDirectory(tempDirectoryPath);

            for (var i = 0; i < 2; i++)
            {
                var assemblyName =
                    Path.Combine(directory.FullName,
                                 string.Concat(Path.GetFileNameWithoutExtension(Path.GetRandomFileName()), ".dll"));

                var results =
                    CSharpAssemblyFactory.Compile(
                        @"
                        public class Foo { }
                        class Bar { }
                        public interface IFoo { }
                        interface IBar { }
                        public abstract class Baz { }
                    ", assemblyName);
            }

            return(new DirectoryTypeScanner(tempDirectoryPath));
        }
Beispiel #2
0
        public AssemblyWrapper Build(string code)
        {
            var builtAssembly =
                CSharpAssemblyFactory.Compile(code, this.GenerateTemporaryAssemblyName());

            this.Assemblies.Add(new AssemblyWrapper(builtAssembly));

            return(this.Assemblies.Last());
        }
        public void Compile_should_return_instance_of_assembly()
        {
            var results =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo
                        {
                        }
                    ");

            Assert.NotNull(results);
        }
        public void Compile_should_return_assembly_with_one_public_type()
        {
            var results =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo
                        {
                        }
                    ");

            Assert.AreEqual(1, results.GetExportedTypes().Length);
        }
Beispiel #5
0
        public void Ctor_should_store_assembly_reference_in_assembly_property()
        {
            var assembly =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo
                        {
                        }
                    ");

            var scanner =
                new AssemblyTypeScanner(assembly);

            scanner.Assembly.ShouldBeSameAs(assembly);
        }
Beispiel #6
0
        public void GetTypes_should_only_return_class_types()
        {
            var assembly =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo { }
                        public struct Bar { }
                    ");

            var scanner =
                new AssemblyTypeScanner(assembly);

            var types =
                scanner.GetTypes(x => true);

            types.Count().ShouldEqual(1);
        }
Beispiel #7
0
        public void GetTypes_should_return_all_types_in_assembly_that_matches_predicate()
        {
            var assembly =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo { }
                        public class Bar { }
                    ");

            var scanner =
                new AssemblyTypeScanner(assembly);

            var types =
                scanner.GetTypes(x => x.Name.Equals("Bar"));

            types.Count().ShouldEqual(1);
        }
Beispiel #8
0
        public void AddTypes_should_extract_types_from_function()
        {
            var assembly =
                CSharpAssemblyFactory.Compile(
                    @"
                        public class Foo { }
                        public class Bar { }
                    ");

            var scanner =
                CreateDefaultTypeScanner();

            scanner.AddTypes(() => assembly.GetExportedTypes().ToList());

            var types =
                scanner.GetTypes(t => true);

            types.Count().ShouldEqual(2);
        }