Beispiel #1
0
        public static void AddWithNullModel()
        {
            var compilationUnit = SyntaxFactory.ParseCompilationUnit("public static class Test { }", options: Shared.ParseOptions);
            var aggregator      = new StyleAggregator();

            Assert.That(() => aggregator.Add(compilationUnit, null !), Throws.TypeOf <ArgumentNullException>());
        }
Beispiel #2
0
        public static void Add()
        {
            var aggregator1      = new StyleAggregator();
            var compilationUnit1 = SyntaxFactory.ParseCompilationUnit(
                @"public static class Test
{
	public static void VarFoo()
	{
		var a = 1;
	}
}", options: Shared.ParseOptions);

            aggregator1 = aggregator1.Add(compilationUnit1, StyleAggregatorTests.CreateModel(compilationUnit1.SyntaxTree));

            var aggregator2      = new StyleAggregator();
            var compilationUnit2 = SyntaxFactory.ParseCompilationUnit(
                @"public static class Test
{
	public static void TypeFoo()
	{
		int a = 1;
	}
}", options: Shared.ParseOptions);

            aggregator2 = aggregator2.Add(compilationUnit2, StyleAggregatorTests.CreateModel(compilationUnit2.SyntaxTree));

            var aggregator3 = aggregator1.Update(aggregator2);
            var data3       = aggregator3.Set.CSharpStyleVarForBuiltInTypesStyle.Data;

            Assert.That(data3.TotalOccurences, Is.EqualTo(2u), nameof(data3.TotalOccurences));
            Assert.That(data3.TrueOccurences, Is.EqualTo(1u), nameof(data3.TrueOccurences));
            Assert.That(data3.FalseOccurences, Is.EqualTo(1u), nameof(data3.FalseOccurences));
        }
Beispiel #3
0
        private static void TestStyleVisitation(string code, string stylePropertyName)
        {
            var aggregator        = new StyleAggregator();
            var setProperty       = aggregator.GetType().GetProperty(nameof(StyleAggregator.Set)) !;
            var styleProperty     = setProperty.PropertyType.GetProperty(stylePropertyName) !;
            var styleDataProperty = styleProperty.PropertyType.GetProperty("Data") !;
            var data = styleDataProperty.GetValue(styleProperty.GetValue(setProperty.GetValue(aggregator)));

            var compilationUnit = SyntaxFactory.ParseCompilationUnit(code, options: Shared.ParseOptions);

            aggregator = aggregator.Add(compilationUnit, StyleAggregatorTests.CreateModel(compilationUnit.SyntaxTree));
            var newData = styleDataProperty.GetValue(styleProperty.GetValue(setProperty.GetValue(aggregator)));

            Assert.That(newData, Is.Not.EqualTo(data));
        }