mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
Setup Type Parameters support
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class TypeParameterBuilderTests
|
||||
{
|
||||
private const string TypeName = "T";
|
||||
|
||||
private readonly TypeParameterBuilder builder;
|
||||
|
||||
public TypeParameterBuilderTests()
|
||||
{
|
||||
this.builder = new TypeParameterBuilder(TypeName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullType_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new TypeParameterBuilder(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsPropertyDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<TypeParameterSyntax>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
|
||||
namespace Sybil.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class TypeParameterConstraintBuilderTests
|
||||
{
|
||||
private const string TypeName = "T";
|
||||
private const string ConstraintType = "TType";
|
||||
private const string Expected = "where T : class, struct, new(), TType";
|
||||
|
||||
private readonly TypeParameterConstraintBuilder builder;
|
||||
|
||||
public TypeParameterConstraintBuilderTests()
|
||||
{
|
||||
this.builder = new TypeParameterConstraintBuilder(TypeName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Constructor_NullType_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = new TypeParameterConstraintBuilder(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithClass_ReturnsBuilder()
|
||||
{
|
||||
this.builder.WithClass().Should().BeOfType<TypeParameterConstraintBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithStruct_ReturnsBuilder()
|
||||
{
|
||||
this.builder.WithStruct().Should().BeOfType<TypeParameterConstraintBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithParameterlessConstructor_ReturnsBuilder()
|
||||
{
|
||||
this.builder.WithParameterlessConstructor().Should().BeOfType<TypeParameterConstraintBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithType_ReturnsBuilder()
|
||||
{
|
||||
this.builder.WithType(ConstraintType).Should().BeOfType<TypeParameterConstraintBuilder>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithType_NullType_ThrowsArgumentNullException()
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
_ = this.builder.WithType(null);
|
||||
};
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsPropertyDeclarationSyntax()
|
||||
{
|
||||
var syntax = this.builder.Build();
|
||||
|
||||
syntax.Should().NotBeNull().And.Subject.Should().BeOfType<TypeParameterConstraintClauseSyntax>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Build_ReturnsExpectedString()
|
||||
{
|
||||
var syntax = this.builder
|
||||
.WithClass()
|
||||
.WithStruct()
|
||||
.WithParameterlessConstructor()
|
||||
.WithType(ConstraintType)
|
||||
.Build();
|
||||
|
||||
var result = syntax.NormalizeWhitespace().ToFullString();
|
||||
|
||||
result.Should().Be(Expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user