Ejemplo n.º 1
0
        public void DictionaryColumn_Basics()
        {
            DictionaryColumn <string, string> scratch      = new DictionaryColumn <string, string>(new StringColumn(), new StringColumn());
            ColumnDictionary <string, string> defaultValue = ColumnDictionary <string, string> .Empty;

            ColumnDictionary <string, string> otherValue = SampleRow();

            otherValue.SetTo(new Dictionary <string, string>()
            {
                ["Name"] = "Scott",
                ["City"] = "Redmond"
            });

            Column.Basics <IDictionary <string, string> >(
                () => new DictionaryColumn <string, string>(
                    new DistinctColumn <string>(new StringColumn()),
                    new StringColumn()),
                defaultValue,
                otherValue,
                (i) =>
            {
                if (scratch[i].Count == 0)
                {
                    scratch[i][(i % 10).ToString()]       = i.ToString();
                    scratch[i][((i + 1) % 10).ToString()] = i.ToString();
                }

                return(scratch[i]);
            }
                );
        }
Ejemplo n.º 2
0
        protected WorksheetLayout()
        {
            m_Guid = System.Guid.NewGuid();

            // defaultColumnsStyles stores the default column Styles in a Hashtable
            m_DefaultColumnStyles = new System.Collections.Hashtable();

            // defaultPropertyColumnsStyles stores the default property column Styles in a Hashtable
            m_DefaultPropertyColumnStyles = new System.Collections.Hashtable();

            // m_ColumnStyles stores the column styles for each data column individually,
            m_ColumnStyles = new ColumnDictionary();


            // The style of the row header. This is the leftmost column that shows usually the row number.
            m_RowHeaderStyle = new RowHeaderStyle(); // holds the style of the row header (leftmost column of data grid)

            // The style of the column header. This is the upmost row that shows the name of the columns.
            m_ColumnHeaderStyle = new ColumnHeaderStyle(); // the style of the column header (uppermost row of datagrid)

            // The style of the property column header. This is the leftmost column in the left of the property columns,
            m_PropertyColumnHeaderStyle = new ColumnHeaderStyle();


            this.m_ShowPropertyColumns = true;
        }
Ejemplo n.º 3
0
        public void DictionaryColumn_Basics()
        {
            DictionaryColumn <string, string> scratch      = new DictionaryColumn <string, string>(new StringColumn(), new StringColumn(), Nullability.DefaultToEmpty);
            ColumnDictionary <string, string> defaultValue = ColumnDictionary <string, string> .Empty;

            ColumnDictionary <string, string> otherValue = SampleRow();
            Dictionary <string, string>       model      = new Dictionary <string, string>()
            {
                ["Name"] = "Scott",
                ["City"] = "Redmond"
            };

            otherValue.SetTo(model);

            // Test ColumnDictionary.Equals against non-ColumnDictionary IDictionary (slower compare path)
            Assert.True(otherValue.Equals(model));
            model["City"] = "Bellevue";
            Assert.False(otherValue.Equals(model));

            Column.Basics <IDictionary <string, string> >(
                () => new DictionaryColumn <string, string>(
                    new DistinctColumn <string>(new StringColumn()),
                    new StringColumn(),
                    Nullability.DefaultToEmpty),
                defaultValue,
                otherValue,
                (i) =>
            {
                if (scratch[i].Count == 0)
                {
                    scratch[i][(i % 10).ToString()]       = i.ToString();
                    scratch[i][((i + 1) % 10).ToString()] = i.ToString();
                }

                return(scratch[i]);
            }
                );

            defaultValue = null;
            Column.Basics <IDictionary <string, string> >(
                () => new DictionaryColumn <string, string>(
                    new DistinctColumn <string>(new StringColumn()),
                    new StringColumn(),
                    Nullability.DefaultToNull),
                defaultValue,
                otherValue,
                (i) =>
            {
                if (scratch[i].Count == 0)
                {
                    scratch[i][(i % 10).ToString()]       = i.ToString();
                    scratch[i][((i + 1) % 10).ToString()] = i.ToString();
                }

                return(scratch[i]);
            }
                );
        }
Ejemplo n.º 4
0
        public static ColumnDictionary <string, string> SampleRow()
        {
            DictionaryColumn <string, string> column = new DictionaryColumn <string, string>(
                new DistinctColumn <string>(new StringColumn(), null),
                new StringColumn(),
                nullByDefault: false);

            ColumnDictionary <string, string> first = (ColumnDictionary <string, string>)column[0];

            first["One"] = "One";
            first["Two"] = "Two";

            return((ColumnDictionary <string, string>)column[1]);
        }
Ejemplo n.º 5
0
        public static ColumnDictionary <string, string> SampleRow()
        {
            DictionaryColumn <string, string> column = new DictionaryColumn <string, string>(
                new DistinctColumn <string>(new StringColumn(), null),
                new StringColumn(),
                Nullability.NullsDisallowed);

            ColumnDictionary <string, string> first = (ColumnDictionary <string, string>)column[0];

            first["One"] = "One";
            first.Add("Two", "Two");

            return((ColumnDictionary <string, string>)column[1]);
        }
Ejemplo n.º 6
0
        public override IDictionary <TKey, TValue> this[int index]
        {
            get
            {
                CacheItem <ColumnDictionary <TKey, TValue> > item = _cache;
                if (item?.RowIndex != index)
                {
                    item   = new CacheItem <ColumnDictionary <TKey, TValue> >(index, ColumnDictionary <TKey, TValue> .Get(this, index));
                    _cache = item;
                }

                return(item.Value);
            }

            set
            {
                _cache = default;
                ColumnDictionary <TKey, TValue> .Set(this, index, value);
            }
        }
Ejemplo n.º 7
0
        public void ColumnDictionary_Basics()
        {
            string sampleName     = "Name";
            string sampleValue    = "Scott";
            string retrievedValue = null;

            string secondName  = "City";
            string secondValue = "Redmond";

            string unusedName = "Unused";

            Dictionary <string, string> expected = new Dictionary <string, string>();

            ColumnDictionary <string, string> row = DictionaryColumnTests.SampleRow();

            Assert.True(0 == ColumnDictionary <string, string> .Empty.Count);
            Assert.False(row.IsReadOnly);

            // Test Empty Dictionary
            Assert.False(row.TryGetValue(sampleName, out retrievedValue));
            Assert.False(row.ContainsKey(sampleName));
            Assert.False(row.Remove(sampleName));
            Assert.True(0 == row.Count);
            Assert.Empty(row.Keys);
            Assert.Empty(row.Values);

            // Add a single value and test results
            expected[sampleName] = sampleValue;
            row[sampleName]      = sampleValue;
            CollectionReadVerifier.VerifySame(expected, row);
            CollectionReadVerifier.VerifySame(expected.Keys, row.Keys);
            CollectionReadVerifier.VerifySame(expected.Values, row.Values);

            // Add a second value and verify
            expected.Add(secondName, secondValue);
            row.Add(new KeyValuePair <string, string>(secondName, secondValue));
            CollectionReadVerifier.VerifySame(expected, row);
            CollectionReadVerifier.VerifySame(expected.Keys, row.Keys);
            CollectionReadVerifier.VerifySame(expected.Values, row.Values);

            // Negative (missing item / already added item) cases
            Assert.True(false == row.Contains(new KeyValuePair <string, string>(sampleName, secondValue)));
            Assert.True(false == row.Contains(new KeyValuePair <string, string>(unusedName, sampleValue)));
            Assert.True(false == row.ContainsKey(unusedName));
            Assert.Throws <KeyNotFoundException>(() => row[unusedName]);
            Assert.Throws <ArgumentException>(() => row.Add(new KeyValuePair <string, string>(sampleName, secondValue)));

            // Change value and verify, then change back
            Assert.Equal(expected[sampleName], row[sampleName]);
            expected[sampleName] = secondValue;
            row[sampleName]      = secondValue;
            Assert.Equal(expected[sampleName], row[sampleName]);
            CollectionReadVerifier.VerifySame(expected, row);
            CollectionReadVerifier.VerifySame(expected.Keys, row.Keys);
            CollectionReadVerifier.VerifySame(expected.Values, row.Values);

            expected[sampleName] = sampleValue;
            row[sampleName]      = sampleValue;
            Assert.Equal(expected[sampleName], row[sampleName]);

            // Remove
            Assert.True(row.Remove(secondName));
            Assert.False(row.Remove(secondName));
            Assert.False(row.ContainsKey(secondName));
            Assert.False(row.Remove(new KeyValuePair <string, string>(unusedName, sampleValue)));
            Assert.False(row.Remove(new KeyValuePair <string, string>(sampleName, secondValue)));
            Assert.True(row.Remove(new KeyValuePair <string, string>(sampleName, sampleValue)));
            Assert.Empty(row);

            // SetTo
            row.SetTo(expected);
            CollectionReadVerifier.VerifySame <KeyValuePair <string, string> >(expected, row);

            // Create another Dictionary with the same values inserted in a different order
            ColumnDictionary <string, string> row2 = DictionaryColumnTests.SampleRow();

            row2[secondName] = secondValue;
            row2[sampleName] = sampleValue;

            // Test Equals and GetHashCode
            CollectionReadVerifier.VerifyEqualityMembers <ColumnDictionary <string, string> >(row, row2);

            // Test equality operators
            Assert.True(row == row2);
            Assert.False(row != row2);

            Assert.False(row == null);
            Assert.True(row != null);

            Assert.False(null == row);
            Assert.True(null != row);

            // GetHashCode handles null key/values safely
            row[null] = null;
            Assert.Equal(row.GetHashCode(), row2.GetHashCode());

            // Verify other collection manipulation
            // NOTE: Must use unique keys, because Add(KeyValuePair) will throw for a duplicate key
            CollectionChangeVerifier.VerifyCollection(row, (i) => new KeyValuePair <string, string>(i.ToString(), i.ToString()));

            if (!Debugger.IsAttached)
            {
                Assert.Throws <IndexOutOfRangeException>(() => ColumnDictionary <string, string> .Get(null, -1));
            }
        }
Ejemplo n.º 8
0
    protected WorksheetLayout()
    {
      m_Guid = System.Guid.NewGuid();

      // defaultColumnsStyles stores the default column Styles in a Hashtable
      m_DefaultColumnStyles = new System.Collections.Hashtable();

      // defaultPropertyColumnsStyles stores the default property column Styles in a Hashtable
      m_DefaultPropertyColumnStyles = new System.Collections.Hashtable();

      // m_ColumnStyles stores the column styles for each data column individually,
      m_ColumnStyles = new ColumnDictionary();


      // The style of the row header. This is the leftmost column that shows usually the row number.
      m_RowHeaderStyle = new RowHeaderStyle(); // holds the style of the row header (leftmost column of data grid)
  
      // The style of the column header. This is the upmost row that shows the name of the columns.
      m_ColumnHeaderStyle = new ColumnHeaderStyle(); // the style of the column header (uppermost row of datagrid)
  
      // The style of the property column header. This is the leftmost column in the left of the property columns,
      m_PropertyColumnHeaderStyle = new ColumnHeaderStyle();


      this.m_ShowPropertyColumns = true;
    }