Ejemplo n.º 1
0
        public void Correctly_Extract_Objects()
        {
            var type = new ClrTypeBuilder()
                       .WithName("Duke")
                       .WithGetSize(42)
                       .Build();

            var obj = new ClrObjectBuilder()
                      .WithAddress(0x100)
                      .WithSize(42)
                      .WithType(type)
                      .Build();

            var heap = new ClrHeapBuilder()
                       .WithGetGeneration(1)
                       .WithGetObjectType(obj.Type)
                       .Build();

            var rt = new ClrRuntimeBuilder()
                     .WithHeap(heap)
                     .Build();



            // arrange
            var extractor = new DefaultObjectExtractor();

            // act
            var res  = extractor.Extract(obj, rt);
            var res2 = extractor.Extract(0x100, rt);

            // assert
            res.Address.Should().Be(0x100);
            res.Gen.Should().Be(1);
            res.Size.Should().Be(42);
            res.FullTypeName.Should().Be("Duke");

            res2.Address.Should().Be(0x100);
            res2.Gen.Should().Be(1);
            res2.Size.Should().Be(42);
            res2.FullTypeName.Should().Be("Duke");
        }
Ejemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            ModuleBuilder moduleBuilder   = ClrTypeBuilder.GetModuleBuilder();
            List <Type>   connectionTypes = new List <Type>();

            foreach (var connection in this.Connections)
            {
                var          connectionString = connection.Value;
                var          tables           = DbSchemaReader.GetSchemata(connectionString);
                List <Entry> entrys           = new List <Entry>();
                foreach (var table in tables)
                {
                    var modelType = moduleBuilder.CreateModelType(connection.Key, table);
                    entrys.Add(new Entry(modelType, table));
                }
                _entrys.Add(connection.Key, entrys);
                var dbcontextType = moduleBuilder.CreateDbContextType(connection.Key, entrys);
                Action <DbContextOptionsBuilder> optionsAction = options => options.UseSqlServer(connection.Value);
                MethodInfo addDbContextmethod =
                    typeof(EntityFrameworkServiceCollectionExtensions).
                    GetMethods(BindingFlags.Public | BindingFlags.Static).
                    FirstOrDefault(mi => mi.Name == "AddDbContext" && mi.GetGenericArguments().Count() == 1).
                    MakeGenericMethod(new Type[] { dbcontextType });
                addDbContextmethod.Invoke(null, new object[] { services, optionsAction, ServiceLifetime.Scoped, ServiceLifetime.Scoped });
                foreach (var entry in entrys)
                {
                    var controllerType = moduleBuilder.CreateControllerType(
                        connection.Key,
                        entry.Type,
                        dbcontextType);

                    connectionTypes.Add(controllerType);
                }
            }

            services.AddMvc().
            SetCompatibilityVersion(CompatibilityVersion.Version_2_1).
            ConfigureApplicationPartManager(p => p.FeatureProviders.Add(new EmitTypeControllerFeatureProvider(connectionTypes)));
            services.AddOData();
        }