/// <summary>
        /// Tests a few boundingbox queries.
        /// </summary>
        protected void TestBoundingBoxQueries()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget target = this.CreateDataStreamTarget();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));
            target.RegisterSource(source);
            target.Pull();

            IDataSourceReadOnly dataSource = this.CreateDataSource();
            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);

            // get reference data and compare to the real thing!
            GeoCoordinateBox box = memorySource.BoundingBox;
            IList<OsmGeo> referenceBoxData = memorySource.Get(box, null);
            IList<OsmGeo> boxData = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // increase box size and compare again.
            box = memorySource.BoundingBox.Resize(0.1);
            referenceBoxData = memorySource.Get(box, null);
            boxData = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.5);
            referenceBoxData = memorySource.Get(box, null);
            boxData = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.25);
            referenceBoxData = memorySource.Get(box, null);
            boxData = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.1);
            referenceBoxData = memorySource.Get(box, null);
            boxData = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);
        }
        public void PBFOsmStreamReaderReset()
        {
            // generate the source.
            var source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Test.Unittests.api.osm.pbf"));

            // pull the data out.
            var target = new OsmStreamTargetEmpty();
            target.RegisterSource(source);
            target.Pull();

            // reset the source.
            if (source.CanReset)
            {
                source.Reset();

                // pull the data again.
                target.Pull();
            }
        }
        /// <summary>
        /// Tests read/write and actual data file.
        /// </summary>
        protected void TestReadWriteData()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget target = this.CreateDataStreamTarget();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));
            target.RegisterSource(source);
            target.Pull();

            IDataSourceReadOnly dataSource = this.CreateDataSource();
            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);
            foreach (Node node in memorySource.GetNodes())
            {
                Node dbNode = dataSource.GetNode(node.Id.Value);
                this.CompareNodes(node, dbNode);
            }
            foreach (Way way in memorySource.GetWays())
            {
                Way dbWay = dataSource.GetWay(way.Id.Value);
                this.CompareWays(way, dbWay);
            }
            foreach (Relation relation in memorySource.GetRelations())
            {
                Relation dbRelation = dataSource.GetRelation(relation.Id.Value);
                this.CompareRelations(relation, dbRelation);
            }
        }
        /// <summary>
        /// Tests writing data and getting ways using it's nodes.
        /// </summary>
        protected void TestGetWaysForNode()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget target = this.CreateDataStreamTarget();
            target.Initialize();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));
            IDataSourceReadOnly dataSource = this.CreateDataSource();
            source.Initialize();
            while (source.MoveNext())
            {
                switch (source.Current().Type)
                {
                    case OsmGeoType.Way:
                        Way way = (source.Current() as Way);
                        target.AddWay(way);
                        target.Flush();

                        if (way.Nodes != null)
                        {
                            foreach (long nodeId in way.Nodes)
                            {
                                IList<Way> ways = dataSource.GetWaysFor(nodeId);
                                Assert.IsNotNull(ways);
                                Assert.IsTrue(ways.Count > 0);
                                List<Way> foundWays = new List<Way>(ways.Where<Way>(x => x.Id == way.Id));
                                Assert.AreEqual(1, foundWays.Count);
                            }
                        }
                        break;
                }
            }

            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);
            foreach (Way way in memorySource.GetWays())
            {
                if (way.Nodes != null)
                {
                    foreach (long nodeId in way.Nodes)
                    {
                        IList<Way> ways = dataSource.GetWaysFor(nodeId);
                        Assert.IsNotNull(ways);
                        Assert.IsTrue(ways.Count > 0);
                        List<Way> foundWays = new List<Way>(ways.Where<Way>(x => x.Id == way.Id));
                        Assert.AreEqual(1, foundWays.Count);
                    }
                }
            }
        }
        /// <summary>
        /// Tests writing data and getting relations using it's members.
        /// </summary>
        protected void TestGetRelationsForMember()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget target = this.CreateDataStreamTarget();
            target.Initialize();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));
            IDataSourceReadOnly dataSource = this.CreateDataSource();
            source.Initialize();
            while (source.MoveNext())
            {
                switch (source.Current().Type)
                {
                    case OsmGeoType.Relation:
                        Relation relation = (source.Current() as Relation);
                        target.AddRelation(relation);
                        target.Flush();

                        if (relation.Members != null)
                        {
                            foreach (var member in relation.Members)
                            {
                                OsmGeoType type = OsmGeoType.Node;
                                switch (member.MemberType.Value)
                                {
                                    case OsmGeoType.Node:
                                        type = OsmGeoType.Node;
                                        break;
                                    case OsmGeoType.Way:
                                        type = OsmGeoType.Way;
                                        break;
                                    case OsmGeoType.Relation:
                                        type = OsmGeoType.Relation;
                                        break;
                                }
                                IList<Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value);
                                Assert.IsNotNull(relations);
                                Assert.IsTrue(relations.Count > 0);
                                List<Relation> foundRelations = new List<Relation>(relations.Where<Relation>(x => x.Id == relation.Id));
                                Assert.AreEqual(1, foundRelations.Count);
                            }
                        }
                        break;
                }
            }

            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);
            foreach (Relation relation in memorySource.GetRelations())
            {
                if (relation.Members != null)
                {
                    foreach (var member in relation.Members)
                    {
                        OsmGeoType type = OsmGeoType.Node;
                        switch (member.MemberType.Value)
                        {
                            case OsmGeoType.Node:
                                type = OsmGeoType.Node;
                                break;
                            case OsmGeoType.Way:
                                type = OsmGeoType.Way;
                                break;
                            case OsmGeoType.Relation:
                                type = OsmGeoType.Relation;
                                break;
                        }
                        IList<Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value);
                        Assert.IsNotNull(relations);
                        Assert.IsTrue(relations.Count > 0);
                        List<Relation> foundRelations = new List<Relation>(relations.Where<Relation>(x => x.Id == relation.Id));
                        Assert.AreEqual(1, foundRelations.Count);
                    }
                }
                break;
            }
        }