﻿using NUnit.Framework;

namespace MongoDB.Replica.Engine.Tests.Actors
{
    [TestFixture]
    public class ConnectionInfoTests
    {
        [Test]
        public void Ctor_Always_ShouldComposeConnectionInfoProperly()
        {
            var connectionInfo = new ConnectionInfo("connectionString", "databaseName", "collectionName");

            Assert.AreEqual("connectionString", connectionInfo.ConnectionString);
            Assert.AreEqual("databaseName", connectionInfo.DatabaseName);
            Assert.AreEqual("collectionName", connectionInfo.CollectionName);
        }

        [Test]
        public void GetHashCode_SameAttributes_ShouldReturnTheSameValue()
        {
            var connectionInfo1 = new ConnectionInfo("connectionString", "databaseName", "collectionName");
            var connectionInfo2 = new ConnectionInfo("connectionString", "databaseName", "collectionName");

            Assert.AreEqual(connectionInfo1.GetHashCode(), connectionInfo2.GetHashCode());
        }

        [Test]
        [TestCase("connectionString1", "connectionString2", "databaseName", "databaseName", "collectionName", "collectionName")]
        [TestCase("connectionString", "connectionString", "databaseName1", "databaseName2", "collectionName", "collectionName")]
        [TestCase("connectionString", "connectionString", "databaseName", "databaseName", "collectionName1", "collectionName2")]
        public void GetHashCode_DifferentAttributes_ShouldNotReturnTheSameValue(string connectionString1, string connectionString2,
            string databaseName1, string databaseName2,
            string collectionName1, string collectionName2)
        {
            var connectionInfo1 = new ConnectionInfo(connectionString1, databaseName1, collectionName1);
            var connectionInfo2 = new ConnectionInfo(connectionString2, databaseName2, collectionName2);

            Assert.AreNotEqual(connectionInfo1.GetHashCode(), connectionInfo2.GetHashCode());
        }
    }
}
