public void TestTypeWriter_WriteAnonymous()
        {
            var people = from id in Enumerable.Range(0, 1)
                         select new
                         {
                             Id = id,
                             Name = "Bob " + id,
                             Created = new DateTime(2013, 1, 19)
                         };
            var mapper = FixedLengthTypeMapper.DefineWriter(people);
            mapper.Property(p => p.Id, 10).ColumnName("id");
            mapper.Property(p => p.Name, 100).ColumnName("name");
            mapper.Property(p => p.Created, 8).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd");

            using (MemoryStream stream = new MemoryStream())
            {
                var options = new FixedLengthOptions() { FillCharacter = '@', RecordSeparator = "\n" };
                mapper.Write(stream, options);

                stream.Position = 0;  // go back to the beginning of the stream

                FixedLengthSchema schema = mapper.GetSchema();
                FlatFileReader reader = new FlatFileReader(new FixedLengthReader(stream, schema, options));
                Assert.IsTrue(reader.Read(), "The writer did not write the entities.");
                int id = reader.GetInt32(0);
                string name = reader.GetString(1);
                DateTime created = reader.GetDateTime(2);
                Assert.AreEqual(people.First().Id, id, "The ID value was not persisted.");
                Assert.AreEqual(people.First().Name, name, "The Name value was not persisted.");
                Assert.AreEqual(people.First().Created, created, "The Created value was not persisted.");
                Assert.IsFalse(reader.Read(), "The writer wrote too many records.");
            }
        }
Exemple #2
0
 public ContinentFixture()
 {
     Floors = FlatFileReader.Read("Data/continents_1_floors.json.gz")
              .Concat(FlatFileReader.Read("Data/continents_2_floors.json.gz"))
              .ToList()
              .AsReadOnly();
 }
        public void TestTypeWriter_AnonymousType()
        {
            var people = from id in Enumerable.Range(0, 1)
                         select new
            {
                Id      = id,
                Name    = "Bob " + id,
                Created = new DateTime(2013, 1, 19)
            };
            var mapper = SeparatedValueTypeMapper.DefineWriter(people);

            mapper.Property(p => p.Id).ColumnName("id");
            mapper.Property(p => p.Name).ColumnName("name");
            mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd");

            using (MemoryStream stream = new MemoryStream())
            {
                var options = new SeparatedValueOptions()
                {
                    IsFirstRecordSchema = true, Separator = "\t"
                };

                mapper.Write(stream, options);

                stream.Position = 0;  // go back to the beginning of the stream

                SeparatedValueSchema schema = mapper.GetSchema();
                FlatFileReader       reader = new FlatFileReader(new SeparatedValueReader(stream, schema, options));
                Assert.IsTrue(reader.Read(), "The writer did not write the entities.");
                int      id      = reader.GetInt32(0);
                string   name    = reader.GetString(1);
                DateTime created = reader.GetDateTime(2);
                Assert.AreEqual(people.First().Id, id, "The ID value was not persisted.");
                Assert.AreEqual(people.First().Name, name, "The Name value was not persisted.");
                Assert.AreEqual(people.First().Created, created, "The Created value was not persisted.");
                Assert.IsFalse(reader.Read(), "The writer wrote too many records.");
            }
        }
Exemple #4
0
 public AchievementFixture()
 {
     Achievements = FlatFileReader.Read("Data/achievements.json.gz").ToList().AsReadOnly();
 }
 public ItemPriceFixture()
 {
     ItemPrices = FlatFileReader.Read("Data/prices.json.gz").ToList().AsReadOnly();
 }
 public OrderBookFixture()
 {
     ItemPrices = FlatFileReader.Read("Data/listings.json.gz").ToList().AsReadOnly();
 }
Exemple #7
0
 public ItemFixture()
 {
     Items = FlatFileReader.Read("Data/items.json.gz").ToList().AsReadOnly();
 }
Exemple #8
0
 public SkinFixture()
 {
     Skins = FlatFileReader.Read("Data/skins.json.gz").ToList().AsReadOnly();
 }
Exemple #9
0
 public RecipeFixture()
 {
     Recipes = FlatFileReader.Read("Data/recipes.json.gz").ToList().AsReadOnly();
 }