public void TestAddRelation() { Relation testRelation = new Relation(); testRelation.Id = -1; var source = new MemoryDataSource(); source.AddRelation(testRelation); // test if the relation is actually there. Assert.AreEqual(testRelation, source.GetRelation(-1)); // test if the relation was not remove after getting it. Assert.AreEqual(testRelation, source.GetRelations(new List <long>() { -1 })[0]); // test if the relation is in the list of relations. Assert.AreEqual(testRelation, new List <Relation>(source.GetRelations())[0]); // test if the relation will be retrieved using a list of ids. List <long> ids = new List <long>(); ids.Add(-1); IList <Relation> relations = source.GetRelations(ids); Assert.IsNotNull(relations); Assert.AreEqual(1, relations.Count); Assert.AreEqual(testRelation, relations[0]); }
public void TestRemoveRelation() { Relation testRelation = new Relation(); testRelation.Id = -1; var source = new MemoryDataSource(); source.AddRelation(testRelation); // test if the relation is actually there. Assert.AreEqual(testRelation, source.GetRelation(-1)); // remove the relation. source.RemoveRelation(-1); // test if the relation is actually gone. Assert.IsNull(source.GetRelation(-1)); }
public void TestAddRelationNull() { var dataSource = new MemoryDataSource(); dataSource.AddRelation(null); }
public void TestGetBoundingBox() { var dataSource = new MemoryDataSource(); // test nodes. Node node = new Node(); node.Id = 1; node.Longitude = -2; node.Latitude = -1; dataSource.AddNode(node); node = new Node(); node.Id = 2; node.Longitude = 2; node.Latitude = 1; dataSource.AddNode(node); GeoCoordinateBox box = dataSource.BoundingBox; IList <OsmGeo> boxResults = dataSource.Get(box, null); Assert.IsNotNull(boxResults); Assert.AreEqual(1, boxResults.Count); boxResults = dataSource.Get(box.Resize(0.1), null); Assert.IsNotNull(boxResults); Assert.AreEqual(2, boxResults.Count); node = new Node(); node.Id = 3; node.Latitude = 10; node.Longitude = 10; dataSource.AddNode(node); node = new Node(); node.Id = 4; node.Latitude = -10; node.Longitude = -10; dataSource.AddNode(node); boxResults = dataSource.Get(box, null); Assert.IsNotNull(boxResults); Assert.AreEqual(1, boxResults.Count); boxResults = dataSource.Get(box.Resize(0.1), null); Assert.IsNotNull(boxResults); Assert.AreEqual(2, boxResults.Count); // test ways. Way positive = new Way(); positive.Id = 1; positive.Nodes = new List <long>(); positive.Nodes.Add(1); positive.Nodes.Add(2); dataSource.AddWay(positive); Way halfPositive = new Way(); halfPositive.Id = 2; halfPositive.Nodes = new List <long>(); halfPositive.Nodes.Add(1); halfPositive.Nodes.Add(3); dataSource.AddWay(halfPositive); Way negative = new Way(); negative.Id = 3; negative.Nodes = new List <long>(); negative.Nodes.Add(3); negative.Nodes.Add(4); dataSource.AddWay(negative); HashSet <OsmGeo> boxResultWithWays = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWays.Contains(positive)); Assert.IsTrue(boxResultWithWays.Contains(halfPositive)); Assert.IsFalse(boxResultWithWays.Contains(negative)); // test relations. Relation positiveRelation1 = new Relation(); positiveRelation1.Id = 1; positiveRelation1.Members = new List <RelationMember>(); positiveRelation1.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Node, MemberRole = "node" }); dataSource.AddRelation(positiveRelation1); Relation positiveRelation2 = new Relation(); positiveRelation2.Id = 2; positiveRelation2.Members = new List <RelationMember>(); positiveRelation2.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Way, MemberRole = "way" }); dataSource.AddRelation(positiveRelation2); Relation negativeRelation3 = new Relation(); negativeRelation3.Id = 3; negativeRelation3.Members = new List <RelationMember>(); negativeRelation3.Members.Add(new RelationMember() { MemberId = 3, MemberType = OsmGeoType.Way, MemberRole = "way" }); dataSource.AddRelation(positiveRelation2); HashSet <OsmGeo> boxResultWithWaysAndRelations = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(positiveRelation1)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(positiveRelation2)); Assert.IsFalse(boxResultWithWaysAndRelations.Contains(negativeRelation3)); // test recursive relations. Relation recusive1 = new Relation(); recusive1.Id = 10; recusive1.Members = new List <RelationMember>(); recusive1.Members.Add(new RelationMember() { MemberId = 1, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive1); Relation recusive2 = new Relation(); recusive2.Id = 11; recusive2.Members = new List <RelationMember>(); recusive2.Members.Add(new RelationMember() { MemberId = 10, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive2); Relation recusive3 = new Relation(); recusive3.Id = 12; recusive3.Members = new List <RelationMember>(); recusive3.Members.Add(new RelationMember() { MemberId = 11, MemberType = OsmGeoType.Relation, MemberRole = "relation" }); dataSource.AddRelation(recusive3); boxResultWithWaysAndRelations = new HashSet <OsmGeo>(dataSource.Get(box, null)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive1)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive2)); Assert.IsTrue(boxResultWithWaysAndRelations.Contains(recusive3)); }
public void TestAddRelationAndMembers() { Way testWay = new Way(); testWay.Id = 1; testWay.Nodes = new List <long>(); testWay.Nodes.Add(1); testWay.Nodes.Add(2); Node node1 = new Node(); node1.Id = 1; node1.Longitude = 0; node1.Latitude = 0; Node node2 = new Node(); node2.Id = 2; node2.Longitude = 0; node2.Latitude = 0; Relation relationAsMember = new Relation(); relationAsMember.Id = 2; Relation relation = new Relation(); relation.Id = 1; relation.Members = new List <RelationMember>(); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = "node", MemberType = OsmGeoType.Node }); relation.Members.Add(new RelationMember() { MemberId = 2, MemberRole = "node", MemberType = OsmGeoType.Node }); relation.Members.Add(new RelationMember() { MemberId = 1, MemberRole = "way", MemberType = OsmGeoType.Way }); relation.Members.Add(new RelationMember() { MemberId = 2, MemberRole = "relation", MemberType = OsmGeoType.Relation }); var source = new MemoryDataSource(); source.AddRelation(relation); // test positive cases. IList <Relation> resultRelations = source.GetRelationsFor(node1); Assert.IsNotNull(resultRelations); Assert.AreEqual(1, resultRelations.Count); Assert.AreEqual(relation, resultRelations[0]); resultRelations = source.GetRelationsFor(node2); Assert.IsNotNull(resultRelations); Assert.AreEqual(1, resultRelations.Count); Assert.AreEqual(relation, resultRelations[0]); resultRelations = source.GetRelationsFor(testWay); Assert.IsNotNull(resultRelations); Assert.AreEqual(1, resultRelations.Count); Assert.AreEqual(relation, resultRelations[0]); resultRelations = source.GetRelationsFor(relationAsMember); Assert.IsNotNull(resultRelations); Assert.AreEqual(1, resultRelations.Count); Assert.AreEqual(relation, resultRelations[0]); // test negative cases. resultRelations = source.GetRelationsFor(OsmGeoType.Node, 10000); Assert.IsNotNull(resultRelations); Assert.AreEqual(0, resultRelations.Count); resultRelations = source.GetRelationsFor(OsmGeoType.Way, 10000); Assert.IsNotNull(resultRelations); Assert.AreEqual(0, resultRelations.Count); resultRelations = source.GetRelationsFor(OsmGeoType.Relation, 10000); Assert.IsNotNull(resultRelations); Assert.AreEqual(0, resultRelations.Count); }
public void TestAddRelationNoId() { var dataSource = new MemoryDataSource(); dataSource.AddRelation(new Relation()); }
public void TestAddRelationNull() { var dataSource = new MemoryDataSource(); Assert.Catch <ArgumentNullException>(() => dataSource.AddRelation(null)); }
public void TestAddRelationNoId() { var dataSource = new MemoryDataSource(); Assert.Catch <ArgumentException>(() => dataSource.AddRelation(new Relation())); }