Exemple #1
0
        /// <summary>
        /// Tests a simple node read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestNode(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddNode(null));
            Assert.Throws <Exception>(() => cache.AddNode(new Node()));
            Assert.IsNull(cache.GetNode(node.Id.Value));

            cache.AddNode(node);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Node readNode = cache.GetNode(node.Id.Value);

            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.TryGetNode(node.Id.Value, out readNode));
            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.RemoveNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.RemoveNode(node.Id.Value));
        }