Exemple #1
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));
        }
Exemple #2
0
        public static void AddWithNullSyntax()
        {
            var compilationUnit = SyntaxFactory.ParseCompilationUnit("public static class Test { }", options: Shared.ParseOptions);
            var model           = StyleAggregatorTests.CreateModel(compilationUnit.SyntaxTree);
            var aggregator      = new StyleAggregator();

            Assert.That(() => aggregator.Add(null !, model), Throws.TypeOf <ArgumentNullException>());
        }
Exemple #3
0
        public static void VisitCSharpStyleExpressionBodiedIndexersStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	private int[] ages; 

	public int this[int i] => this.ages[i];
}", nameof(IStyleSet.CSharpStyleExpressionBodiedIndexersStyle));
Exemple #4
0
        public static void VisitDotnetStyleQualificationForFieldStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	private int x;

	public int Bar() => this.x;
}", nameof(IStyleSet.DotnetStyleQualificationForFieldStyle));
Exemple #5
0
        public static void VisitDotnetStyleQualificationForPropertyStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public int X { get; set; }

	public int Bar() => this.X;
}", nameof(IStyleSet.DotnetStyleQualificationForPropertyStyle));
Exemple #6
0
        public static void VisitCSharpStyleExpressionBodiedPropertiesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	private int age; 

	public int Age => age;
}", nameof(IStyleSet.CSharpStyleExpressionBodiedPropertiesStyle));
Exemple #7
0
        public static void VisitCSharpStyleExpressionBodiedConstructorsStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	private readonly int x; 
	
	public Foo() => this.x = 10;
}", nameof(IStyleSet.CSharpStyleExpressionBodiedConstructorsStyle));
Exemple #8
0
        public static void VisitCSharpStyleExpressionBodiedMethodsStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	public int Foo() 
	{ 
		return 10; 
	} 
}", nameof(IStyleSet.CSharpStyleExpressionBodiedMethodsStyle));
Exemple #9
0
        public static void VisitCSharpSpaceBetweenParenthesesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		for(var i = 0; i < 10; i++) { }
	}
}", nameof(IStyleSet.CSharpSpaceBetweenParenthesesStyle));
Exemple #10
0
        public static void VisitCSharpSpaceBetweenMethodCallParameterListParenthesesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar(int x) 
	{
		Bar( 3 );
	}
}", nameof(IStyleSet.CSharpSpaceBetweenMethodCallParameterListParenthesesStyle));
Exemple #11
0
        public static void VisitCSharpSpaceAfterKeywordsInControlFlowStatementsStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar(object x)
	{
		for (var i = 0; i < 10; i++) { }
	}
}", nameof(IStyleSet.CSharpSpaceAfterKeywordsInControlFlowStatementsStyle));
Exemple #12
0
        public static void VisitCSharpSpaceAfterCastStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar(object x)
	{
		var y = (int) x;
	}
}", nameof(IStyleSet.CSharpSpaceAfterCastStyle));
Exemple #13
0
        public static void VisitCSharpStyleExpressionBodiedOperatorsStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	public static Foo operator +(Foo f1, Foo f2) => f1.Data + 
		f2.Data;

	public int Data { get; } 
}", nameof(IStyleSet.CSharpStyleExpressionBodiedOperatorsStyle));
Exemple #14
0
        public static void VisitCSharpStylePatternLocalOverAnonymousFunctionStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		int X() => 22;
	}
}", nameof(IStyleSet.CSharpStylePatternLocalOverAnonymousFunctionStyle));
Exemple #15
0
        public static void VisitCSharpPreferSimpleDefaultExpressionStyleAsDefaultLiteral() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		string x = default;
	}
}", nameof(IStyleSet.CSharpPreferSimpleDefaultExpressionStyle));
Exemple #16
0
        public static void VisitForCSharpStyleVarForBuiltInTypesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public static class Test
{
	public static void Foo()
	{
		var a = 1;
	}
}", nameof(IStyleSet.CSharpStyleVarForBuiltInTypesStyle));
Exemple #17
0
        public static void VisitDotnetStyleQualificationForMethodStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	public void Bar()
	{
		this.Bar();
	}
}", nameof(IStyleSet.DotnetStyleQualificationForMethodStyle));
Exemple #18
0
        public static void VisitForCSharpStyleVarElsewhereStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public static class Test
{
	public static int Foo()
	{
		var x = Foo();
	}
}", nameof(IStyleSet.CSharpStyleVarElsewhereStyle));
Exemple #19
0
        public static void VisitCSharpStylePatternMatchingOverAsWithNullCheckStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar(object o)
	{
		if(o is string s) { }
	}
}", nameof(IStyleSet.CSharpStylePatternMatchingOverAsWithNullCheckStyle));
Exemple #20
0
        public static void VisitForCSharpNewLineBeforeMembersInAnonymousTypesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public static class Test
{
	public static void Foo()
	{
		var x = new { A = 1, B = 2 };
	}
}", nameof(IStyleSet.CSharpNewLineBeforeMembersInAnonymousTypesStyle));
Exemple #21
0
        public static void VisitDotnetStylePreferInferredAnonymousTypeMemberNamesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		var age = 42;
		var anon = new { age };
	}
}", nameof(IStyleSet.DotnetStylePreferInferredAnonymousTypeMemberNamesStyle));
Exemple #22
0
        public static void VisitForCSharpPreferBracesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		if(true)
			var x = 2;
	}
}", nameof(IStyleSet.CSharpPreferBracesStyle));
Exemple #23
0
        public static void VisitForCSharpNewLineBeforeCatchStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public static class Test
{
	public static void Foo()
	{
		try { }
		catch { }
	}
}", nameof(IStyleSet.CSharpNewLineBeforeCatchStyle));
Exemple #24
0
        public static void VisitForCSharpNewLineBeforeElseStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public static class Test
{
	public static void Foo()
	{
		if(true) { }
		else { }
	}
}", nameof(IStyleSet.CSharpNewLineBeforeElseStyle));
Exemple #25
0
        public static void VisitCSharpStyleVarWhenTypeIsApparentStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Customer { } 

public static class Test
{
	public static void Foo()
	{
		var customer = new Customer();
	}
}", nameof(IStyleSet.CSharpStyleVarWhenTypeIsApparentStyle));
Exemple #26
0
        public static void VisitDotnetStyleObjectInitializerStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Data { public int Value { get; set; } } 

public class Foo 
{ 
	public void Bar()
	{
		var x = new Data { Value = 22 };
	}
}", nameof(IStyleSet.DotnetStyleObjectInitializerStyle));
Exemple #27
0
        public static void VisitDotnetStyleQualificationForEventStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public event EventHandler DoIt;

	public void Bar()
	{
		this.DoIt += (a, b) => { };
	}
}", nameof(IStyleSet.DotnetStyleQualificationForEventStyle));
Exemple #28
0
        public static void VisitDotnetStylePreferInferredTupleNamesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		var age = 42;
		var name = ""Jane"";
		var tuple = (age, name);
	}
}", nameof(IStyleSet.DotnetStylePreferInferredTupleNamesStyle));
Exemple #29
0
        public static void VisitForCSharpNewLineBetweenQueryExpressionClausesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo
{
	public void Bar()
	{
		var x = new int[] { 1, 2, 3 };
		var q = from a in x
				  from b in x
				  select a * b;
	}
}", nameof(IStyleSet.CSharpNewLineBetweenQueryExpressionClausesStyle));
Exemple #30
0
        public static void VisitDotnetStyleExplicitTupleNamesStyle() =>
        StyleAggregatorTests.TestStyleVisitation(
            @"public class Foo 
{ 
	private int id;

	public void Bar()
	{
		(string name, int id) data = (""x"", 42);
		var x = data.Item1;
	}
}", nameof(IStyleSet.DotnetStyleExplicitTupleNamesStyle));