1 // Licensed to the Apache Software Foundation(ASF) under one
2 // or more contributor license agreements.See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
19 using System.Collections.Generic;
22 using Thrift.Collections;
24 namespace Client.Tests
27 static class TestDataFactory
29 public static CrazyNesting CreateCrazyNesting(int count = 10)
34 return new CrazyNesting()
36 Binary_field = CreateBytesArray(count),
37 List_field = CreateListField(count),
38 Set_field = CreateSetField(count),
39 String_field = string.Format("data level {0}", count)
43 private static THashSet<Insanity> CreateSetField(int count)
45 var retval = new THashSet<Insanity>();
46 for (var i = 0; i < count; ++i)
47 retval.Add(CreateInsanity(count));
51 private static Insanity CreateInsanity(int count)
55 UserMap = CreateUserMap(count),
56 Xtructs = CreateXtructs(count)
60 private static List<Xtruct> CreateXtructs(int count)
62 var retval = new List<Xtruct>();
63 for (var i = 0; i < count; ++i)
64 retval.Add(CreateXtruct(count));
68 private static Xtruct CreateXtruct(int count)
72 Byte_thing = (sbyte)(count % 128),
75 String_thing = string.Format("data level {0}", count)
79 private static Dictionary<Numberz, long> CreateUserMap(int count)
81 var retval = new Dictionary<Numberz, long>();
82 retval.Add(Numberz.ONE, count);
83 retval.Add(Numberz.TWO, count);
84 retval.Add(Numberz.THREE, count);
85 retval.Add(Numberz.FIVE, count);
86 retval.Add(Numberz.SIX, count);
87 retval.Add(Numberz.EIGHT, count);
91 private static List<Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>> CreateListField(int count)
93 var retval = new List<Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>>();
94 for (var i = 0; i < count; ++i)
95 retval.Add(CreateListFieldData(count));
99 private static Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>> CreateListFieldData(int count)
101 var retval = new Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>();
102 for (var i = 0; i < count; ++i)
103 retval.Add( CreateIntHashSet(count), CreateListFieldDataDict(count));
107 private static THashSet<int> CreateIntHashSet(int count)
109 var retval = new THashSet<int>();
110 for (var i = 0; i < count; ++i)
115 private static Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>> CreateListFieldDataDict(int count)
117 var retval = new Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>();
118 for (var i = 0; i < count; ++i)
119 retval.Add(i, CreateListFieldDataDictValue(count));
123 private static THashSet<List<Dictionary<Insanity, string>>> CreateListFieldDataDictValue(int count)
125 var retval = new THashSet<List<Dictionary<Insanity, string>>>();
126 for (var i = 0; i < count; ++i)
127 retval.Add( CreateListFieldDataDictValueList(count));
131 private static List<Dictionary<Insanity, string>> CreateListFieldDataDictValueList(int count)
133 var retval = new List<Dictionary<Insanity, string>>();
134 for (var i = 0; i < count; ++i)
135 retval.Add(CreateListFieldDataDictValueListDict(count));
139 private static Dictionary<Insanity, string> CreateListFieldDataDictValueListDict(int count)
141 var retval = new Dictionary<Insanity, string>();
142 retval.Add(CreateInsanity(count), string.Format("data level {0}", count));
146 private static byte[] CreateBytesArray(int count)
148 var retval = new byte[count];
149 for (var i = 0; i < count; ++i)
150 retval[i] = (byte)(i % 0xFF);