public void TestSimpleTagsCollectionSimple()
        {
            var collection = new TagsCollection();

            collection["simple"] = "yes";

            Assert.IsTrue(collection.ContainsKey("simple"));
            Assert.IsTrue(collection.ContainsKeyValue("simple", "yes"));
            Assert.AreEqual("yes", collection["simple"]);
            Assert.AreEqual(1, collection.Count);
        }
Пример #2
0
        /// <summary>
        /// Tests an empty tags collection.
        /// </summary>
        protected void TestTagsCollectionSimple()
        {
            TagsCollectionBase collection = new TagsCollection();

            collection["simple"] = "yes";

            Assert.IsTrue(collection.ContainsKey("simple"));
            Assert.IsTrue(collection.ContainsKeyValue("simple","yes"));
            Assert.AreEqual("yes", collection["simple"]);
            Assert.AreEqual(1, collection.Count);
        }
 /// <summary>
 /// Compares two tag collection for indentical content.
 /// </summary>
 /// <param name="expectedTags"></param>
 /// <param name="foundTags"></param>
 private void CompareTags(TagsCollection expectedTags, TagsCollection foundTags)
 {
     if (expectedTags == null)
     {
         Assert.IsNull(foundTags);
     }
     else
     {
         Assert.IsNotNull(foundTags);
         Assert.AreEqual(expectedTags.Count, foundTags.Count);
         foreach (Tag expectedTag in expectedTags)
         {
             Assert.IsTrue(foundTags.ContainsKeyValue(expectedTag.Key, expectedTag.Value));
         }
     }
 }
        public void Scene2DSimpleSerializeDeserializeTest()
        {
            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"),
                imageSource);

            // initialize the data source.
            var xmlSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.test.osm"));
            IEnumerable<OsmGeo> dataSource = xmlSource;
            MemoryDataSource source = MemoryDataSource.CreateFrom(xmlSource);

            // get data.
            var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
            var projection = new WebMercator();
            GeoCoordinateBox box = null;
            foreach (var osmGeo in dataSource)
            {
                ICompleteOsmGeo completeOsmGeo = null;
                switch (osmGeo.Type)
                {
                    case OsmGeoType.Node:
                        completeOsmGeo = osmGeo as Node;
                        if(completeOsmGeo.Tags == null)
                        { // make sure every node has a tags collection.
                            completeOsmGeo.Tags = new TagsCollection();
                        }
                        break;
                    case OsmGeoType.Way:
                        completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way,
                            source);
                        break;
                    case OsmGeoType.Relation:
                        completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation,
                            source);
                        break;
                }

                // update box.
                if (completeOsmGeo != null)
                {
                    if (box == null) { box = completeOsmGeo.BoundingBox; }
                    else if (completeOsmGeo.BoundingBox != null) { box = box + completeOsmGeo.BoundingBox; }
                }

                // translate each object into scene object.
                mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo);
            }

            // create the stream.
            TagsCollectionBase metaTags = new TagsCollection();
            metaTags.Add("SomeTestKey", "SomeTestValue");
            var stream = new MemoryStream();
            scene.Serialize(stream, true, metaTags);

            // deserialize the stream.
            metaTags = null;
            stream.Seek(0, SeekOrigin.Begin);
            IPrimitives2DSource sceneSource = Scene2D.Deserialize(stream, true, out metaTags);

            // test meta tags.
            Assert.IsTrue(metaTags.ContainsKeyValue("SomeTestKey", "SomeTestValue"));

            if (box != null)
            {
                // query both and get the same results.
                int counter = 100;
                var rand = new Random();
                while (counter > 0)
                {
                    var queryBox = new GeoCoordinateBox(
                        box.GenerateRandomIn(rand),
                        box.GenerateRandomIn(rand));
                    var zoomFactor = (float)projection.ToZoomFactor(15);
                    View2D testView = View2D.CreateFromBounds(
                        projection.LatitudeToY(queryBox.MaxLat),
                        projection.LongitudeToX(queryBox.MinLon),
                        projection.LatitudeToY(queryBox.MinLat),
                        projection.LongitudeToX(queryBox.MaxLon));
                    var testScene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16);
                    IEnumerable<Primitive2D> primitives = sceneSource.Get(testView, zoomFactor);

                    //                    var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor));
                    //                    var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor));

                    //Assert.AreEqual(resultReference.Count, resultIndex.Count);
                    //foreach (var data in resultIndex)
                    //{
                    //    Assert.IsTrue(resultReference.Contains(data));
                    //}
                    //foreach (var data in resultReference)
                    //{
                    //    Assert.IsTrue(resultIndex.Contains(data));
                    //}
                    counter--;
                }
            }
        }