コード例 #1
0
        public void Set_Existing_WithField_NonNullFriendlyName()
        {
            var dict = new CustomFieldDictionary {
                { TEST_FIELD }
            };
            IDictionary <string, AssetCustomField> dictRef = dict;

            dictRef[TEST_KEY] = TEST_FIELD2;
            Assert.Collection(dict.Keys, a => Assert.Equal(TEST_KEY, a));
            Assert.Collection(dict.Values, (AssetCustomField a) => {
                Assert.Equal(TEST_FRIENDLY_KEY, a.FriendlyName);
                Assert.Equal(TEST_KEY, a.Field);
                Assert.Null(a.Format);
                Assert.Equal(TEST_VALUE2, a.Value);
            });
            Assert.Equal(dict.Count, dict.Friendly.Count);
            Assert.False(dict.Friendly.ContainsKey(TEST_KEY));
            Assert.True(dict.Friendly.ContainsKey(TEST_FRIENDLY_KEY));
            Assert.Collection(dict.Friendly.Values, a => Assert.Equal(TEST_VALUE2, a));

            string value;

            Assert.True(dict.TryGetValue(TEST_KEY, out value));
            Assert.Equal(TEST_VALUE2, value);
            Assert.Equal(TEST_VALUE2, dict[TEST_KEY]);
            Assert.True(dict.Friendly.TryGetValue(TEST_FRIENDLY_KEY, out value));
            Assert.Equal(TEST_VALUE2, value);
            Assert.Equal(TEST_VALUE2, dict.Friendly[TEST_FRIENDLY_KEY]);

            Assert.False(dict.TryGetValue(TEST_VALUE2, out value));
        }
コード例 #2
0
        public void Set_New_WithString()
        {
            var dict = new CustomFieldDictionary();

            dict[TEST_KEY] = TEST_VALUE;
            Assert.Collection(dict.Keys, a => Assert.Equal(TEST_KEY, a));
            Assert.Collection(dict.Values, (AssetCustomField a) => {
                Assert.Equal(TEST_KEY, a.FriendlyName);
                Assert.Equal(TEST_KEY, a.Field);
                Assert.Null(a.Format);
                Assert.Equal(TEST_VALUE, a.Value);
            });
            Assert.Equal(dict.Count, dict.Friendly.Count);
            Assert.True(dict.Friendly.ContainsKey(TEST_KEY));
            Assert.Collection(dict.Friendly.Keys, a => Assert.Equal(TEST_KEY, a));
            Assert.Collection(dict.Friendly.Values, a => Assert.Equal(TEST_VALUE, a));

            string value;

            Assert.True(dict.TryGetValue(TEST_KEY, out value));
            Assert.Equal(TEST_VALUE, value);
            Assert.Equal(TEST_VALUE, dict[TEST_KEY]);
            Assert.True(dict.Friendly.TryGetValue(TEST_KEY, out value));
            Assert.Equal(TEST_VALUE, value);
            Assert.Equal(TEST_VALUE, dict.Friendly[TEST_KEY]);

            Assert.False(dict.TryGetValue(TEST_VALUE, out value));
        }
コード例 #3
0
        public void Add_WithField_UpdatesFriendlyNames()
        {
            var dict = new CustomFieldDictionary();
            IDictionary <string, AssetCustomField> dictRef = dict;

            dict.Add(TEST_FIELD);
            Assert.Collection(dict.Keys, a => Assert.Equal(TEST_KEY, a));
            Assert.Collection(dict.Values, (AssetCustomField a) => {
                Assert.Equal(TEST_FRIENDLY_KEY, a.FriendlyName);
                Assert.Equal(TEST_KEY, a.Field);
                Assert.Null(a.Format);
                Assert.Equal(TEST_VALUE, a.Value);
            });
            Assert.Equal(dict.Count, dict.Friendly.Count);
            Assert.False(dict.Friendly.ContainsKey(TEST_KEY));
            Assert.True(dict.Friendly.ContainsKey(TEST_FRIENDLY_KEY));
            Assert.Collection(dict.Friendly.Values, a => Assert.Equal(TEST_VALUE, a));

            string value;

            Assert.True(dict.TryGetValue(TEST_KEY, out value));
            Assert.Equal(TEST_VALUE, value);
            Assert.True(dict.Friendly.TryGetValue(TEST_FRIENDLY_KEY, out value));
            Assert.Equal(TEST_VALUE, value);
            Assert.Equal(TEST_VALUE, dict.Friendly[TEST_FRIENDLY_KEY]);

            Assert.False(dict.TryGetValue(TEST_VALUE, out value));

            var actual = dictRef[TEST_KEY];

            Assert.Equal(TEST_FRIENDLY_KEY, actual.FriendlyName);
            Assert.Equal(TEST_KEY, actual.Field);
            Assert.Null(actual.Format);
            Assert.Equal(TEST_VALUE, actual.Value);
        }