Пример #1
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);
        }
Пример #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 Set_Existing_WithField_NullFriendlyNameAndField()
        {
            var dict = new CustomFieldDictionary {
                { TEST_FIELD }
            };
            IDictionary <string, AssetCustomField> dictRef = dict;

            dictRef[TEST_KEY] = new AssetCustomField
            {
                FriendlyName = null,
                Format       = null,
                Field        = null,
                Value        = TEST_VALUE2
            };
            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_VALUE2, a.Value);
            });
            Assert.Equal(dict.Count, dict.Friendly.Count);
            Assert.True(dict.Friendly.ContainsKey(TEST_KEY));
            Assert.False(dict.Friendly.ContainsKey(TEST_FRIENDLY_KEY));
            Assert.Collection(dict.Friendly.Values, a => Assert.Equal(TEST_VALUE2, a));
        }
Пример #4
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));
        }
Пример #5
0
        public void Add_WithField_DoesNotAcceptNullKey()
        {
            var dict    = new CustomFieldDictionary();
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            Assert.Throws <ArgumentNullException>(() => dict.Add(null, TEST_VALUE));
            Assert.Throws <ArgumentNullException>(() => dictRef.Add(null, TEST_FIELD));
            Assert.DoesNotContain(null, new List <string>(dict.Friendly.Keys));
        }
Пример #6
0
        public void Set_FriendlyNameCollision_ThrowsArgumentException()
        {
            var dict = new CustomFieldDictionary {
                { TEST_FIELD }
            };

            // this throws because TEST_FIELD has the key TEST_KEY and the friendly name TEST_FRIENDLY_KEY,
            // and we're adding a field with the same friendly name but the key TEST_FRIENDLY_KEY
            Assert.Throws <ArgumentException>(() => dict[TEST_FRIENDLY_KEY] = TEST_VALUE2);
        }
Пример #7
0
        public void New_IsEmpty()
        {
            var dict = new CustomFieldDictionary();

            Assert.Empty(dict);
            Assert.Empty(dict.Models);
            Assert.Same(dict, dict.Models);
            Assert.Empty(dict.StringValues);
            Assert.Empty(dict.Friendly);
        }
Пример #8
0
        public void Set_WithString_DoesNotAcceptNullValue()
        {
            var dict = new CustomFieldDictionary
            {
                [TEST_KEY] = TEST_VALUE
            };

            Assert.Throws <ArgumentNullException>(() => dict[TEST_KEY] = null);
            Assert.DoesNotContain(null, new List <string>(dict.Friendly.Values));
        }
Пример #9
0
        public void Add_WithField_DoesNotAcceptDuplicateKey()
        {
            var dict = new CustomFieldDictionary
            {
                [TEST_KEY] = TEST_VALUE
            };
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            Assert.Throws <ArgumentException>(() => dictRef.Add(TEST_KEY, dictRef[TEST_KEY]));
        }
Пример #10
0
        public void Add_WithField_DoesNotAcceptNullValue()
        {
            var dict    = new CustomFieldDictionary();
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            Assert.Throws <ArgumentNullException>(() => dict.Add(null));
            Assert.Throws <ArgumentNullException>(() => dict.Add(new AssetCustomField {
                Field = null
            }));
            Assert.Throws <ArgumentNullException>(() => dictRef.Add(TEST_KEY, null));
        }
Пример #11
0
        public void Add_WithField_DoesNotAcceptWhereFieldPropertyIsNotNullAndDoesNotMatchKey()
        {
            var dict    = new CustomFieldDictionary();
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            Assert.Throws <ArgumentException>(() => dictRef.Add(TEST_KEY, new AssetCustomField
            {
                Field        = TEST_FRIENDLY_KEY,
                FriendlyName = TEST_FRIENDLY_KEY,
                Format       = null,
                Value        = TEST_VALUE2
            }));
        }
Пример #12
0
        public void Add_WithField_DoesAcceptWhereFieldPropertyIsNull()
        {
            var dict    = new CustomFieldDictionary();
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            dictRef.Add(TEST_KEY, new AssetCustomField
            {
                Field        = null,
                FriendlyName = TEST_FRIENDLY_KEY,
                Format       = null,
                Value        = TEST_VALUE2
            });
            Assert.Single(dict);
            Assert.Equal(TEST_VALUE2, dict[TEST_KEY]);
        }
Пример #13
0
        public void Add_WithField_DoesNotAcceptDuplicateFriendlyName()
        {
            var dict = new CustomFieldDictionary {
                {
                    new AssetCustomField
                    {
                        Field        = TEST_KEY,
                        FriendlyName = TEST_FRIENDLY_KEY,
                        Format       = null,
                        Value        = TEST_VALUE
                    }
                }
            };
            var dictRef = (IDictionary <string, AssetCustomField>)dict;

            Assert.Throws <ArgumentException>(() => dictRef.Add(TEST_FRIENDLY_KEY, new AssetCustomField
            {
                Field        = TEST_FRIENDLY_KEY,
                FriendlyName = TEST_FRIENDLY_KEY,
                Format       = null,
                Value        = TEST_VALUE2
            }));
        }
Пример #14
0
        public void NotReadOnly()
        {
            var dict = new CustomFieldDictionary();

            Assert.False(dict.IsReadOnly);
        }
Пример #15
0
 internal FriendlyNameDictionary(CustomFieldDictionary dictionary)
 {
     CustomFields = dictionary;
 }