コード例 #1
0
        public void TryGetValue_ShouldReturnBool_AndValueSetInOutParameter()
        {
            // Arrange
            var myDictionary = new AdvancedDictionary <string, string>(100);

            // Assert
            Assert.IsNotNull(myDictionary);

            // Action
            myDictionary.Add("MyKey", "MyValue");

            // Assert
            Assert.IsTrue(myDictionary.TryGetValue("MyKey", out string data));
            Assert.IsFalse(myDictionary.TryGetValue("InvalidKey", out string data2));
        }
コード例 #2
0
        public void Add_DictionaryWithMaxWeight_ShouldAddNewItem_RemoveOldest()
        {
            // Arrange
            var myDictionary = new AdvancedDictionary <string, string>(5);

            // Assert
            Assert.IsNotNull(myDictionary);

            // Action
            myDictionary.Add("MyKey1", "MyValue1");
            myDictionary.Add("MyKey2", "MyValue2");
            myDictionary.Add("MyKey3", "MyValue3");
            myDictionary.Add("MyKey4", "MyValue4");
            myDictionary.Add("MyKey5", "MyValue5");
            myDictionary.Add("MyKey6", "MyValue6");

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

            // Assert
            Assert.IsFalse(myDictionary.TryGetValue("MyKey1", out string data1));
            Assert.IsTrue(myDictionary.TryGetValue("MyKey6", out string data2));
        }