mirror of
https://github.com/AlexMacocian/Sybil.git
synced 2026-07-15 15:19:59 +00:00
98 lines
4.0 KiB
C#
98 lines
4.0 KiB
C#
using FluentAssertions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Sybil.IntegrationTests.Models;
|
|
|
|
namespace Sybil.IntegrationTests;
|
|
|
|
[TestClass]
|
|
public sealed class FlowTests
|
|
{
|
|
private const string ExpectedNamespace =
|
|
@"[InternalsVisibleTo(""FlowTests"")]
|
|
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();
|
|
this.PropertyString = string.Empty;
|
|
}
|
|
|
|
private string someTypeString = $""{typeof(string)}"";
|
|
[SomeAttribute2]
|
|
private string fieldString;
|
|
[SomeAttribute3(typeof(String))]
|
|
public string PropertyString { private set; get; }
|
|
|
|
[SomeAttribute4(0.5F)]
|
|
public string GetFieldString()
|
|
{
|
|
this.fieldString = 0;
|
|
return this.fieldString;
|
|
}
|
|
}
|
|
}";
|
|
|
|
[TestMethod]
|
|
public void NewNamespace_GeneratesExpected()
|
|
{
|
|
var namespaceSyntax = SyntaxBuilder.CreateNamespace("TestNamespace")
|
|
.WithAttribute(SyntaxBuilder.CreateAttribute("InternalsVisibleTo")
|
|
.WithArgument("FlowTests"))
|
|
.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();\rthis.PropertyString = string.Empty;"))
|
|
.WithField(
|
|
SyntaxBuilder.CreateField("string", "someTypeString")
|
|
.WithModifier("private")
|
|
.WithInitializer("$\"{typeof(string)}\""))
|
|
.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("this.fieldString = 0;\r\nreturn this.fieldString;")))
|
|
.Build();
|
|
|
|
var namespaceString = namespaceSyntax.ToFullString();
|
|
namespaceString.Should().Be(ExpectedNamespace);
|
|
}
|
|
}
|