Example #1
0
        public void IsNoteAlreadyExitsForThisLocation_Should_return_zero_or_greater_than_zero_based_on_input(string email, double latitude, double longitude, bool isNoteExists)
        {
            // Arrange
            var configuration = new Mock <IConfiguration>();
            var options       = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Notes.Add(new Note {
                    Remark = "this is first Note", Latitude = 523.987, Longitude = 908.786, Email = "*****@*****.**"
                });
                context.Notes.Add(new Note {
                    Remark = "second one", Latitude = 423.987, Longitude = 808.786, Email = "*****@*****.**"
                });
                context.Notes.Add(new Note {
                    Remark = "this is third Note", Latitude = 323.987, Longitude = 708.786, Email = "*****@*****.**"
                });

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(options))
            {
                var landmarkService = new LandmarkService(context, configuration.Object);

                // Act
                var response = landmarkService.IsNoteExistsForThisLocation(email, longitude, latitude);

                // Assert
                Assert.IsTrue(isNoteExists ? response > 0 : response == 0);
            }
        }
Example #2
0
        public BusinessLayerTests()
        {
            var options = SqliteInMemory.CreateOptions <ApplicationContext>();

            context = new ApplicationContext(options);
            context.Database.EnsureCreated();

            // Seed Inventory content
            context.SeedItemTypes();
            context.SeedItemImages();


            // Seed Monster content
            context.SeedMonsterModels();
            context.SeedMonsterNames();
            context.SeedMonsterTitles();


            inventoryRepository = new InventoryRepository(context);
            inventoryService    = new InventoryService(inventoryRepository);

            playerRepository = new PlayerRepository(context);
            playerService    = new PlayerService(playerRepository);

            monsterRepository = new MonsterRepository(context);
            monsterService    = new MonsterService(monsterRepository);

            knightRepository   = new KnightRepository(context);
            landmarkRepository = new LandmarkRepository(context);
            landmarkService    = new LandmarkService(landmarkRepository, knightRepository);
        }
Example #3
0
        public static void initLandmarkService()
        {
            if (ls == null)
            {
                int  retries = 0;
                bool failed  = !Project.serverAvailable;

                while (Project.serverAvailable && retries <= maxRetries)
                {
                    initedOffline = false;
                    failed        = false;
                    try
                    {
                        ls = new LandmarkService();
                        //ls.Url = "http://" + Project.TERRA_SERVER + "/LandmarkService.asmx";
                        LandmarkType[] lt = ls.GetLandmarkTypes();
                        int            numLandmarkTypes = lt.Length;
                        landmarkPointTypes = new string[numLandmarkTypes];
                        //
                        //	Populate a hash table associating an index with a landmark type
                        //	This will be used when drawing landmarks, to associate a landmark type
                        //	with an image in an image list, which is addressed by index
                        //
                        int j = 0;
                        for (int i = 0; i < numLandmarkTypes; i++)
                        {
                            string type = "" + lt[i].Type;
                            // as of May 31,03 , "Institution" and "Recreation Area" cause exception:
                            //          Server was unable to process request. --> Data is Null. This method or property cannot be called on Null values.
                            if ("Recreation Area".Equals(type) || "Institution".Equals(type))
                            {
                                continue;
                            }
                            if ("Terminal".Equals(type))
                            {
                                type = "Transportation Terminal";
                            }
                            landmarkPointTypes[j] = type;
                            j++;
                        }

                        if (j > 0)
                        {
                            // now make a clean compacted copy of the same:
                            landmarkPointShow = new bool[j];
                            string[] tmp = new string[j];
                            stringToIndex.Clear();
                            for (int i = 0; i < j; i++)
                            {
                                tmp[i] = landmarkPointTypes[i].ToLower();
                                landmarkPointShow[i] = true;
                                stringToIndex.Add(tmp[i], i);
                            }
                            landmarkPointTypes = tmp;
                        }

                        // (re)populate lmtype table from m_landmarksDS:
                        m_landmarksDS.Tables["lmtype"].Clear();
                        foreach (string type in landmarkPointTypes)
                        {
                            // Create DataRow objects and add them to the DataTable
                            DataRow myDataRow;
                            myDataRow         = m_landmarksDS.Tables["lmtype"].NewRow();
                            myDataRow["type"] = type;
                            try
                            {
                                m_landmarksDS.Tables["lmtype"].Rows.Add(myDataRow);
                            }
                            catch {}                              // already there, skip it
                        }
                        break;
                    }
                    catch (Exception e)
                    {
                        LibSys.StatusBar.Error("Unable to establish a connection to the LandmarkServer Web Service" + e.Message);
                        failed = true;
                    }
                    catch
                    {
                        LibSys.StatusBar.Error("LandmarkServer Web Service protocol error during initialization");
                        failed = true;
                    }

                    if (failed)
                    {
                        retries++;
                        if (retries == maxRetries)
                        {
                            LibSys.StatusBar.Error("Unable to establish a connection to the LandmarkServer Web Service");
                            //MessageBox.Show("Unable to establish a connection to the Landmark Web Service"
                            //	, "TerraService Error",
                            //	MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }
                    }
                }

                if (failed && !initedOffline)
                {
                    // try populate types from dataset:
                    DataRow[] rows             = m_landmarksDS.Tables["lmtype"].Select("");
                    int       numLandmarkTypes = rows.Length;
                    if (numLandmarkTypes > 0)
                    {
                        landmarkPointTypes = new string[numLandmarkTypes];
                        landmarkPointShow  = new bool[numLandmarkTypes];
                        stringToIndex.Clear();
                        int i = 0;
                        foreach (DataRow row in rows)
                        {
                            landmarkPointTypes[i] = ((string)row["type"]).ToLower();
                            landmarkPointShow[i]  = true;
                            stringToIndex.Add(landmarkPointTypes[i], i);
                            i++;
                        }
                    }
                    if (numLandmarkTypes > 0 && landmarkPointTypes[0] == "terminal")
                    {
                        landmarkPointTypes[0] = "transportation terminal";
                    }
                    initedOffline = true;
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:RidderRedderApi.Web.Api.Controllers.LandmarkController"/> class.
 /// </summary>
 /// <param name="landmarkService">Landmark service.</param>
 public LandmarkController(LandmarkService landmarkService)
 {
     this.landmarkService = landmarkService;
 }