using DigitalData.Core.DTO;

namespace DigitalData.Core.Tests.DTO
{
	public class BaseDtoTest
	{
		public record SampleDto(int Id) : BaseDTO<int>(Id);

		[Test]
		public void EntitiesWithSameIdShouldBeEqual()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(1);

			Assert.That(dto2, Is.EqualTo(dto1));
		}

		[Test]
		public void EntitiesWithDifferentIdsShouldNotBeEqual()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(2);

			Assert.That(dto2, Is.Not.EqualTo(dto1));
		}

		[Test]
		public void GetHashCodeShouldReturnSameValueForEntitiesWithSameId()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(1);

			Assert.That(dto2.GetHashCode(), Is.EqualTo(dto1.GetHashCode()));
		}

		[Test]
		public void EqualsShouldReturnFalseForNull()
		{
			var dto = new SampleDto(1);

			Assert.IsFalse(dto.Equals(null));
		}

		[Test]
		public void EqualityOperatorShouldReturnTrueForSameReference()
		{
			var dto = new SampleDto(1);

			Assert.That(dto, Is.EqualTo(dto));
		}

		[Test]
		public void EqualityOperatorShouldReturnFalseForDifferentEntitiesWithDifferentIds()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(2);

			Assert.IsFalse(dto1 == dto2);
		}

		[Test]
		public void InequalityOperatorShouldReturnTrueForDifferentEntitiesWithDifferentIds()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(2);

			Assert.IsTrue(dto1 != dto2);
		}

		[Test]
		public void InequalityOperatorShouldReturnFalseForEntitiesWithSameId()
		{
			var dto1 = new SampleDto(1);
			var dto2 = new SampleDto(1);

			Assert.IsFalse(dto1 != dto2);
		}

		[Test]
		public void EntityWithSameIdShouldBeContained()
		{
			IEnumerable<SampleDto> dtos = new List<SampleDto>() { new(1), new(2) };
			var dto = new SampleDto(1);
			Assert.That(dtos, Does.Contain(dto));
		}

		[Test]
		public void EntityWithSameIdShouldBeNotContained()
		{
			IEnumerable<SampleDto> dtos = new List<SampleDto>() { new(1), new(2) };
			var dto = new SampleDto(3);
			Assert.That(dtos, !Does.Contain(dto));
		}
	}
}