public static void Test_ReferenceDictionary_Constructor_Size([Range(1, 20)] int size)
        {
            //arrange
            var map = new EngineObjectReferenceDictionary <IEngineObject, object>(size);

            //act
            FieldInfo info = map.GetType().BaseType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                             .FirstOrDefault(x => x.Name.Contains("bucket"));

            //assert
            //This will use reflection to get the collection size under the hood.
            Assert.AreEqual(GetPrime(size), ((int[])info.GetValue(map)).Count());
        }
        public static void Test_ReferenceDictionary_Register()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            bool result = map.Register(testEngineObject, testObject);

            //assert
            Assert.IsTrue(result);
            Assert.IsTrue(map.ContainsKey(testEngineObject));
            Assert.AreEqual(testObject, map[testEngineObject]);

            //not in the dictionary so it should throw
            Assert.Throws <KeyNotFoundException>(() => { var o = map[Mock.Of <IEngineObject>()]; });
            Assert.IsFalse(map.ContainsKey(Mock.Of <IEngineObject>()));            //shouldn't contain some new key value. Might fail due to Moq setup.
        }
        public static void Test_ReferenceDictionary_TryLookup()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            map.Register(testEngineObject, testObject);

            //assert
            Assert.AreEqual(testObject, map.TryLookup(testEngineObject));
            Assert.AreNotEqual(testObject, map.TryLookup(Mock.Of <IEngineObject>()));
            Assert.IsNull(map.TryLookup(Mock.Of <IEngineObject>()));

            Assert.Throws <ArgumentNullException>(() => map.TryLookup(null));
            Assert.Throws <ArgumentNullException>(() => map.Register(null, testObject));
            Assert.Throws <ArgumentNullException>(() => map.Register(testEngineObject, null));
            Assert.Throws <ArgumentNullException>(() => map.Register(null, null));
        }
        public static void Test_ReferenceDictionary_Unregister()
        {
            //arrange
            IEngineObject testEngineObject = SetupEquatableIsEqualToSelfInstance <IEngineObject>();
            object        testObject       = new object();
            var           map = new EngineObjectReferenceDictionary <IEngineObject, object>();

            //act
            map.Register(testEngineObject, testObject);
            var result       = map.TryUnregister(testEngineObject);
            var failedResult = map.TryUnregister(testEngineObject);

            //assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Value, testObject);

            //check the intentional failed result
            Assert.IsFalse(failedResult.Success);
            Assert.IsNull(failedResult.Value);
        }