示例#1
0
 /// <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
     }));
 }
示例#2
0
        public IFakeTable AddTable(string tableName)
        {
            this.Add(new FakeTableXml(this, tableName));
            IFakeTable table = this[tableName];

            return(table);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        public FakeColumn(IFakeTable table, string columnName, Type columnObjectType)
        {
            this.Table = table;
            this.Name  = columnName;
            this.Type  = columnObjectType;

            this.objects = new Dictionary <int, object>();
        }
示例#5
0
 public virtual IFakeTable this[string tableName]
 {
     get
     {
         IFakeTable table = this.Tables.Where(tab => tab.Name.Equals(tableName)).FirstOrDefault();
         return(table);
     }
     set
     {
         this.AddTable(tableName);
     }
 }
示例#6
0
        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();
            }
        }
示例#7
0
 public IFakeTable this[string tableName]
 {
     get
     {
         IFakeTable table = this.GetTable(tableName);
         return(table);
     }
     set
     {
         this.RemoveTable(tableName);
         this.Add(value);
     }
 }
示例#8
0
        /// <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);
        }
示例#9
0
        /// <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);
        }
示例#10
0
文件: FakeDb.cs 项目: snielsson/Ssn
 public IFakeTable GetOrAddTable(IFakeTable fakeTable)
 {
     return Tables.GetOrAdd(fakeTable.GetType(), fakeTable);
 }
示例#11
0
 public virtual bool Remove(IFakeTable item)
 {
     return(this.Cast().Remove(item));
 }
示例#12
0
        public IFakeTable GetTable(string tableName)
        {
            IFakeTable table = this.Tables.Where(tab => tab.Name.Equals(tableName)).FirstOrDefault();

            return(table);
        }
示例#13
0
 public virtual void Add(IFakeTable item)
 {
     this.Cast().Add(item);
 }
示例#14
0
 public bool Remove(IFakeTable item)
 {
     this.RemoveTable(item.Name);
     return(true);
 }
示例#15
0
        public bool Contains(IFakeTable item)
        {
            bool ret = this.Tables.Where(file => file.Name.Equals(item.Name)).Any();

            return(ret);
        }
示例#16
0
 public virtual bool Contains(IFakeTable item)
 {
     return(this.Cast().Contains(item));
 }
示例#17
0
 public FakeRow(IFakeTable fakeTable, int index)
 {
     this.Table = fakeTable;
     this.Index = index;
 }