public void ValidateReturnsExpectedResultWhenShapeRecordValidatorReturnsErrors()
        {
            var problems = new FileProblem[]
            {
                new FileError("file1", "error1", new ProblemParameter("parameter1", "value1")),
                new FileWarning("file2", "error2", new ProblemParameter("parameter2", "value2"))
            };
            var sut = new ZipArchiveShapeEntryValidator(
                Encoding.UTF8,
                new FakeShapeRecordValidator(problems));
            var header = new ShapeFileHeader(
                ShapeFileHeader.Length,
                ShapeType.Point,
                BoundingBox3D.Empty);

            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.Validate(entry);

                    Assert.Equal(
                        ZipArchiveProblems.None.AddRange(problems),
                        result);
                }
            }
        }
        public void ValidatePassesExpectedShapeRecordsToShapeRecordValidator()
        {
            var validator = new CollectShapeRecordValidator();
            var sut       = new ZipArchiveShapeEntryValidator(Encoding.UTF8, validator);
            var records   = _fixture.CreateMany <ShapeRecord>(2).ToArray();
            var fileSize  = records.Aggregate(ShapeFileHeader.Length, (length, record) => length.Plus(record.Length));
            var header    = new ShapeFileHeader(
                fileSize,
                ShapeType.Point,
                BoundingBox3D.Empty);

            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);
                            }

                            entryStream.Flush();
                        }
                }

                stream.Flush();
                stream.Position = 0;

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

                    var result = sut.Validate(entry);

                    Assert.Equal(ZipArchiveProblems.None, result);
                    Assert.Equal(records, validator.Collected, new ShapeRecordEqualityComparer());
                }
            }
        }
        public void TranslateReturnsExpectedResultWhenShapeRecordTranslatorReturnsChanges()
        {
            var changes = TranslatedChanges.Empty
                          .Append(new Uploads.AddRoadNode(new RecordNumber(1), new RoadNodeId(1), RoadNodeType.RealNode))
                          .Append(new Uploads.AddRoadNode(new RecordNumber(1), new RoadNodeId(1), RoadNodeType.RealNode));
            var sut = new ZipArchiveShapeEntryTranslator(
                Encoding.UTF8,
                new FakeShapeRecordTranslator(ignored => changes));
            var header = new ShapeFileHeader(
                ShapeFileHeader.Length,
                ShapeType.Point,
                BoundingBox3D.Empty);

            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());
                }
            }
        }