public void ConstructorWithRecordsetCellsExpectedAddsRecordsetCells()
 {
     var cells = new[]
     {
         new RecordsetCell(),
         new RecordsetCell()
     };
     var record = new RecordsetRecord(cells);
     Assert.AreEqual(2, record.Count);
     Assert.AreSame(cells[0], record[0]);
     Assert.AreSame(cells[1], record[1]);
 }
示例#2
0
        /// <summary>
        /// Sets the value of the field at the given field index in the given row.
        /// <remarks>
        /// A new row is added if <paramref name="record"/> is <code>null</code>.
        /// A new field is added if <paramref name="fieldIndex"/> is greater than or equal to <see cref="Fields"/> count.
        /// </remarks>
        /// </summary>
        /// <param name="record">The record to be updated; may be null.</param>
        /// <param name="fieldIndex">The index of the field to be updated.</param>
        /// <param name="value">The value.</param>
        public void SetValue(ref RecordsetRecord record, int fieldIndex, string value)
        {
            if (record == null)
            {
                record = NewRecord();
                Records.Add(record);
            }

            var cell = new RecordsetCell
            {
                Name  = record.Label + "." + Fields[fieldIndex].Alias,
                Label = Fields[fieldIndex].Alias,
                Value = value
            };

            if (fieldIndex >= record.Count)
            {
                record.Add(cell);
            }
            else
            {
                record[fieldIndex] = cell;
            }
        }
        /// <summary>
        /// Sets the value of the field at the given field index in the given row.
        /// <remarks>
        /// A new row is added if <paramref name="record"/> is <code>null</code>.
        /// A new field is added if <paramref name="fieldIndex"/> is greater than or equal to <see cref="Fields"/> count.
        /// </remarks>
        /// </summary>
        /// <param name="record">The record to be updated; may be null.</param>
        /// <param name="fieldIndex">The index of the field to be updated.</param>
        /// <param name="value">The value.</param>
        public void SetValue(ref RecordsetRecord record, int fieldIndex, string value)
        {
            if(record == null)
            {
                record = NewRecord();
                Records.Add(record);
            }

            var cell = new RecordsetCell
            {
                Name = record.Label + "." + Fields[fieldIndex].Alias,
                Label = Fields[fieldIndex].Alias,
                Value = value
            };
            if(fieldIndex >= record.Count)
            {
                record.Add(cell);
            }
            else
            {
                record[fieldIndex] = cell;
            }
        }
 public void AddWithNullExpectedThrowsArgumentNullException()
 {
     var record = new RecordsetRecord();
     record.Add(null);
 }
 public void ConstructorWithNoParametersExpectedCreatesEmpty()
 {
     var record = new RecordsetRecord();
     Assert.AreEqual(0, record.Count);
 }
 public void JsonSerializationExpectedIncludesLabel()
 {
     var record = new RecordsetRecord
     {
         Label = "TestRec(2)"
     };
     var random = new Random();
     for(var i = 0; i < 10; i++)
     {
         var colName = "Column" + (i + 1);
         record.Add(new RecordsetCell
         {
             Name = record.Label + "." + colName,
             Value = random.GenerateString(30, string.Empty, true)
         });
     }
     var jsonStr = JsonConvert.SerializeObject(record);
     dynamic jsonObj = JsonConvert.DeserializeObject(jsonStr);
     Assert.AreEqual(record.Label, jsonObj.Label.Value);
 }
 public void JsonSerializationExpectedDoesNotImplementIEnumerable()
 {
     var record = new RecordsetRecord();
     var enumerable = record as IEnumerable<RecordsetCell>;
     Assert.IsNull(enumerable);
 }
 public void ClearWithCellsExpectedRemovesCells()
 {
     var record = new RecordsetRecord(new[]
     {
         new RecordsetCell(),
         new RecordsetCell()
     });
     Assert.AreEqual(2, record.Count);
     record.Clear();
     Assert.AreEqual(0, record.Count);
 }
        public void AddWithRecordsetCellExpectedAddsRecordsetCell()
        {
            var record = new RecordsetRecord();
            var cell = new RecordsetCell();
            record.Add(cell);

            Assert.AreEqual(1, record.Count);
            Assert.AreSame(cell, record[0]);
        }