public void ShouldAnnonateImmutableTypes()
        {
            // arrange
            var builder = new CodeModelBuilder();

            builder.RegisterConventionsFrom(TestTarget.Conventions.Marker.Assembly);

            builder.Model.AddNode(new TypeNode(typeof (SetPropertyInCtor)));

            // act
            builder.RunMutator<AnnonateImmutableTypes>();

            // assert
            Assert.That(builder.Model, Graph.Has
                .NodeForType<SetPropertyInCtor>(Annonated.With<Immutable>()));
        }
        public void ExportToDgml()
        {
            var builder = new CodeModelBuilder();

            builder.RegisterConventionsFrom(typeof(TestTarget.Conventions.Marker).Assembly);

            builder.RunMutator(new AddAssemblies(typeof(Marker).Assembly));
            builder.RunMutator<AddTypes>();
            builder.RunMutator(new AddMethods(AddMethods.DefaultFlags | BindingFlags.NonPublic));
            builder.RunMutator<AddProperties>();
            builder.RunMutator<AddFields>();
            builder.RunMutator<DetectEntities>();
            builder.RunMutator<LinkMethodCalls>();
            builder.RunMutator<LinkFieldAccess>();
            builder.RunMutator<LinkPropertyAccess>();

            builder.RunMutator<DetectApplyEvent>();
            builder.RunMutator<DetectApplyEventMethods>();

            var exporter = new DgmlExporter
            {
                CategoryStyles =
                {
                    new CategoryStyle {Target = typeof (TypeNode), Background = "#999933"},
                    new CategoryStyle {Target = typeof (MethodNode), Background = "LightGreen"},
                    new CategoryStyle {Target = typeof (PropertyNode), Background = "Yellow"},
                    new CategoryStyle {Target = typeof (FieldNode), Background = "#993300"},
                    new CategoryStyle {Target = typeof (ApplyEventMethod), Background = "Red"},

                    new CategoryStyle {Target = typeof(ApplyEventLink), Stroke = "#FF11FFBB"}
                }
            };

            using (var output = File.Create(Path.Combine(TestContext.CurrentContext.WorkDirectory, "graph.dgml")))
            {
                exporter.Export(builder.Model, output);
            }
        }
Пример #3
0
        private CodeModelBuilder SetUpCodeModelBuilder()
        {
            var modelBuilder = new CodeModelBuilder();

            foreach (var assembly in this.config.ConventionAssemblies)
            {
                modelBuilder.RegisterConventionsFrom(Assembly.LoadFrom(assembly));
            }

            foreach (var assembly in this.config.AssembliesToAnalyze)
            {
                modelBuilder.RunMutator(new AddAssemblies(Assembly.LoadFrom(assembly)));
            }

            return modelBuilder;
        }