using eSuite.Core.Miscellaneous;
using NUnit.Framework;

namespace eSuite.Core.UnitTests
{
    [TestFixture]
    public class GeneralIdRefUnitTests
    {
        [Test]
        public void GeneralIdRef_WhenHaveGuid_CanSetValue()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Guid = testGuid
            };

            //Assert
            Assert.That(generalIdRef.Guid, Is.EqualTo(testGuid));
        }

        [Test]
        public void GeneralIdRef_WhenHaveId_CanSetValue()
        {
            //Arrange
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            { 
                Id = expectedId
            };

            //Assert
            Assert.That(generalIdRef.Id, Is.EqualTo(expectedId));
        }

        [Test]
        public void GeneralIdRef_WhenHaveGuidAndId_CanSetValues()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            //Assert
            Assert.That(generalIdRef.Id, Is.EqualTo(expectedId));
            Assert.That(generalIdRef.Guid, Is.EqualTo(testGuid));
        }

        [Test]
        public void GeneralIdRef_WhenTwoGeneralIdRefsHaveSameGuidAndId_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenTwoGeneralIdRefsHaveSameGuidOnly_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenTwoGeneralIdRefsHaveSameIdOnly_AreEqual()
        {
            //Arrange
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenFirstSuppliesBothButSecondOnlyId_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = null
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenFirstSuppliesBothButSecondOnlyGuid_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = null,
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenFirstSuppliesIdAndSecondBoth_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = null
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenFirstSuppliesGuidButSecondBoth_AreEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = null,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.True);
        }

        [Test]
        public void GeneralIdRef_WhenIdsMatchButGuidsDont_AreNotEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = new Guid("{1352575E-F476-4268-84B8-C550B8F34355}")
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.False);
        }

        [Test]
        public void GeneralIdRef_WhenGuidsMatchButIdsDont_AreNotEqual()
        {
            //Arrange
            var testGuid = new Guid("{28CC619B-0479-4F5D-87B8-EE255763A783}");
            const int expectedId = 69;

            //Act
            var generalIdRef = new GeneralIdRef
            {
                Id = 72,
                Guid = testGuid
            };

            var generalIdRef2 = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            //Act
            var result = generalIdRef2.Equals(generalIdRef);

            //Assert
            Assert.That(result, Is.False);
        }

        [Test]
        public void GeneralIdRef_GetHashCode_ReturnsExpectedValue()
        {
            //Arrange
            var testGuid = new Guid("135b64dd-8f99-42df-afc0-7708f76fc7a2");
            const int expectedId = 192;

            var expectedHashCode = HashCode.Combine(expectedId, testGuid);


            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };
            //Act
            var hashCode = generalIdRef.GetHashCode();

            //Assert
            Assert.That(hashCode, Is.EqualTo(expectedHashCode));
        }

        [Test]
        public void GeneralIdRef_EqualsString_ReturnsFalse()
        {
            //Arrange
            var testGuid = new Guid("135b64dd-8f99-42df-afc0-7708f76fc7a2");
            const int expectedId = 192;

            var generalIdRef = new GeneralIdRef
            {
                Id = expectedId,
                Guid = testGuid
            };

            var testSubject = "string";
            //Act
            var result = generalIdRef.Equals(testSubject);

            //Assert
            Assert.That(result, Is.False);
        }
    }
}
