Esempio n. 1
0
        public void TranslateEntryCanNotBeNull()
        {
            var sut = new ZipArchiveDbaseEntryTranslator <FakeDbaseRecord>(
                Encoding.Default,
                new FakeDbaseRecordTranslator());

            Assert.Throws <ArgumentNullException>(() => sut.Translate(null, TranslatedChanges.Empty));
        }
Esempio n. 2
0
        public void TranslatePassesExpectedDbaseRecordsToDbaseRecordValidator()
        {
            var schema     = new FakeDbaseSchema();
            var translator = new CollectDbaseRecordTranslator();
            var sut        = new ZipArchiveDbaseEntryTranslator <FakeDbaseRecord>(
                Encoding.UTF8,
                translator);
            var records = new []
            {
                new FakeDbaseRecord {
                    Field = { Value = 1 }
                },
                new FakeDbaseRecord {
                    Field = { Value = 2 }
                }
            };
            var date   = DateTime.Today;
            var header = new DbaseFileHeader(
                date,
                DbaseCodePage.Western_European_ANSI,
                new DbaseRecordCount(records.Length),
                schema);

            using (var stream = new MemoryStream())
            {
                using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
                {
                    var entry = archive.CreateEntry("entry");
                    using (var entryStream = entry.Open())
                        using (var writer = new BinaryWriter(entryStream, Encoding.UTF8))
                        {
                            header.Write(writer);
                            foreach (var record in records)
                            {
                                record.Write(writer);
                            }
                            writer.Write(DbaseRecord.EndOfFile);
                            entryStream.Flush();
                        }
                }
                stream.Flush();
                stream.Position = 0;

                using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true))
                {
                    var entry = archive.GetEntry("entry");

                    var result = sut.Translate(entry, TranslatedChanges.Empty);

                    Assert.Equal(TranslatedChanges.Empty, result, new TranslatedChangeEqualityComparer());
                    Assert.Equal(records, translator.Collected);
                }
            }
        }
Esempio n. 3
0
        public void TranslateChangesCanNotBeNull()
        {
            var sut = new ZipArchiveDbaseEntryTranslator <FakeDbaseRecord>(
                Encoding.Default,
                new FakeDbaseRecordTranslator());

            using (var stream = new MemoryStream())
                using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
                {
                    var entry = archive.CreateEntry("entry");
                    Assert.Throws <ArgumentNullException>(() => sut.Translate(entry, null));
                }
        }
Esempio n. 4
0
        public void TranslateReturnsExpectedResultWhenDbaseRecordTranslatorReturnsChanges()
        {
            var changes = TranslatedChanges.Empty
                          .Append(new Uploads.AddRoadNode(new RecordNumber(1), new RoadNodeId(1), RoadNodeType.FakeNode))
                          .Append(new Uploads.AddRoadNode(new RecordNumber(2), new RoadNodeId(2), RoadNodeType.FakeNode));
            var sut = new ZipArchiveDbaseEntryTranslator <FakeDbaseRecord>(
                Encoding.UTF8,
                new FakeDbaseRecordTranslator(ignored => changes));
            var date   = DateTime.Today;
            var header = new DbaseFileHeader(
                date,
                DbaseCodePage.Western_European_ANSI,
                new DbaseRecordCount(0),
                new FakeDbaseSchema());

            using (var stream = new MemoryStream())
            {
                using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
                {
                    var entry = archive.CreateEntry("entry");
                    using (var entryStream = entry.Open())
                        using (var writer = new BinaryWriter(entryStream, Encoding.UTF8))
                        {
                            header.Write(writer);
                            entryStream.Flush();
                        }
                }
                stream.Flush();
                stream.Position = 0;

                using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true))
                {
                    var entry = archive.GetEntry("entry");

                    var result = sut.Translate(entry, TranslatedChanges.Empty);

                    Assert.Equal(
                        changes,
                        result,
                        new TranslatedChangeEqualityComparer());
                }
            }
        }