/// <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); ComparisonHelpers.CompareSimple(node, dbNode); } foreach (Way way in memorySource.GetWays()) { Way dbWay = dataSource.GetWay(way.Id.Value); ComparisonHelpers.CompareSimple(way, dbWay); } foreach (Relation relation in memorySource.GetRelations()) { Relation dbRelation = dataSource.GetRelation(relation.Id.Value); ComparisonHelpers.CompareSimple(relation, dbRelation); } }
/// <summary> /// Compares the two collection to check if they contain the same objects. /// </summary> /// <param name="expected"></param> /// <param name="found"></param> private void CompareResults(IList <OsmGeo> expected, IList <OsmGeo> found) { //Assert.AreEqual(expected.Count, found.Count); Dictionary <string, OsmGeo> referenceBoxDataIndex = new Dictionary <string, OsmGeo>(); foreach (OsmGeo osmGeo in expected) { referenceBoxDataIndex.Add(string.Format("{0}:{1}", osmGeo.Type.ToString(), osmGeo.Id.Value), osmGeo); } foreach (OsmGeo osmGeo in found) { string refString = string.Format("{0}:{1}", osmGeo.Type.ToString(), osmGeo.Id.Value); OsmGeo refOsmGeo; if (referenceBoxDataIndex.TryGetValue(refString, out refOsmGeo)) { Assert.IsNotNull(refOsmGeo); switch (osmGeo.Type) { case OsmGeoType.Node: ComparisonHelpers.CompareSimple(refOsmGeo as Node, osmGeo as Node); break; case OsmGeoType.Way: ComparisonHelpers.CompareSimple(refOsmGeo as Way, osmGeo as Way); break; case OsmGeoType.Relation: ComparisonHelpers.CompareSimple(refOsmGeo as Relation, osmGeo as Relation); break; } } else { Assert.Fail("Reference data not found!"); } } }
/// <summary> /// Tests read/writing a relation. /// </summary> protected void TestRelationReadWrite() { this.NotifyEmptyExpected(); // empty test database. // create a test-relation. Relation relation = new Relation(); relation.Id = 1; // create a target, add the relation, create a source and verify relation in db. var target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); var dataSource = this.CreateDataSource(); Relation foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; relation.Visible = true; // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; relation.Visible = true; relation.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; relation.Visible = true; relation.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); relation.Tags = new TagsCollection(); relation.Tags.Add("tag", "value"); // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; relation.Visible = true; relation.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); relation.Members = new List <RelationMember>(); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = "node1", MemberType = OsmGeoType.Node }); relation.Members.Add(new RelationMember() { MemberId = 2, MemberRole = "node2", MemberType = OsmGeoType.Node }); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = "node1", MemberType = OsmGeoType.Node }); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = "way", MemberType = OsmGeoType.Way }); // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); this.NotifyEmptyExpected(); // empty test database. // create a test-relation. relation = new Relation(); relation.Id = 1; relation.UserName = "******"; relation.UserId = 10; relation.Version = 1; relation.Visible = true; relation.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); relation.Members = new List <RelationMember>(); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = string.Empty, MemberType = OsmGeoType.Node }); // create a target, add the relation, create a source and verify relation in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddRelation(relation); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundRelation = dataSource.GetRelation(1); ComparisonHelpers.CompareSimple(relation, foundRelation); }
/// <summary> /// Tests read/writing a node. /// </summary> protected void TestNodeReadWrite() { this.NotifyEmptyExpected(); // empty test database. // create a test-node. Node node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; // create a target, add the node, create a source and verify node in db. var target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); var dataSource = this.CreateDataSource(); Node foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; node.UserId = 10; // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; node.UserId = 10; node.Version = 1; // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; node.UserId = 10; node.Version = 1; node.Visible = true; // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; node.UserId = 10; node.Version = 1; node.Visible = true; node.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); this.NotifyEmptyExpected(); // empty test database. // create a test-node. node = new Node(); node.Id = 1; node.Latitude = 51.0; node.Longitude = 4.0; node.UserName = "******"; node.UserId = 10; node.Version = 1; node.Visible = true; node.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); node.Tags = new TagsCollection(); node.Tags.Add("tag", "value"); // create a target, add the node, create a source and verify node in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddNode(node); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundNode = dataSource.GetNode(1); ComparisonHelpers.CompareSimple(node, foundNode); }
/// <summary> /// Tests read/writing a way. /// </summary> protected void TestWayReadWrite() { this.NotifyEmptyExpected(); // empty test database. // create a test-way. Way way = new Way(); way.Id = 1; // create a target, add the way, create a source and verify way in db. var target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); var dataSource = this.CreateDataSource(); Way foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; way.Version = 1; // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; way.Version = 1; way.Visible = true; // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; way.Version = 1; way.Visible = true; way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; way.Version = 1; way.Visible = true; way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); way.Tags = new TagsCollection(); way.Tags.Add("tag", "value"); // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); this.NotifyEmptyExpected(); // empty test database. // create a test-way. way = new Way(); way.Id = 1; way.UserName = "******"; way.UserId = 10; way.Version = 1; way.Visible = true; way.TimeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); way.Nodes = new List <long>(); way.Nodes.Add(1); way.Nodes.Add(2); way.Nodes.Add(3); way.Nodes.Add(1); // create a target, add the way, create a source and verify way in db. target = this.CreateDataStreamTarget(); target.Initialize(); target.AddWay(way); target.Flush(); target.Close(); dataSource = this.CreateDataSource(); foundWay = dataSource.GetWay(1); ComparisonHelpers.CompareSimple(way, foundWay); }