mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
Add support for base class (#4)
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Sybil.IntegrationTests
|
||||
{
|
||||
using System;
|
||||
|
||||
public sealed class TestClass
|
||||
public sealed class TestClass : BaseTestClass
|
||||
{
|
||||
TestClass(string fieldString) : base(fieldString)
|
||||
{
|
||||
@@ -35,6 +35,7 @@ namespace Sybil.IntegrationTests
|
||||
.WithUsing("System")
|
||||
.WithClass(
|
||||
SyntaxBuilder.CreateClass("TestClass")
|
||||
.WithBaseClass("BaseTestClass")
|
||||
.WithModifiers("public sealed")
|
||||
.WithConstructor(
|
||||
SyntaxBuilder.CreateConstructor("TestClass")
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Sybil.Tests
|
||||
public class ClassBuilderTests
|
||||
{
|
||||
private const string Name = "Test";
|
||||
private const string Base = "Base";
|
||||
private const string PublicClass =
|
||||
@"public class Test
|
||||
{
|
||||
@@ -16,6 +17,10 @@ namespace Sybil.Tests
|
||||
private const string PublicStaticClass =
|
||||
@"public static class Test
|
||||
{
|
||||
}";
|
||||
private const string ClassWithBase =
|
||||
@"class Test : Base
|
||||
{
|
||||
}";
|
||||
|
||||
private readonly ClassBuilder builder;
|
||||
@@ -118,6 +123,25 @@ namespace Sybil.Tests
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_NullBaseClass_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
this.builder.WithBaseClass(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_BaseClassValid_ReturnsBuilder()
|
||||
{
|
||||
var returnedBuilder = this.builder.WithBaseClass(Base);
|
||||
|
||||
returnedBuilder.Should().NotBeNull().And.Subject.Should().BeOfType<ClassBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsClassDeclarationSyntax()
|
||||
{
|
||||
@@ -141,5 +165,16 @@ namespace Sybil.Tests
|
||||
|
||||
result.Should().Be(PublicStaticClass);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithBaseClass_ReturnsExpectedString()
|
||||
{
|
||||
var result = this.builder
|
||||
.WithBaseClass(Base)
|
||||
.Build()
|
||||
.ToFullString();
|
||||
|
||||
result.Should().Be(ClassWithBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,16 @@ namespace Sybil
|
||||
this.ClassDeclaration = SyntaxFactory.ClassDeclaration(className);
|
||||
}
|
||||
|
||||
public ClassBuilder WithBaseClass(string baseClass)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(baseClass) ? throw new ArgumentNullException(nameof(baseClass)) : baseClass;
|
||||
|
||||
this.ClassDeclaration = this.ClassDeclaration.AddBaseListTypes(
|
||||
SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(baseClass)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClassBuilder WithModifier(string modifier)
|
||||
{
|
||||
_ = string.IsNullOrWhiteSpace(modifier) ? throw new ArgumentNullException(nameof(modifier)) : modifier;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.1.2</Version>
|
||||
<Version>0.2.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user