using FluentAssertions;
using NUnit.Framework;

namespace Facility.Definition.UnitTests;

public sealed class DtoTests
{
	[Test]
	public void InvalidName()
	{
		new ServiceDtoInfo(name: "4u").IsValid.Should().BeFalse();
	}

	[Test]
	public void DuplicateField()
	{
		var fields = new[]
		{
			new ServiceFieldInfo("why", "int32"),
			new ServiceFieldInfo("Why", "int32"),
		};
		new ServiceDtoInfo(name: "x", fields: fields).IsValid.Should().BeFalse();
	}

	[Test]
	public void OneMinimalDto()
	{
		var service = TestUtility.ParseTestApi("service TestApi { data One { } }");

		var dto = service.Dtos.Single();
		dto.Name.Should().Be("One");
		dto.Attributes.Count.Should().Be(0);
		dto.Fields.Count.Should().Be(0);
		dto.Summary.Should().Be("");
		dto.Remarks.Count.Should().Be(0);
		service.Dtos.FirstOrDefault(x => x.Name == "One").Should().Be(dto);

		TestUtility.GenerateFsd(service).Should().Equal(
			"// DO NOT EDIT: generated by TestUtility",
			"",
			"service TestApi",
			"{",
			"\tdata One",
			"\t{",
			"\t}",
			"}",
			"");
	}

	[Test]
	public void TwoDtosSameName()
	{
		TestUtility.ParseInvalidTestApi("service TestApi { data One {} data One {} }")
			.Message.Should().Be("TestApi.fsd(1,31): Duplicate service member: One");
	}
}
