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