示例#1
0
        public void TestAddWay()
        {
            Way testWay = new Way();

            testWay.Id = -1;
            var source = new MemoryDataSource();

            source.AddWay(testWay);

            // test if the way is actually there.
            Assert.AreEqual(testWay, source.GetWay(-1));

            // test if the way was not remove after getting it.
            Assert.AreEqual(testWay, source.GetWays(new List <long>()
            {
                -1
            })[0]);

            // test if the way is in the list of ways.
            Assert.AreEqual(testWay, new List <Way>(source.GetWays())[0]);

            // test if the way will be retrieved using a list of ids.
            var ids = new List <long>();

            ids.Add(-1);
            IList <Way> ways = source.GetWays(ids);

            Assert.IsNotNull(ways);
            Assert.AreEqual(1, ways.Count);
            Assert.AreEqual(testWay, ways[0]);
        }
        /// <summary>
        /// Compares what is in the complete list against the objects in the reference source.
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        private void Compare(MemoryDataSource expected, List <ICompleteOsmGeo> actual)
        {
            var exectedList = new List <ICompleteOsmGeo>();

            foreach (var node in expected.GetNodes())
            {
                var completeNode = node;
                if (completeNode != null)
                {
                    exectedList.Add(completeNode);
                }
            }
            foreach (var way in expected.GetWays())
            {
                var completeWay = CompleteWay.CreateFrom(way, expected);
                if (completeWay != null)
                {
                    exectedList.Add(completeWay);
                }
            }
            foreach (var relation in expected.GetRelations())
            {
                var completeRelation = CompleteRelation.CreateFrom(relation, expected);
                if (completeRelation != null)
                {
                    exectedList.Add(completeRelation);
                }
            }

            ComparisonHelpers.CompareComplete(exectedList, actual);
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
        /// <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);
                    }
                }
            }
        }