Esempio n. 1
0
        /// <summary>
        /// Gets list of all map icons stored in the database.
        /// </summary>
        /// <returns><b>List</b> containing <b>MapIconItem</b> objects populated with data from database.</returns>
        public static async Task <List <MapIconItem> > GetMapIconItemsAsync()
        {
            var result = new List <MapIconItem>();

            using (var cnn = await GetDbConnectionAsync())
            {
                cnn.Open();

                var sqlcommand =
                    @"SELECT m.Id, m.Name, l.Id, l.Name, g.Altitude, g.Latitude, g.Longitude 
                    FROM ((MapElement m  
                    INNER JOIN Layer l ON m.Layer_Id = l.Id) 
                    INNER JOIN Geoposition g ON m.Id = g.MapElement_Id)
                    WHERE m.Type='MapIconItem'";

                result = cnn.
                         Query <MapIconItem, MapLayerItem, BasicGeoposition, MapIconItem>(sqlcommand,
                                                                                          (icon, layer, pos) =>
                {
                    var ret = MapElementItemFactoryService.GetMapIconItem(icon.Name, pos, layer, icon.Id);
                    return(ret);
                },
                                                                                          splitOn: "Id,Altitude").ToList();
            }

            return(result);
        }
Esempio n. 2
0
        private async Task CreateAndAddMapIconAsync(BasicGeoposition position, string title, MapLayerItem layer)
        {
            var pos = new BasicGeoposition()
            {
                Longitude = position.Longitude, Latitude = position.Latitude
            };
            var newItem = MapElementItemFactoryService.GetMapIconItem(title, pos, layer);

            AddMapElementItem(newItem);
            await DatabaseAccessService.InsertMapIconItemAsync(newItem);
        }
        public void GetMapIconItem_ConstructsMapIconItemCorrectly()
        {
            var expectName     = "TestName";
            var expectPosition = new BasicGeoposition()
            {
                Latitude = 1, Longitude = 2
            };
            var expectLayer = new MapLayerItem()
            {
                Id = 3, Name = "TestLayer"
            };
            int expectId = 4;

            var icon = MapElementItemFactoryService.GetMapIconItem(expectName, expectPosition, expectLayer, expectId);

            Assert.AreEqual(expectName, icon.Name);
            Assert.AreEqual(expectPosition, icon.GetPosition());
            Assert.AreEqual(expectLayer, icon.ParentLayer);
            Assert.AreEqual(expectId, icon.Id);
        }
Esempio n. 4
0
        public async Task GetMapIconItemsAsync_ReturnsIconListCorrectly()
        {
            var taskSource = new TaskCompletionSource <object>();
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    await DatabaseAccessService.DeleteDatabase();
                    await DatabaseAccessService.CreateDatabaseAsync();

                    var insertedLayer = new MapLayerItem()
                    {
                        Id = 1234124, Name = "Test Layer"
                    };
                    var insertedIcon = MapElementItemFactoryService.GetMapIconItem(
                        "Test Icon",
                        new BasicGeoposition()
                    {
                        Latitude = 1, Longitude = 2
                    },
                        insertedLayer,
                        123);

                    await DatabaseAccessService.InsertLayerAsync(insertedLayer);
                    await DatabaseAccessService.InsertMapIconItemAsync(insertedIcon);

                    using (var cnn = await DatabaseAccessService.GetDbConnectionAsync())
                    {
                        cnn.Open();

                        var queriedMapElementList = await DatabaseAccessService.GetMapIconItemsAsync();
                        Assert.AreEqual(1, queriedMapElementList.Count, $@"Database query for inserted MapElement
                                                            returned list with number of entries different than one.
                                                            Expected: 1,
                                                            Actual: {queriedMapElementList.Count}.");

                        var queriedMapElement = queriedMapElementList.First();

                        Assert.IsNotNull(queriedMapElement, "Map element is null.");
                        Assert.AreEqual(insertedIcon.Id, queriedMapElement.Id, $@"Method returned 
                                                                    MapElement with differrent Id.
                                                                    Expected: {insertedIcon.Id},
                                                                    Actual: {queriedMapElement.Id}.");
                        Assert.AreEqual(insertedIcon.Name, queriedMapElement.Name, $@"Method returned 
                                                                        MapElement with different Name.
                                                                        Expected: {insertedIcon.Name},
                                                                        Actual: {queriedMapElement.Name}.");
                        Assert.AreEqual(insertedLayer.Id, queriedMapElement.ParentLayer.Id, $@"Method returned
                                                                                MapElement with different parent layer.
                                                                                Expected: {insertedLayer.Id},
                                                                                Actual: {queriedMapElement.ParentLayer.Id}.");
                    }

                    taskSource.SetResult(null);
                }
                catch (Exception e)
                {
                    taskSource.SetException(e);
                }
            });

            await taskSource.Task;
        }
Esempio n. 5
0
        public async Task InsertMapIconItemAsync_InsertsElementCorrectly()
        {
            var taskSource = new TaskCompletionSource <object>();

            // using dispatcher to run the test in ui thread.
            // using UITestMethod attribute was umpossible because it
            // doesn't support async
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    await DatabaseAccessService.DeleteDatabase();
                    await DatabaseAccessService.CreateDatabaseAsync();


                    var insertedLayer = new MapLayerItem()
                    {
                        Id = 1234124, Name = "Test Layer"
                    };
                    var insertedIcon = MapElementItemFactoryService.GetMapIconItem(
                        "Test Icon",
                        new BasicGeoposition()
                    {
                        Latitude = 1, Longitude = 2
                    },
                        insertedLayer,
                        123);

                    await DatabaseAccessService.InsertLayerAsync(insertedLayer);
                    await DatabaseAccessService.InsertMapIconItemAsync(insertedIcon);

                    using (var cnn = await DatabaseAccessService.GetDbConnectionAsync())
                    {
                        cnn.Open();

                        var queriedMapElementList = (cnn.Query <dynamic>($"SELECT * FROM MapElement WHERE Id={insertedIcon.Id}")).ToList();
                        Assert.AreEqual(1, queriedMapElementList.Count, $@"Database query for inserted MapElement returned list with number of entries
                                                            different than one.
                                                            Expected: 1,
                                                            Actual: {queriedMapElementList.Count}.");

                        var queriedMapElement = queriedMapElementList.First();

                        Assert.IsNotNull(queriedMapElement, "Database query for inserted MapElement returned null.");
                        Assert.AreEqual(insertedIcon.Id, queriedMapElement.Id, $@"Database query for inserted MapElement returned 
                                                                    MapElement with differrent Id.
                                                                    Expected: {insertedIcon.Id},
                                                                    Actual: {queriedMapElement.Id}.");
                        Assert.AreEqual(insertedIcon.Name, queriedMapElement.Name, $@"Database query for inserted MapElement returned 
                                                                        MapElement with different Name.
                                                                        Expected: {insertedIcon.Name},
                                                                        Actual: {queriedMapElement.Name}.");
                        Assert.AreEqual(insertedLayer.Id, queriedMapElement.Layer_Id, $@"Database query for inserted MapElement returned
                                                                                MapElement with different parent layer.
                                                                                Expected: {insertedLayer.Id},
                                                                                Actual: {queriedMapElement.Layer_id}.");
                    }
                    taskSource.SetResult(null);
                }
                catch (Exception e)
                {
                    taskSource.SetException(e);
                }
            });

            await taskSource.Task;
        }