/// <summary> /// Returns <see cref="List{T}"/> of all <see cref="IFakeRow"/>s which meets the given condition. /// </summary> /// <param name="source"> Input <see cref="IFakeTable"/>. </param> /// <param name="condition"> Input condition. </param> /// <returns></returns> public static List <IFakeRow> Where(this IFakeTable source, Func <IFakeRow, bool> condition) { return(Where(source, new List <Func <IFakeRow, bool> >() { condition })); }
public IFakeTable AddTable(string tableName) { this.Add(new FakeTableXml(this, tableName)); IFakeTable table = this[tableName]; return(table); }
/// <summary> /// Returns <see cref="List{T}"/> of all <see cref="IFakeRow"/>s which meets the given conditions. /// </summary> /// <param name="source"> Input <see cref="IFakeTable"/>. </param> /// <param name="conditions"> Input conditions. </param> /// <returns></returns> public static List <IFakeRow> Where(this IFakeTable source, IEnumerable <Func <IFakeRow, bool> > conditions) { if (conditions == null && !conditions.Any()) { throw new ArgumentNullException(nameof(conditions), "You must specify at least one condition which will be use to get elements."); } List <IFakeRow> results = new List <IFakeRow>(); foreach (var row in source.Rows.ToList()) { bool shouldBeAdded = true; foreach (var condition in conditions) { if (!condition.Invoke(row)) { shouldBeAdded = false; break; } } if (shouldBeAdded) { results.Add(row); } } return(results); }
public FakeColumn(IFakeTable table, string columnName, Type columnObjectType) { this.Table = table; this.Name = columnName; this.Type = columnObjectType; this.objects = new Dictionary <int, object>(); }
public virtual IFakeTable this[string tableName] { get { IFakeTable table = this.Tables.Where(tab => tab.Name.Equals(tableName)).FirstOrDefault(); return(table); } set { this.AddTable(tableName); } }
public void Add(IFakeTable item) { string xml = XmlUtils.Parse(item); string path = Path.Combine(this.DirectoryPath, $"{ item.Name }.xml"); using (StreamWriter writer = File.CreateText(path)) { writer.Write(xml); writer.Flush(); writer.Close(); } }
public IFakeTable this[string tableName] { get { IFakeTable table = this.GetTable(tableName); return(table); } set { this.RemoveTable(tableName); this.Add(value); } }
/// <summary> /// Returns <see cref="List{T}"/> which contains <see cref="IFakeJoinedRow"/>s /// which were made by adding <see cref="IFakeRow"/> to this <see cref="IFakeJoinedRow"/>. /// This is in form of <see cref="List{T}"/> because multiple <see cref="IFakeRow"/>s could have value in specified <see cref="IFakeColumn"/> equal with this <see cref="IFakeJoinedRow"/>. /// </summary> /// <param name="source"></param> /// <param name="table"></param> /// <param name="columnName"></param> /// <returns></returns> public static List <IFakeJoinedRow> JoinRow(this IFakeJoinedRow source, IFakeTable table, string columnName) { List <IFakeJoinedRow> list = new List <IFakeJoinedRow>(); table.Rows.ForEach(row => { if (source.CanJoinRow(row, columnName)) { list.Add(source.JoinToNew(row.ToJoinedRow())); } }); return(list); }
/// <summary> /// Parses <see cref="IFakeTable"/> to it's XML representative. /// </summary> /// <param name="item"></param> /// <returns></returns> internal static string Parse(IFakeTable item) { StringBuilder builder = new StringBuilder(); foreach (IFakeRow row in item.Rows) { builder.Append($"<Row>"); foreach (IFakeColumn column in item.Columns) { object columnValue = row[column.Name]; builder.Append($"<Column name=\"{ column.Name }\" value=\"{ columnValue }\" type=\"{ column.Type }\" />"); } builder.Append($"</Row>"); } string xml = builder.ToString(); return(xml); }
public IFakeTable GetOrAddTable(IFakeTable fakeTable) { return Tables.GetOrAdd(fakeTable.GetType(), fakeTable); }
public virtual bool Remove(IFakeTable item) { return(this.Cast().Remove(item)); }
public IFakeTable GetTable(string tableName) { IFakeTable table = this.Tables.Where(tab => tab.Name.Equals(tableName)).FirstOrDefault(); return(table); }
public virtual void Add(IFakeTable item) { this.Cast().Add(item); }
public bool Remove(IFakeTable item) { this.RemoveTable(item.Name); return(true); }
public bool Contains(IFakeTable item) { bool ret = this.Tables.Where(file => file.Name.Equals(item.Name)).Any(); return(ret); }
public virtual bool Contains(IFakeTable item) { return(this.Cast().Contains(item)); }
public FakeRow(IFakeTable fakeTable, int index) { this.Table = fakeTable; this.Index = index; }