using e_suite.API.Common.models;
using e_suite.Database.Core;
using Moq;
using NUnit.Framework;

namespace e_suite.API.Common.UnitTests;

[TestFixture]
public class PatchFactoryUnitTests
{
    [Test]
    public void Create_ReturnsPatchInstanceWithCorrectValue()
    {
        // Arrange
        var esuiteDatabaseDbContext = new Mock<IEsuiteDatabaseDbContext>();
        var factory = new PatchFactory(esuiteDatabaseDbContext.Object);
        var dto = new PatchUserProfile
        {
            FirstName = "Colin"
        };
        
        // Act
        var patch = factory.Create(dto);

        // Assert
        Assert.That(patch, Is.Not.Null);
        Assert.That(patch, Is.InstanceOf<IPatch<PatchUserProfile>>());

        // And verify the internal value is the same object
        var concrete = patch as Patch<PatchUserProfile>;
        Assert.That(concrete!.Value, Is.EqualTo(dto));
    }

    [Test]
    public void Create_ReturnsNewInstanceEachTime()
    {
        //Arrange
        var esuiteDatabaseDbContext = new Mock<IEsuiteDatabaseDbContext>();
        var factory = new PatchFactory(esuiteDatabaseDbContext.Object);
        var dto = new PatchUserProfile();
        
        //Act
        var p1 = factory.Create(dto);
        var p2 = factory.Create(dto);

        //Assert
        Assert.That(p1, Is.Not.SameAs(p2));
    }

}