mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
Implement attribute builders
Add attributes to class, constructor, field, method and property
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Macocian Alexandru Victor
|
||||
Copyright (c) 2024 Macocian Alexandru Victor
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,3 +1,84 @@
|
||||
# Sybil
|
||||
|
||||
C# Syntax builders following builder pattern
|
||||
|
||||
## Usage
|
||||
|
||||
Sybil supports building of namespaces with classes, constructors, parameters, properties, fields and methods.
|
||||
Example of creating a namespace with one class with one constructor and base class, multiple fields, properties and methods:
|
||||
```C#
|
||||
var namespaceSyntax = SyntaxBuilder.CreateNamespace("TestNamespace")
|
||||
.WithUsing("System")
|
||||
.WithClass(
|
||||
SyntaxBuilder.CreateClass("TestClass")
|
||||
.WithBaseClass("BaseTestClass")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute")
|
||||
.WithArgument("SomeIntProperty", 1)
|
||||
.WithArgument("SomeStringProperty", "Hello")
|
||||
.WithArgument("SomeEnumProperty", MyEnum.Value)
|
||||
.WithArgument("SomeTypeProperty", typeof(string))
|
||||
.WithNullArgument("SomeNullProperty"))
|
||||
.WithModifiers("public sealed")
|
||||
.WithConstructor(
|
||||
SyntaxBuilder.CreateConstructor("TestClass")
|
||||
.WithBase(
|
||||
SyntaxBuilder.CreateBaseConstructor()
|
||||
.WithArgument("fieldString"))
|
||||
.WithAttribute(
|
||||
SyntaxBuilder.CreateAttribute("SomeAttribute5")
|
||||
.WithNullArgument())
|
||||
.WithParameter("string", "fieldString")
|
||||
.WithBody("this.fieldString = fieldString ?? throw new ArgumentNullException();"))
|
||||
.WithField(
|
||||
SyntaxBuilder.CreateField("string", "fieldString")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute2"))
|
||||
.WithModifier("private"))
|
||||
.WithProperty(
|
||||
SyntaxBuilder.CreateProperty("string", "PropertyString")
|
||||
.WithModifier("public")
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateSetter()
|
||||
.WithModifier("private"))
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateGetter())
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute3")
|
||||
.WithArgument(typeof(string))))
|
||||
.WithMethod(
|
||||
SyntaxBuilder.CreateMethod("string", "GetFieldString")
|
||||
.WithModifier("public")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute4")
|
||||
.WithArgument(0.5f))
|
||||
.WithBody("return this.fieldString;")))
|
||||
.Build();
|
||||
|
||||
var namespaceString = namespaceSyntax.ToFullString();
|
||||
```
|
||||
|
||||
This generates the following syntax:
|
||||
```C#
|
||||
namespace TestNamespace
|
||||
{
|
||||
using System;
|
||||
|
||||
[SomeAttribute(SomeIntProperty = 1, SomeStringProperty = "Hello", SomeEnumProperty = MyEnum.Value, SomeTypeProperty = typeof(String), SomeNullProperty = null)]
|
||||
public sealed class TestClass : BaseTestClass
|
||||
{
|
||||
[SomeAttribute5(null)]
|
||||
TestClass(string fieldString) : base(fieldString)
|
||||
{
|
||||
this.fieldString = fieldString ?? throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
[SomeAttribute2]
|
||||
private string fieldString;
|
||||
[SomeAttribute3(typeof(String))]
|
||||
public string PropertyString { private set; get; }
|
||||
|
||||
[SomeAttribute4(0.5F)]
|
||||
public string GetFieldString()
|
||||
{
|
||||
return this.fieldString;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1,26 +1,32 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Sybil.IntegrationTests.Models;
|
||||
|
||||
namespace Sybil.IntegrationTests
|
||||
namespace Sybil.IntegrationTests;
|
||||
|
||||
[TestClass]
|
||||
public sealed class FlowTests
|
||||
{
|
||||
[TestClass]
|
||||
public sealed class FlowTests
|
||||
{
|
||||
private const string ExpectedNamespace =
|
||||
private const string ExpectedNamespace =
|
||||
@"namespace TestNamespace
|
||||
{
|
||||
using System;
|
||||
|
||||
[SomeAttribute(SomeIntProperty = 1, SomeStringProperty = ""Hello"", SomeEnumProperty = MyEnum.Value, SomeTypeProperty = typeof(String), SomeNullProperty = null)]
|
||||
public sealed class TestClass : BaseTestClass
|
||||
{
|
||||
[SomeAttribute5(null)]
|
||||
TestClass(string fieldString) : base(fieldString)
|
||||
{
|
||||
this.fieldString = fieldString ?? throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
[SomeAttribute2]
|
||||
private string fieldString;
|
||||
[SomeAttribute3(typeof(String))]
|
||||
public string PropertyString { private set; get; }
|
||||
|
||||
[SomeAttribute4(0.5F)]
|
||||
public string GetFieldString()
|
||||
{
|
||||
return this.fieldString;
|
||||
@@ -28,41 +34,54 @@ namespace Sybil.IntegrationTests
|
||||
}
|
||||
}";
|
||||
|
||||
[TestMethod]
|
||||
public void NewNamespace_GeneratesExpected()
|
||||
{
|
||||
var namespaceSyntax = SyntaxBuilder.CreateNamespace("TestNamespace")
|
||||
.WithUsing("System")
|
||||
.WithClass(
|
||||
SyntaxBuilder.CreateClass("TestClass")
|
||||
.WithBaseClass("BaseTestClass")
|
||||
.WithModifiers("public sealed")
|
||||
.WithConstructor(
|
||||
SyntaxBuilder.CreateConstructor("TestClass")
|
||||
.WithBase(
|
||||
SyntaxBuilder.CreateBaseConstructor()
|
||||
.WithArgument("fieldString"))
|
||||
.WithParameter("string", "fieldString")
|
||||
.WithBody("this.fieldString = fieldString ?? throw new ArgumentNullException();"))
|
||||
.WithField(
|
||||
SyntaxBuilder.CreateField("string", "fieldString")
|
||||
[TestMethod]
|
||||
public void NewNamespace_GeneratesExpected()
|
||||
{
|
||||
var namespaceSyntax = SyntaxBuilder.CreateNamespace("TestNamespace")
|
||||
.WithUsing("System")
|
||||
.WithClass(
|
||||
SyntaxBuilder.CreateClass("TestClass")
|
||||
.WithBaseClass("BaseTestClass")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute")
|
||||
.WithArgument("SomeIntProperty", 1)
|
||||
.WithArgument("SomeStringProperty", "Hello")
|
||||
.WithArgument("SomeEnumProperty", MyEnum.Value)
|
||||
.WithArgument("SomeTypeProperty", typeof(string))
|
||||
.WithNullArgument("SomeNullProperty"))
|
||||
.WithModifiers("public sealed")
|
||||
.WithConstructor(
|
||||
SyntaxBuilder.CreateConstructor("TestClass")
|
||||
.WithBase(
|
||||
SyntaxBuilder.CreateBaseConstructor()
|
||||
.WithArgument("fieldString"))
|
||||
.WithAttribute(
|
||||
SyntaxBuilder.CreateAttribute("SomeAttribute5")
|
||||
.WithNullArgument())
|
||||
.WithParameter("string", "fieldString")
|
||||
.WithBody("this.fieldString = fieldString ?? throw new ArgumentNullException();"))
|
||||
.WithField(
|
||||
SyntaxBuilder.CreateField("string", "fieldString")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute2"))
|
||||
.WithModifier("private"))
|
||||
.WithProperty(
|
||||
SyntaxBuilder.CreateProperty("string", "PropertyString")
|
||||
.WithModifier("public")
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateSetter()
|
||||
.WithModifier("private"))
|
||||
.WithProperty(
|
||||
SyntaxBuilder.CreateProperty("string", "PropertyString")
|
||||
.WithModifier("public")
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateSetter()
|
||||
.WithModifier("private"))
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateGetter()))
|
||||
.WithMethod(
|
||||
SyntaxBuilder.CreateMethod("string", "GetFieldString")
|
||||
.WithModifier("public")
|
||||
.WithBody("return this.fieldString;")))
|
||||
.Build();
|
||||
.WithAccessor(
|
||||
SyntaxBuilder.CreateGetter())
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute3")
|
||||
.WithArgument(typeof(string))))
|
||||
.WithMethod(
|
||||
SyntaxBuilder.CreateMethod("string", "GetFieldString")
|
||||
.WithModifier("public")
|
||||
.WithAttribute(SyntaxBuilder.CreateAttribute("SomeAttribute4")
|
||||
.WithArgument(0.5f))
|
||||
.WithBody("return this.fieldString;")))
|
||||
.Build();
|
||||
|
||||
var namespaceString = namespaceSyntax.ToFullString();
|
||||
namespaceString.Should().Be(ExpectedNamespace);
|
||||
}
|
||||
var namespaceString = namespaceSyntax.ToFullString();
|
||||
namespaceString.Should().Be(ExpectedNamespace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Sybil.IntegrationTests.Models
|
||||
{
|
||||
public enum MyEnum
|
||||
{
|
||||
Value
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@@ -3,174 +3,173 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class AccessorBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class AccessorBuilderTests
|
||||
{
|
||||
private const string PublicGet = "public get;";
|
||||
private const string PublicStaticGet = "public static get;";
|
||||
private const string Set = "set;";
|
||||
private const string GetExpressionField = "get => this.field ;";
|
||||
private const string GetBodyField =
|
||||
private const string PublicGet = "public get;";
|
||||
private const string PublicStaticGet = "public static get;";
|
||||
private const string Set = "set;";
|
||||
private const string GetExpressionField = "get => this.field ;";
|
||||
private const string GetBodyField =
|
||||
@"get
|
||||
{
|
||||
return this.field;
|
||||
}";
|
||||
|
||||
private readonly AccessorBuilder builder;
|
||||
private readonly AccessorBuilder builder;
|
||||
|
||||
public AccessorBuilderTests()
|
||||
public AccessorBuilderTests()
|
||||
{
|
||||
this.builder = new AccessorBuilder(Microsoft.CodeAnalysis.CSharp.SyntaxKind.GetAccessorDeclaration);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsNullArgumentException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new AccessorBuilder(Microsoft.CodeAnalysis.CSharp.SyntaxKind.GetAccessorDeclaration);
|
||||
}
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsNullArgumentException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier("public");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers("public static");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier("public");
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody("return this.field;");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ExpressionNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
this.builder.WithArrowExpression(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers("public static");
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ExpressionValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithArrowExpression("this.field;");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsAccessorDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<AccessorDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody("return this.field;");
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier("public").Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(PublicGet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ExpressionNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithArrowExpression(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers("public static").Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
result.Should().Be(PublicStaticGet);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ExpressionValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithArrowExpression("this.field;");
|
||||
[TestMethod]
|
||||
public void SetAccessor_ReturnsExpectedString()
|
||||
{
|
||||
var result = new AccessorBuilder(Microsoft.CodeAnalysis.CSharp.SyntaxKind.SetAccessorDeclaration).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(Set);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsAccessorDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody("return this.field;").Build().ToFullString();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<AccessorDeclarationSyntax>();
|
||||
}
|
||||
result.Should().Be(GetBodyField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier("public").Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithArrowExpression("this.field;").Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicGet);
|
||||
}
|
||||
result.Should().Be(GetExpressionField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers("public static").Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithBody_OverridesWithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithArrowExpression("this field;")
|
||||
.WithBody("return this.field;")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(PublicStaticGet);
|
||||
}
|
||||
result.Should().Be(GetBodyField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SetAccessor_ReturnsExpectedString()
|
||||
{
|
||||
var result = new AccessorBuilder(Microsoft.CodeAnalysis.CSharp.SyntaxKind.SetAccessorDeclaration).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_OverridesWithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody("return this.field;")
|
||||
.WithArrowExpression("this.field;")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(Set);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody("return this.field;").Build().ToFullString();
|
||||
|
||||
result.Should().Be(GetBodyField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithArrowExpression("this.field;").Build().ToFullString();
|
||||
|
||||
result.Should().Be(GetExpressionField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_OverridesWithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithArrowExpression("this field;")
|
||||
.WithBody("return this.field;")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(GetBodyField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_OverridesWithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody("return this.field;")
|
||||
.WithArrowExpression("this.field;")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(GetExpressionField);
|
||||
}
|
||||
result.Should().Be(GetExpressionField);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class AttributeBuilderTests
|
||||
{
|
||||
private const string AttributeName = "SomeAttribute";
|
||||
private const string PropertyName = "SomeProperty";
|
||||
private const string StringValue = "SomeString";
|
||||
private const int IntValue = 1;
|
||||
private const uint UintValue = 1U;
|
||||
private const long LongValue = 1L;
|
||||
private const ulong UlongValue = 1UL;
|
||||
private const short ShortValue = 1;
|
||||
private const ushort UshortValue = 1;
|
||||
private const float FloatValue = 1.5f;
|
||||
private const double DoubleValue = 1.5;
|
||||
private const byte ByteValue = 1;
|
||||
private const char CharValue = 'c';
|
||||
private const bool BoolTrueValue = true;
|
||||
private const bool BoolFalseValue = false;
|
||||
|
||||
private const string AttributeWithPropertyNameAndStringValue = $"{AttributeName}({PropertyName} = \"{StringValue}\")";
|
||||
private const string AttributeWithPropertyNameAndIntValue = $"{AttributeName}({PropertyName} = 1)";
|
||||
private const string AttributeWithPropertyNameAndUintValue = $"{AttributeName}({PropertyName} = 1U)";
|
||||
private const string AttributeWithPropertyNameAndLongValue = $"{AttributeName}({PropertyName} = 1L)";
|
||||
private const string AttributeWithPropertyNameAndUlongValue = $"{AttributeName}({PropertyName} = 1UL)";
|
||||
private const string AttributeWithPropertyNameAndShortValue = $"{AttributeName}({PropertyName} = 1)";
|
||||
private const string AttributeWithPropertyNameAndUshortValue = $"{AttributeName}({PropertyName} = 1)";
|
||||
private const string AttributeWithPropertyNameAndFloatValue = $"{AttributeName}({PropertyName} = 1.5F)";
|
||||
private const string AttributeWithPropertyNameAndDoubleValue = $"{AttributeName}({PropertyName} = 1.5)";
|
||||
private const string AttributeWithPropertyNameAndByteValue = $"{AttributeName}({PropertyName} = 1)";
|
||||
private const string AttributeWithPropertyNameAndCharValue = $"{AttributeName}({PropertyName} = 'c')";
|
||||
private const string AttributeWithPropertyNameAndBoolTrueValue = $"{AttributeName}({PropertyName} = true)";
|
||||
private const string AttributeWithPropertyNameAndBoolFalseValue = $"{AttributeName}({PropertyName} = false)";
|
||||
private const string AttributeWithPropertyNameAndNullValue = $"{AttributeName}({PropertyName} = null)";
|
||||
private const string AttributeWithStringValue = $"{AttributeName}(\"{StringValue}\")";
|
||||
private const string AttributeWithIntValue = $"{AttributeName}(1)";
|
||||
private const string AttributeWithUintValue = $"{AttributeName}(1U)";
|
||||
private const string AttributeWithLongValue = $"{AttributeName}(1L)";
|
||||
private const string AttributeWithUlongValue = $"{AttributeName}(1UL)";
|
||||
private const string AttributeWithShortValue = $"{AttributeName}(1)";
|
||||
private const string AttributeWithUshortValue = $"{AttributeName}(1)";
|
||||
private const string AttributeWithFloatValue = $"{AttributeName}(1.5F)";
|
||||
private const string AttributeWithDoubleValue = $"{AttributeName}(1.5)";
|
||||
private const string AttributeWithByteValue = $"{AttributeName}(1)";
|
||||
private const string AttributeWithCharValue = $"{AttributeName}('c')";
|
||||
private const string AttributeWithBoolTrueValue = $"{AttributeName}(true)";
|
||||
private const string AttributeWithBoolFalseValue = $"{AttributeName}(false)";
|
||||
private const string AttributeWithNullValue = $"{AttributeName}(null)";
|
||||
|
||||
private readonly AttributeBuilder attributeBuilder = SyntaxBuilder.CreateAttribute(AttributeName);
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentBool_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, false);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentString_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, "Hello");
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentInt_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentFloat_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1f);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentDouble_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1d);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentLong_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1L);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentUint_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1U);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentUlong_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 1UL);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentShort_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, (short)1);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentUshort_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, (ushort)1);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentByte_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, (byte)1);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentChar_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithArgument(null, 'c');
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithNullArgument_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
attributeBuilder.WithNullArgument(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgumentString_NullValue_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
attributeBuilder.WithArgument("SomeProperty", (string)null);
|
||||
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndStringValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, StringValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndStringValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndIntValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, IntValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndIntValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndFloatValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, FloatValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndFloatValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndDoubleValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, DoubleValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndDoubleValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndLongValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, LongValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndLongValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndUintValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, UintValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndUintValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndUlongValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, UlongValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndUlongValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndShortValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, ShortValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndShortValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndUshortValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, UshortValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndUshortValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndByteValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, ByteValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndByteValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndBoolTrueValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, BoolTrueValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndBoolTrueValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndBoolFalseValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, BoolFalseValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndBoolFalseValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndCharValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(PropertyName, CharValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndCharValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithPropertyNameAndNullValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithNullArgument(PropertyName).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithPropertyNameAndNullValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithStringValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(StringValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithStringValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithIntValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(IntValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithIntValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithFloatValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(FloatValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithFloatValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithDoubleValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(DoubleValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithDoubleValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithLongValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(LongValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithLongValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithUintValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(UintValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithUintValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithUlongValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(UlongValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithUlongValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithShortValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(ShortValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithShortValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithUshortValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(UshortValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithUshortValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithByteValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(ByteValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithByteValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithBoolTrueValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(BoolTrueValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithBoolTrueValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithBoolFalseValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(BoolFalseValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithBoolFalseValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithCharValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithArgument(CharValue).Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithCharValue);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_WithNullValue_ReturnsExpected()
|
||||
{
|
||||
var result = attributeBuilder.WithNullArgument().Build().ToFullString();
|
||||
|
||||
result.Should().Be(AttributeWithNullValue);
|
||||
}
|
||||
}
|
||||
@@ -3,65 +3,64 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class BaseConstructorBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class BaseConstructorBuilderTests
|
||||
private const string EmptyBase = ": base()";
|
||||
private const string TestBase = ": base(test)";
|
||||
|
||||
private readonly BaseConstructorBuilder builder;
|
||||
|
||||
public BaseConstructorBuilderTests()
|
||||
{
|
||||
private const string EmptyBase = ": base()";
|
||||
private const string TestBase = ": base(test)";
|
||||
this.builder = new BaseConstructorBuilder();
|
||||
}
|
||||
|
||||
private readonly BaseConstructorBuilder builder;
|
||||
|
||||
public BaseConstructorBuilderTests()
|
||||
[TestMethod]
|
||||
public void WithArgument_NullArgument_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new BaseConstructorBuilder();
|
||||
}
|
||||
this.builder.WithArgument(null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_NullArgument_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithArgument(null);
|
||||
};
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
[TestMethod]
|
||||
public void WithArgument_ValidArgument_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithArgument("test");
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_ValidArgument_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithArgument("test");
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
[TestMethod]
|
||||
public void Build_ReturnsConstructorInitializerSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsConstructorInitializerSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ConstructorInitializerSyntax>();
|
||||
}
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ConstructorInitializerSyntax>();
|
||||
}
|
||||
[TestMethod]
|
||||
public void EmptyBaseConstructor_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.Build().ToFullString();
|
||||
|
||||
[TestMethod]
|
||||
public void EmptyBaseConstructor_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.Build().ToFullString();
|
||||
result.Should().Be(EmptyBase);
|
||||
}
|
||||
|
||||
result.Should().Be(EmptyBase);
|
||||
}
|
||||
[TestMethod]
|
||||
public void WithArgument_ShouldReturnExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithArgument("test")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
[TestMethod]
|
||||
public void WithArgument_ShouldReturnExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithArgument("test")
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(TestBase);
|
||||
}
|
||||
result.Should().Be(TestBase);
|
||||
}
|
||||
}
|
||||
@@ -3,178 +3,177 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class ClassBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ClassBuilderTests
|
||||
{
|
||||
private const string Name = "Test";
|
||||
private const string Base = "Base";
|
||||
private const string PublicClass =
|
||||
private const string Name = "Test";
|
||||
private const string Base = "Base";
|
||||
private const string PublicClass =
|
||||
@"public class Test
|
||||
{
|
||||
}";
|
||||
private const string PublicStaticClass =
|
||||
private const string PublicStaticClass =
|
||||
@"public static class Test
|
||||
{
|
||||
}";
|
||||
private const string ClassWithBase =
|
||||
private const string ClassWithBase =
|
||||
@"class Test : Base
|
||||
{
|
||||
}";
|
||||
|
||||
private readonly ClassBuilder builder;
|
||||
private readonly ClassBuilder builder;
|
||||
|
||||
public ClassBuilderTests()
|
||||
public ClassBuilderTests()
|
||||
{
|
||||
this.builder = new ClassBuilder(Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new ClassBuilder(Name);
|
||||
}
|
||||
_ = new ClassBuilder(null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new ClassBuilder(null);
|
||||
};
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier("public");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers("public static");
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithField_NullFieldBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier("public");
|
||||
this.builder.WithField(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithProperty_NullPropertyBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
this.builder.WithProperty(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithMethod_NullMethodBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers("public static");
|
||||
this.builder.WithMethod(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithField_NullFieldBuilder_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithConstructor_NullConstructorBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithField(null);
|
||||
};
|
||||
this.builder.WithConstructor(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithProperty_NullPropertyBuilder_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithBaseClass_NullBaseClass_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithProperty(null);
|
||||
};
|
||||
this.builder.WithBaseClass(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithMethod_NullMethodBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithMethod(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithBaseClass_BaseClassValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBaseClass(Base);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().BeOfType<ClassBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithConstructor_NullConstructorBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithConstructor(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsClassDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ClassDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_NullBaseClass_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBaseClass(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier("public").Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
result.Should().Be(PublicClass);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_BaseClassValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBaseClass(Base);
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers("public static").Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().BeOfType<ClassBuilder>();
|
||||
}
|
||||
result.Should().Be(PublicStaticClass);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsClassDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
[TestMethod]
|
||||
public void WithBaseClass_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBaseClass(Base)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ClassDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier("public").Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicClass);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers("public static").Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicStaticClass);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBaseClass(Base)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(ClassWithBase);
|
||||
}
|
||||
result.Should().Be(ClassWithBase);
|
||||
}
|
||||
}
|
||||
@@ -3,221 +3,220 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class ConstructorBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ConstructorBuilderTests
|
||||
{
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string Null = "null";
|
||||
private const string ParameterType = "string";
|
||||
private const string ParameterName = "someString";
|
||||
private const string Name = "Test";
|
||||
private const string Body = "this.someString = someString;";
|
||||
private const string PublicEmptyConstructor =
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string Null = "null";
|
||||
private const string ParameterType = "string";
|
||||
private const string ParameterName = "someString";
|
||||
private const string Name = "Test";
|
||||
private const string Body = "this.someString = someString;";
|
||||
private const string PublicEmptyConstructor =
|
||||
@"public Test()
|
||||
{
|
||||
}";
|
||||
private const string PublicSealedEmptyConstructor =
|
||||
private const string PublicSealedEmptyConstructor =
|
||||
@"public sealed Test()
|
||||
{
|
||||
}";
|
||||
private const string ConstructorWithParameter =
|
||||
private const string ConstructorWithParameter =
|
||||
@"Test(string someString)
|
||||
{
|
||||
}";
|
||||
private const string ConstructorWithParameterWithDefault =
|
||||
private const string ConstructorWithParameterWithDefault =
|
||||
@"Test(string someString = null)
|
||||
{
|
||||
}";
|
||||
private const string ConstructorWithBody =
|
||||
private const string ConstructorWithBody =
|
||||
@"Test()
|
||||
{
|
||||
this.someString = someString;
|
||||
}";
|
||||
private const string ConstructorWithModifiersBodyAndParameter =
|
||||
private const string ConstructorWithModifiersBodyAndParameter =
|
||||
@"public public sealed Test(string someString = null)
|
||||
{
|
||||
this.someString = someString;
|
||||
}";
|
||||
|
||||
private readonly ConstructorBuilder builder;
|
||||
private readonly ConstructorBuilder builder;
|
||||
|
||||
public ConstructorBuilderTests()
|
||||
public ConstructorBuilderTests()
|
||||
{
|
||||
this.builder = new ConstructorBuilder(Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new ConstructorBuilder(Name);
|
||||
}
|
||||
_ = new ConstructorBuilder(null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new ConstructorBuilder(null);
|
||||
};
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBase_NullBase_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
this.builder.WithBase(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
this.builder.WithParameter(ParameterType, null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
this.builder.WithParameter(null, ParameterName);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBase_NullBase_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithParameter(ParameterType, ParameterName);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBase(null);
|
||||
};
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithParameter(ParameterType, null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody(Body);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithParameter(null, ParameterName);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsConstructorDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ConstructorDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithParameter(ParameterType, ParameterName);
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(PublicEmptyConstructor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
result.Should().Be(PublicSealedEmptyConstructor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody(Body);
|
||||
[TestMethod]
|
||||
public void WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(ConstructorWithParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsConstructorDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
[TestMethod]
|
||||
public void WithParameter_WithDefault_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName, Null).Build().ToFullString();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<ConstructorDeclarationSyntax>();
|
||||
}
|
||||
result.Should().Be(ConstructorWithParameterWithDefault);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody(Body).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicEmptyConstructor);
|
||||
}
|
||||
result.Should().Be(ConstructorWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithBody_WithParameter_WithModifier_WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.WithModifier(Public)
|
||||
.WithModifiers(PublicSealed)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(PublicSealedEmptyConstructor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
|
||||
result.Should().Be(ConstructorWithParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_WithDefault_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName, Null).Build().ToFullString();
|
||||
|
||||
result.Should().Be(ConstructorWithParameterWithDefault);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody(Body).Build().ToFullString();
|
||||
|
||||
result.Should().Be(ConstructorWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_WithParameter_WithModifier_WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.WithModifier(Public)
|
||||
.WithModifiers(PublicSealed)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(ConstructorWithModifiersBodyAndParameter);
|
||||
}
|
||||
result.Should().Be(ConstructorWithModifiersBodyAndParameter);
|
||||
}
|
||||
}
|
||||
@@ -3,107 +3,106 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class FieldBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class FieldBuilderTests
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string FieldName = "someString";
|
||||
private const string FieldType = "string";
|
||||
private const string PublicField = "public string someString;";
|
||||
private const string PublicSealedField = "public sealed string someString;";
|
||||
|
||||
private readonly FieldBuilder builder;
|
||||
|
||||
public FieldBuilderTests()
|
||||
{
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string FieldName = "someString";
|
||||
private const string FieldType = "string";
|
||||
private const string PublicField = "public string someString;";
|
||||
private const string PublicSealedField = "public sealed string someString;";
|
||||
this.builder = new FieldBuilder(FieldType, FieldName);
|
||||
}
|
||||
|
||||
private readonly FieldBuilder builder;
|
||||
|
||||
public FieldBuilderTests()
|
||||
[TestMethod]
|
||||
public void Constructor_NullFieldType_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new FieldBuilder(FieldType, FieldName);
|
||||
}
|
||||
_ = new FieldBuilder(null, FieldName);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullFieldType_ThrowsArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullFieldName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new FieldBuilder(null, FieldName);
|
||||
};
|
||||
_ = new FieldBuilder(FieldType, null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullFieldName_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new FieldBuilder(FieldType, null);
|
||||
};
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsFieldDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<FieldDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(PublicField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsFieldDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<FieldDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicField);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicSealedField);
|
||||
}
|
||||
result.Should().Be(PublicSealedField);
|
||||
}
|
||||
}
|
||||
@@ -3,315 +3,314 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class MethodBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class MethodBuilderTests
|
||||
{
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string Null = "null";
|
||||
private const string ParameterType = "string";
|
||||
private const string ParameterName = "someString";
|
||||
private const string Name = "Test";
|
||||
private const string ReturnType = "string";
|
||||
private const string Expression = "this.someString;";
|
||||
private const string Body = "this.someString = someString;";
|
||||
private const string PublicEmptyMethod = "public string Test() => throw new NotImplementedException() ;";
|
||||
private const string PublicSealedEmptyMethod = "public sealed string Test() => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithParameter = "string Test(string someString) => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithThisParameter = "string Test(this string someString) => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithParameterWithDefault = "string Test(string someString = null) => throw new NotImplementedException() ;";
|
||||
private const string MethodWithArrowExpression = "string Test() => this.someString ;";
|
||||
private const string PublicSealedMethodWithParameterAndExpression = "public sealed string Test(string someString = null) => this.someString ;";
|
||||
private const string MethodWithBody =
|
||||
private const string Public = "public";
|
||||
private const string PublicSealed = "public sealed";
|
||||
private const string Null = "null";
|
||||
private const string ParameterType = "string";
|
||||
private const string ParameterName = "someString";
|
||||
private const string Name = "Test";
|
||||
private const string ReturnType = "string";
|
||||
private const string Expression = "this.someString;";
|
||||
private const string Body = "this.someString = someString;";
|
||||
private const string PublicEmptyMethod = "public string Test() => throw new NotImplementedException() ;";
|
||||
private const string PublicSealedEmptyMethod = "public sealed string Test() => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithParameter = "string Test(string someString) => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithThisParameter = "string Test(this string someString) => throw new NotImplementedException() ;";
|
||||
private const string EmptyMethodWithParameterWithDefault = "string Test(string someString = null) => throw new NotImplementedException() ;";
|
||||
private const string MethodWithArrowExpression = "string Test() => this.someString ;";
|
||||
private const string PublicSealedMethodWithParameterAndExpression = "public sealed string Test(string someString = null) => this.someString ;";
|
||||
private const string MethodWithBody =
|
||||
@"string Test()
|
||||
{
|
||||
this.someString = someString;
|
||||
}";
|
||||
private const string PublicSealedMethodWithBodyAndParameter =
|
||||
private const string PublicSealedMethodWithBodyAndParameter =
|
||||
@"public sealed string Test(string someString = null)
|
||||
{
|
||||
this.someString = someString;
|
||||
}";
|
||||
|
||||
private readonly MethodBuilder builder;
|
||||
private readonly MethodBuilder builder;
|
||||
|
||||
public MethodBuilderTests()
|
||||
public MethodBuilderTests()
|
||||
{
|
||||
this.builder = new MethodBuilder(ReturnType, Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new MethodBuilder(ReturnType, Name);
|
||||
}
|
||||
_ = new MethodBuilder(ReturnType, null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullName_ThrowArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullReturnType_ThrowArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new MethodBuilder(ReturnType, null);
|
||||
};
|
||||
_ = new MethodBuilder(null, Name);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullReturnType_ThrowArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new MethodBuilder(null, Name);
|
||||
};
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
this.builder.WithParameter(ParameterType, null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
this.builder.WithParameter(null, ParameterName);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithParameter(ParameterType, ParameterName);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicSealed);
|
||||
this.builder.WithThisParameter(ParameterType, null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithParameter(ParameterType, null);
|
||||
};
|
||||
this.builder.WithThisParameter(null, ParameterName);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithThisParameter(ParameterType, ParameterName);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithParameter(null, ParameterName);
|
||||
};
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ParameterValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody(Body);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithExpression_ExpressionNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithParameter(ParameterType, ParameterName);
|
||||
this.builder.WithExpression(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterNameNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithThisParameter(ParameterType, null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithExpression_ExpressionValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithExpression(Expression);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterTypeNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithThisParameter(null, ParameterName);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsMethodDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<MethodDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ParameterValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithThisParameter(ParameterType, ParameterName);
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(PublicEmptyMethod);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBody(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
result.Should().Be(PublicSealedEmptyMethod);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_BodyValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBody(Body);
|
||||
[TestMethod]
|
||||
public void WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(EmptyMethodWithParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithExpression_ExpressionNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithExpression(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithParameter_WithDefault_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName, Null).Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
result.Should().Be(EmptyMethodWithParameterWithDefault);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithExpression_ExpressionValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithExpression(Expression);
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithThisParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(EmptyMethodWithThisParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsMethodDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody(Body).Build().ToFullString();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<MethodDeclarationSyntax>();
|
||||
}
|
||||
result.Should().Be(MethodWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithExpression(Expression).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicEmptyMethod);
|
||||
}
|
||||
result.Should().Be(MethodWithArrowExpression);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicSealed).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithBody_OverwritesWithExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithExpression(Expression)
|
||||
.WithBody(Body)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(PublicSealedEmptyMethod);
|
||||
}
|
||||
result.Should().Be(MethodWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithExpression_OverwritesWithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithExpression(Expression)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(EmptyMethodWithParameter);
|
||||
}
|
||||
result.Should().Be(MethodWithArrowExpression);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameter_WithDefault_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithParameter(ParameterType, ParameterName, Null).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithBody_WithModifiers_WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithModifiers(PublicSealed)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(EmptyMethodWithParameterWithDefault);
|
||||
}
|
||||
result.Should().Be(PublicSealedMethodWithBodyAndParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithThisParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithThisParameter(ParameterType, ParameterName).Build().ToFullString();
|
||||
[TestMethod]
|
||||
public void WithExpression_WithModifiers_WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithExpression(Expression)
|
||||
.WithModifiers(PublicSealed)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(EmptyMethodWithThisParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithBody(Body).Build().ToFullString();
|
||||
|
||||
result.Should().Be(MethodWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithArrowExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithExpression(Expression).Build().ToFullString();
|
||||
|
||||
result.Should().Be(MethodWithArrowExpression);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_OverwritesWithExpression_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithExpression(Expression)
|
||||
.WithBody(Body)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(MethodWithBody);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithExpression_OverwritesWithBody_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithExpression(Expression)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(MethodWithArrowExpression);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBody_WithModifiers_WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBody(Body)
|
||||
.WithModifiers(PublicSealed)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(PublicSealedMethodWithBodyAndParameter);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithExpression_WithModifiers_WithParameter_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithExpression(Expression)
|
||||
.WithModifiers(PublicSealed)
|
||||
.WithParameter(ParameterType, ParameterName, Null)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(PublicSealedMethodWithParameterAndExpression);
|
||||
}
|
||||
result.Should().Be(PublicSealedMethodWithParameterAndExpression);
|
||||
}
|
||||
}
|
||||
@@ -3,84 +3,83 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class NamespaceBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class NamespaceBuilderTests
|
||||
{
|
||||
private const string Using = "System";
|
||||
private const string Namespace = "Test";
|
||||
private const string NamespaceWithUsing =
|
||||
private const string Using = "System";
|
||||
private const string Namespace = "Test";
|
||||
private const string NamespaceWithUsing =
|
||||
@"namespace Test
|
||||
{
|
||||
using System;
|
||||
}";
|
||||
|
||||
private readonly NamespaceBuilder builder;
|
||||
private readonly NamespaceBuilder builder;
|
||||
|
||||
public NamespaceBuilderTests()
|
||||
public NamespaceBuilderTests()
|
||||
{
|
||||
this.builder = new NamespaceBuilder(Namespace);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullNamespace_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new NamespaceBuilder(Namespace);
|
||||
}
|
||||
_ = new NamespaceBuilder(null);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullNamespace_ThrowsArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithUsing_NullUsing_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new NamespaceBuilder(null);
|
||||
};
|
||||
this.builder.WithUsing(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithUsing_NullUsing_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithUsing_ValidUsing_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithUsing(Using);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithClass_NullClassBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithUsing(null);
|
||||
};
|
||||
this.builder.WithClass(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithUsing_ValidUsing_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithUsing(Using);
|
||||
[TestMethod]
|
||||
public void Build_ReturnsNamespaceDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<NamespaceDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithClass_NullClassBuilder_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithClass(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithUsing_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithUsing(Using)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsNamespaceDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<NamespaceDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithUsing_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithUsing(Using)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(NamespaceWithUsing);
|
||||
}
|
||||
result.Should().Be(NamespaceWithUsing);
|
||||
}
|
||||
}
|
||||
@@ -3,118 +3,117 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class PropertyBuilderTests
|
||||
{
|
||||
[TestClass]
|
||||
public class PropertyBuilderTests
|
||||
private const string Public = "public";
|
||||
private const string PublicStatic = "public static";
|
||||
private const string TypeName = "string";
|
||||
private const string PropertyName = "SomeString";
|
||||
private const string PublicProperty = "public string SomeString { }";
|
||||
private const string PublicStaticProperty = "public static string SomeString { }";
|
||||
|
||||
private readonly PropertyBuilder builder;
|
||||
|
||||
public PropertyBuilderTests()
|
||||
{
|
||||
private const string Public = "public";
|
||||
private const string PublicStatic = "public static";
|
||||
private const string TypeName = "string";
|
||||
private const string PropertyName = "SomeString";
|
||||
private const string PublicProperty = "public string SomeString { }";
|
||||
private const string PublicStaticProperty = "public static string SomeString { }";
|
||||
this.builder = new PropertyBuilder(TypeName, PropertyName);
|
||||
}
|
||||
|
||||
private readonly PropertyBuilder builder;
|
||||
|
||||
public PropertyBuilderTests()
|
||||
[TestMethod]
|
||||
public void Constructor_NullPropertyType_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder = new PropertyBuilder(TypeName, PropertyName);
|
||||
}
|
||||
_ = new PropertyBuilder(null, PropertyName);
|
||||
};
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullPropertyType_ThrowsArgumentNullException()
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullPropertyName_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new PropertyBuilder(null, PropertyName);
|
||||
};
|
||||
_ = new PropertyBuilder(TypeName, null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullPropertyName_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new PropertyBuilder(TypeName, null);
|
||||
};
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierNull_ThrowsArgumentNullException()
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifier(null);
|
||||
};
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ModifierValid_ReturnsBuilder()
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicStatic);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithAccessor_NullAccessor_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifier(Public);
|
||||
this.builder.WithAccessor(null);
|
||||
};
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersNull_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithModifiers(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void Build_ReturnsPropertyDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<PropertyDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ModifiersValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithModifiers(PublicStatic);
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().Be(this.builder);
|
||||
}
|
||||
result.Should().Be(PublicProperty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithAccessor_NullAccessor_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithAccessor(null);
|
||||
};
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicStatic).Build().ToFullString();
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsPropertyDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<PropertyDeclarationSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifier_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifier(Public).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicProperty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithModifiers_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder.WithModifiers(PublicStatic).Build().ToFullString();
|
||||
|
||||
result.Should().Be(PublicStaticProperty);
|
||||
}
|
||||
result.Should().Be(PublicStaticProperty);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@@ -0,0 +1,417 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
|
||||
namespace Sybil
|
||||
{
|
||||
public sealed class AttributeBuilder : IBuilder<AttributeSyntax>
|
||||
{
|
||||
private AttributeSyntax AttributeSyntax { get; set; }
|
||||
|
||||
internal AttributeBuilder(string attributeName)
|
||||
{
|
||||
this.AttributeSyntax = SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeName));
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, int value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, float value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, double value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, long value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, uint value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, ulong value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, short value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, ushort value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, byte value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, bool value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(value ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, char value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.CharacterLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithNullArgument(string propertyName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string propertyName, Type type)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseTypeName(type.Name))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument<TEnum>(string propertyName, TEnum value)
|
||||
where TEnum : Enum
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(propertyName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyName));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.NameEquals(propertyName),
|
||||
null,
|
||||
SyntaxFactory.MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
SyntaxFactory.IdentifierName(typeof(TEnum).Name),
|
||||
SyntaxFactory.IdentifierName(Enum.GetName(typeof(TEnum), value)))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(int value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(float value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(double value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(long value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(uint value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(ulong value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(short value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(ushort value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(byte value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(bool value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(value ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(char value)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.CharacterLiteralExpression, SyntaxFactory.Literal(value))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithNullArgument()
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument(Type type)
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.TypeOfExpression(
|
||||
SyntaxFactory.ParseTypeName(type.Name))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeBuilder WithArgument<TEnum>(TEnum value)
|
||||
where TEnum : Enum
|
||||
{
|
||||
this.AttributeSyntax = this.AttributeSyntax.AddArgumentListArguments(
|
||||
SyntaxFactory.AttributeArgument(
|
||||
SyntaxFactory.MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
SyntaxFactory.IdentifierName(typeof(TEnum).Name),
|
||||
SyntaxFactory.IdentifierName(Enum.GetName(typeof(TEnum), value)))));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AttributeSyntax Build()
|
||||
{
|
||||
return this.AttributeSyntax
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace Sybil
|
||||
{
|
||||
private ClassDeclarationSyntax ClassDeclaration { get; set; }
|
||||
|
||||
private readonly List<AttributeBuilder> Attributes = new List<AttributeBuilder>();
|
||||
private readonly List<ConstructorBuilder> Constructors = new List<ConstructorBuilder>();
|
||||
private readonly List<FieldBuilder> Fields = new List<FieldBuilder>();
|
||||
private readonly List<PropertyBuilder> Properties = new List<PropertyBuilder>();
|
||||
@@ -80,9 +81,17 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClassBuilder WithAttribute(AttributeBuilder attributeBuilder)
|
||||
{
|
||||
this.Attributes.Add(attributeBuilder ?? throw new ArgumentNullException(nameof(attributeBuilder)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClassDeclarationSyntax Build()
|
||||
{
|
||||
return this.ClassDeclaration
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.Attributes.Select(p => p.Build()).ToArray())))
|
||||
.AddMembers(this.Constructors.Select(p => p.Build()).ToArray())
|
||||
.AddMembers(this.Fields.Select(p => p.Build()).ToArray())
|
||||
.AddMembers(this.Properties.Select(p => p.Build()).ToArray())
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sybil
|
||||
{
|
||||
public sealed class ConstructorBuilder : IBuilder<ConstructorDeclarationSyntax>
|
||||
{
|
||||
private readonly List<AttributeBuilder> attributes = new List<AttributeBuilder>();
|
||||
|
||||
private BaseConstructorBuilder baseConstructorBuilder;
|
||||
|
||||
private ConstructorDeclarationSyntax ConstructorDeclarationSyntax { get; set; }
|
||||
@@ -28,6 +31,7 @@ namespace Sybil
|
||||
this.baseConstructorBuilder = baseConstructorBuilder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorBuilder WithModifiers(string modifiers)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifiers) ? throw new ArgumentNullException(nameof(modifiers)) : modifiers;
|
||||
@@ -36,6 +40,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorBuilder WithModifier(string modifier)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifier) ? throw new ArgumentNullException(nameof(modifier)) : modifier;
|
||||
@@ -44,6 +49,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorBuilder WithParameter(string parameterType, string parameterName, string defaultValue = null)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(parameterName) ? throw new ArgumentNullException(nameof(parameterName)) : parameterName;
|
||||
@@ -66,6 +72,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorBuilder WithBody(string body)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(body) ? throw new ArgumentNullException(nameof(body)) : body;
|
||||
@@ -75,6 +82,14 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorBuilder WithAttribute(AttributeBuilder attributeBuilder)
|
||||
{
|
||||
_ = attributeBuilder ?? throw new ArgumentNullException(nameof(attributeBuilder));
|
||||
|
||||
this.attributes.Add(attributeBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstructorDeclarationSyntax Build()
|
||||
{
|
||||
if (this.baseConstructorBuilder is null is false)
|
||||
@@ -82,7 +97,9 @@ namespace Sybil
|
||||
this.ConstructorDeclarationSyntax = this.ConstructorDeclarationSyntax.WithInitializer(this.baseConstructorBuilder.Build());
|
||||
}
|
||||
|
||||
return this.ConstructorDeclarationSyntax.NormalizeWhitespace();
|
||||
return this.ConstructorDeclarationSyntax
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.attributes.Select(p => p.Build()).ToArray())))
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-1
@@ -2,12 +2,14 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sybil
|
||||
{
|
||||
public sealed class FieldBuilder : IBuilder<FieldDeclarationSyntax>
|
||||
{
|
||||
private readonly List<AttributeBuilder> attributeBuilders = new List<AttributeBuilder>();
|
||||
private FieldDeclarationSyntax FieldDeclarationSyntax { get; set; }
|
||||
|
||||
internal FieldBuilder(
|
||||
@@ -31,6 +33,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldBuilder WithModifiers(string modifiers)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifiers) ? throw new ArgumentNullException(nameof(modifiers)) : modifiers;
|
||||
@@ -40,9 +43,18 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldBuilder WithAttribute(AttributeBuilder attributeBuilder)
|
||||
{
|
||||
this.attributeBuilders.Add(attributeBuilder ?? throw new ArgumentNullException(nameof(attributeBuilder)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldDeclarationSyntax Build()
|
||||
{
|
||||
return this.FieldDeclarationSyntax.NormalizeWhitespace();
|
||||
return this.FieldDeclarationSyntax
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.attributeBuilders.Select(p => p.Build()).ToArray())))
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-2
@@ -2,12 +2,15 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sybil
|
||||
{
|
||||
public sealed class MethodBuilder : IBuilder<MethodDeclarationSyntax>
|
||||
{
|
||||
private readonly List<AttributeBuilder> attributeBuilders = new List<AttributeBuilder>();
|
||||
|
||||
private BlockSyntax BlockBody { get; set; }
|
||||
private ArrowExpressionClauseSyntax ArrowExpression { get; set; }
|
||||
private MethodDeclarationSyntax MethodDeclarationSyntax { get; set; }
|
||||
@@ -31,6 +34,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithModifiers(string modifiers)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifiers) ? throw new ArgumentNullException(nameof(modifiers)) : modifiers;
|
||||
@@ -39,6 +43,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithParameter(string parameterType, string parameterName, string defaultValue = null)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(parameterName) ? throw new ArgumentNullException(nameof(parameterName)) : parameterName;
|
||||
@@ -62,6 +67,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithThisParameter(string parameterType, string parameterName)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(parameterName) ? throw new ArgumentNullException(nameof(parameterName)) : parameterName;
|
||||
@@ -78,6 +84,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithBody(string body)
|
||||
{
|
||||
this.BlockBody = SyntaxFactory.Block(
|
||||
@@ -86,6 +93,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithExpression(string expression)
|
||||
{
|
||||
this.ArrowExpression = SyntaxFactory.ArrowExpressionClause(
|
||||
@@ -95,14 +103,27 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodBuilder WithAttribute(AttributeBuilder attributeBuilder)
|
||||
{
|
||||
this.attributeBuilders.Add(attributeBuilder ?? throw new ArgumentNullException(nameof(attributeBuilder)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MethodDeclarationSyntax Build()
|
||||
{
|
||||
if (this.BlockBody is null is false)
|
||||
{
|
||||
return this.MethodDeclarationSyntax.WithBody(this.BlockBody).NormalizeWhitespace();
|
||||
return this.MethodDeclarationSyntax
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.attributeBuilders.Select(p => p.Build()).ToArray())))
|
||||
.WithBody(this.BlockBody)
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
|
||||
return this.MethodDeclarationSyntax.WithExpressionBody(this.ArrowExpression).NormalizeWhitespace();
|
||||
return this.MethodDeclarationSyntax
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.attributeBuilders.Select(p => p.Build()).ToArray())))
|
||||
.WithExpressionBody(this.ArrowExpression)
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Sybil
|
||||
{
|
||||
public sealed class PropertyBuilder : IBuilder<PropertyDeclarationSyntax>
|
||||
{
|
||||
private readonly List<AttributeBuilder> attributes = new List<AttributeBuilder>();
|
||||
private readonly List<AccessorBuilder> accessors = new List<AccessorBuilder>();
|
||||
|
||||
private PropertyDeclarationSyntax PropertyDeclarationSyntax { get; set; }
|
||||
@@ -31,6 +32,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyBuilder WithModifiers(string modifiers)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifiers) ? throw new ArgumentNullException(nameof(modifiers)) : modifiers;
|
||||
@@ -39,6 +41,7 @@ namespace Sybil
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyBuilder WithAccessor(AccessorBuilder accessorBuilder)
|
||||
{
|
||||
_ = accessorBuilder ?? throw new ArgumentNullException(nameof(accessorBuilder));
|
||||
@@ -48,9 +51,19 @@ namespace Sybil
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyBuilder WithAttribute(AttributeBuilder attributeBuilder)
|
||||
{
|
||||
this.attributes.Add(attributeBuilder ?? throw new ArgumentNullException(nameof(attributeBuilder)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyDeclarationSyntax Build()
|
||||
{
|
||||
return this.PropertyDeclarationSyntax.WithAccessorList(this.BuildAccessorList()).NormalizeWhitespace();
|
||||
return this.PropertyDeclarationSyntax
|
||||
.WithAccessorList(this.BuildAccessorList())
|
||||
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(this.attributes.Select(p => p.Build()).ToArray())))
|
||||
.NormalizeWhitespace();
|
||||
}
|
||||
|
||||
private AccessorListSyntax BuildAccessorList()
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.3.0</Version>
|
||||
<Version>0.4.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
+10
-36
@@ -4,41 +4,15 @@ namespace Sybil
|
||||
{
|
||||
public static class SyntaxBuilder
|
||||
{
|
||||
public static NamespaceBuilder CreateNamespace(string @namespace)
|
||||
{
|
||||
return new NamespaceBuilder(@namespace);
|
||||
}
|
||||
public static ClassBuilder CreateClass(string className)
|
||||
{
|
||||
return new ClassBuilder(className);
|
||||
}
|
||||
public static ConstructorBuilder CreateConstructor(string className)
|
||||
{
|
||||
return new ConstructorBuilder(className);
|
||||
}
|
||||
public static BaseConstructorBuilder CreateBaseConstructor()
|
||||
{
|
||||
return new BaseConstructorBuilder();
|
||||
}
|
||||
public static PropertyBuilder CreateProperty(string typeName, string propertyName)
|
||||
{
|
||||
return new PropertyBuilder(typeName, propertyName);
|
||||
}
|
||||
public static AccessorBuilder CreateSetter()
|
||||
{
|
||||
return new AccessorBuilder(SyntaxKind.SetAccessorDeclaration);
|
||||
}
|
||||
public static AccessorBuilder CreateGetter()
|
||||
{
|
||||
return new AccessorBuilder(SyntaxKind.GetAccessorDeclaration);
|
||||
}
|
||||
public static FieldBuilder CreateField(string fieldType, string fieldName)
|
||||
{
|
||||
return new FieldBuilder(fieldType, fieldName);
|
||||
}
|
||||
public static MethodBuilder CreateMethod(string returnType, string methodName)
|
||||
{
|
||||
return new MethodBuilder(returnType, methodName);
|
||||
}
|
||||
public static NamespaceBuilder CreateNamespace(string @namespace) => new NamespaceBuilder(@namespace);
|
||||
public static ClassBuilder CreateClass(string className) => new ClassBuilder(className);
|
||||
public static ConstructorBuilder CreateConstructor(string className) => new ConstructorBuilder(className);
|
||||
public static BaseConstructorBuilder CreateBaseConstructor() => new BaseConstructorBuilder();
|
||||
public static PropertyBuilder CreateProperty(string typeName, string propertyName) => new PropertyBuilder(typeName, propertyName);
|
||||
public static AccessorBuilder CreateSetter() => new AccessorBuilder(SyntaxKind.SetAccessorDeclaration);
|
||||
public static AccessorBuilder CreateGetter() => new AccessorBuilder(SyntaxKind.GetAccessorDeclaration);
|
||||
public static FieldBuilder CreateField(string fieldType, string fieldName) => new FieldBuilder(fieldType, fieldName);
|
||||
public static MethodBuilder CreateMethod(string returnType, string methodName) => new MethodBuilder(returnType, methodName);
|
||||
public static AttributeBuilder CreateAttribute(string attributeName) => new AttributeBuilder(attributeName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user