Пример #1
0
        public void ParseMunicipality(MunicipalityService ms, NationService ns)
        {
            // Clears the database of Nations/Munincipality
            var myNations = ns.Get();

            foreach (var i in myNations)
            {
                ns.Remove(i);
            }

            var myMunicipality = ms.Get();

            foreach (var i in myMunicipality)
            {
                ms.Remove(i);
            }

            var dk = new Nation()
            {
                NationName = "Danmark",
                NationID   = "1"
            };

            ns.Create(dk);

            string line   = "";
            var    reader = new StreamReader("./Municipality_test_pos.csv");

            reader.ReadLine(); // Skip first

            while ((line = reader.ReadLine()) != null)
            {
                var data       = line.Split(";");
                var population = float.Parse(data[4].Trim());

                var mun = new Municipality()
                {
                    MunicipalityID = int.Parse(data[0].Trim()),
                    Name           = data[1].Trim(),
                    Population     = population,
                    NationName     = "Danmark"
                };

                Municipalities.Add(int.Parse(data[0].Trim()));

                ms.Create(mun);
            }
            reader.Close();
        }
Пример #2
0
        public async Task ReturnEmptyMunicipalitiesList()
        {
            IQueryable <Municipality> municipalities = new List <Municipality>().AsQueryable();

            var repositoryMock = new Mock <IMunicipalityRepository>();

            repositoryMock.Setup(x => x.GetAll()).ReturnsAsync(municipalities);

            var municipalityService = new MunicipalityService(repositoryMock.Object, _logger);

            IEnumerable <MunicipalityDTO> result = await municipalityService.GetAll();

            repositoryMock.Verify(x => x.GetAll(), Times.Once);

            Assert.NotNull(result);
            Assert.Empty(result);
        }
Пример #3
0
        public async Task ReturnMunicipalitiesListWithMultipleElements()
        {
            IQueryable <Municipality> municipalities = new List <Municipality> {
                new Municipality(),
                new Municipality(),
                new Municipality()
            }.AsQueryable();

            var repositoryMock = new Mock <IMunicipalityRepository>();

            repositoryMock.Setup(x => x.GetAll()).ReturnsAsync(municipalities);

            var municipalityService = new MunicipalityService(repositoryMock.Object, _logger);

            IEnumerable <MunicipalityDTO> result = await municipalityService.GetAll();

            repositoryMock.Verify(x => x.GetAll(), Times.Once);

            Assert.NotNull(result);
            Assert.Equal(3, result.Count());
        }
Пример #4
0
        static void Main(string[] args)
        {
            DbClient client              = new DbClient(new MongoClient());
            var      citizenService      = new CitizenService(Client);
            var      municipalityService = new MunicipalityService(Client);
            var      locationService     = new LocationService(Client, municipalityService);
            var      testCenterService   = new TestCenterService(Client);
            var      testService         = new TestService(Client);

            bool run = true;

            while (run)
            {
                Console.WriteLine("[A] Add new Citizen");
                Console.WriteLine("[B] Add new TestCenter and TestCenterManagement");
                Console.WriteLine("[C] Add new Test");
                Console.WriteLine("[D] Add Test to all Citizens");
                Console.WriteLine("[E] Add new Location");
                Console.WriteLine("[F] Add Locations to all Citizens");
                Console.WriteLine("[G] Seed data");
                Console.WriteLine("[H] View active cases for Municipalities");
                Console.WriteLine("[I] View active cases by Sex");
                Console.WriteLine("[J] View active cases by Age");
                Console.WriteLine("[K] View possible cases by Location three days prior");
                Console.WriteLine("[X] Quit");
                Console.WriteLine("INPUT: ");

                var userInput = Console.ReadKey();

                switch (userInput.KeyChar)
                {
                case 'A':
                {
                    Console.Write("Firstname: ");
                    string firstname = Console.ReadLine();
                    Console.Write("Lastname: ");
                    string lastname = Console.ReadLine();
                    Console.Write("SSN (XXXXXX-XXXX): ");
                    string ssn = Console.ReadLine();
                    Console.Write("Age: ");
                    string age = Console.ReadLine();
                    Console.Write("Sex: ");
                    string sex = Console.ReadLine();
                    Console.Write("Municipality: ");
                    string municipalityName = Console.ReadLine();

                    int municipalityId = municipalityService.GetId(municipalityName);

                    var newCitizen = new Citizen
                    {
                        Firstname       = firstname,
                        Lastname        = lastname,
                        SSN             = ssn,
                        Age             = int.Parse(age),
                        Sex             = sex,
                        Tests           = new List <Test>(),
                        Location_id     = new List <int>(),
                        Municipality_id = municipalityId
                    };

                    citizenService.AddCitizen(newCitizen);
                }
                break;

                case 'B':
                {
                    Console.Write("Municipality: ");
                    string municipalityName = Console.ReadLine();
                    Console.Write("Hours: ");
                    int hours = int.Parse(Console.ReadLine());
                    Console.Write("Phonenumber: ");
                    int phonenumber = int.Parse(Console.ReadLine());
                    Console.Write("Email: ");
                    string email = Console.ReadLine();

                    testCenterService.AddTestCenter(municipalityName, hours, phonenumber, email);
                }
                break;

                case 'C':
                {
                    Console.Write("Citizen-ID: ");
                    int citizenId = int.Parse(Console.ReadLine());
                    Console.Write("TestCenter-ID: ");
                    int testCenterId = int.Parse(Console.ReadLine());

                    if (Client.TestCenters.Find(t => t.TestCenterId == testCenterId).Any())
                    {
                        Console.WriteLine("No TestCenter with ID {0} exists.", testCenterId);
                        break;
                    }
                    else if (Client.Citizens.Find(c => c.CitizenId == citizenId).Any())
                    {
                        Console.WriteLine("No Citizen with ID {0} exists.", citizenId);
                        break;
                    }

                    testService.TestCitizen(citizenId, testCenterId);
                }
                break;

                case 'D':
                {
                    testService.TestAllCitizens();
                    Console.WriteLine("All citizens tested.");
                }
                break;

                case 'E':
                {
                    Console.Write("Citizen-ID: ");
                    int citizenId = int.Parse(Console.ReadLine());
                    Console.Write("Address: ");
                    string address = Console.ReadLine();
                    Console.Write("Zip: ");
                    int zip = int.Parse(Console.ReadLine());
                    Console.Write("Municipality name: ");
                    string municipalityName = Console.ReadLine();

                    locationService.AddLocation(citizenId, address, zip, municipalityName);
                }
                break;

                case 'F':
                {
                    locationService.AddLocationToAllCitizen();
                    Console.WriteLine("All Citizen have now locations");
                }
                break;

                case 'G':
                {
                    Console.WriteLine("Sure you want to seed? Seeding will reset all Citizens and Municipalities[Y/N]");
                    string userKey = Console.ReadLine();

                    if (userKey.Contains('Y'))
                    {
                        Seed();
                        Console.WriteLine("Seeding done!");
                    }
                    else
                    {
                        Console.WriteLine("Seeding canceled.");
                    }
                }
                break;

                case 'H':
                {
                    testCenterService.ActiveCovidCasesPerMunicipality();
                }
                break;

                case 'I':
                {
                    testCenterService.ActiveCovidCasesSex();
                }
                break;

                case 'J':
                {
                    Console.Write("Min age: ");
                    int minAge = int.Parse(Console.ReadLine());
                    Console.Write("Max age: ");
                    int maxAge = int.Parse(Console.ReadLine());
                    int cases  = testCenterService.ActiveCovidCasesAge(minAge, maxAge);
                    Console.WriteLine("Total number of cases: {0}", cases);
                }
                break;

                case 'K':
                {
                    Console.Write("Infected citizen's ID: ");
                    int            citizenId = int.Parse(Console.ReadLine());
                    List <Citizen> citizens  = citizenService.CitizensAtSameLocation(citizenId);
                    Console.WriteLine("Citizens which has been the at the same location as an infected: ");
                    foreach (var citizen in citizens)
                    {
                        Console.WriteLine("-------------------------------------------------------");
                        Console.WriteLine($"ID: {citizen.CitizenId}");
                        Console.WriteLine($"Name: {citizen.Firstname} {citizen.Lastname}");
                        Console.WriteLine($"SSN : {citizen.SSN}");
                        Console.WriteLine("-------------------------------------------------------");
                    }
                }
                break;

                case 'X':
                    run = false;
                    break;
                }

                Console.WriteLine("\nPress any key.");
                Console.ReadKey();
                Console.Clear();
            }
        }
Пример #5
0
 public MunicipalityServiceTests()
 {
     _municipalityService = new MunicipalityService(_municipalityRepo);
 }
Пример #6
0
        static void Main(string[] args)
        {
            CitizenService              cs   = new CitizenService();
            LocationService             ls   = new LocationService();
            MunicipalityService         ms   = new MunicipalityService();
            CountryService              ns   = new CountryService();
            TestCenterService           tcs  = new TestCenterService();
            TestCenterManagementService tcms = new TestCenterManagementService();

            LocationCitizenService   lcs  = new LocationCitizenService();
            TestCenterCitizenService tccs = new TestCenterCitizenService();

            MongoFunctions cf = new MongoFunctions();

            int  choice;
            bool done = false;

            do
            {
                Console.WriteLine("Time to choose \n"
                                  + " 1: to add a new citizen\n"
                                  + " 2: to add Testcenter\n"
                                  + " 3: to add Management\n"
                                  + " 4: to add Testcase\n"
                                  + " 5: to a add location\n"
                                  + " 6: to add Location Citizen\n"
                                  + " 0: to exit");

                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case 1:
                    cf.citizenCreation(cs);
                    break;

                case 2:
                    cf.TestCenterCreation(tcs);
                    break;

                case 3:
                    cf.ManagementCreation(tcms, tcs);
                    break;

                case 4:
                    cf.TestCaseCreation(cs, tcs, tccs, lcs);
                    break;

                case 5:
                    cf.LocationCreation(ls);
                    break;

                case 6:
                    cf.LocationCitizenCreation(lcs, cs, ls);
                    break;


                case 0:
                    done = true;
                    break;
                }
            } while (true);
        }
Пример #7
0
        static void Main(string[] args)
        {
            CitizenService              cs   = new CitizenService();
            LocationService             ls   = new LocationService();
            MunicipalityService         ms   = new MunicipalityService();
            NationService               ns   = new NationService();
            TestCenterService           tcs  = new TestCenterService();
            TestCenterManagementService tcms = new TestCenterManagementService();

            LocationCitizenService   lcs  = new LocationCitizenService();
            TestCenterCitizenService tccs = new TestCenterCitizenService();

            GenerateFunctions gf = new GenerateFunctions();
            CreateFunctions   cf = new CreateFunctions();

            int  choice;
            int  choice2;
            bool finished       = false;
            bool finishedSearch = false;


            // program start
            Console.WriteLine("Make a choice! \n" +
                              " 1: Add Denmark municipality and random dummy data\n" +
                              " 2: Empty database");
            choice = Convert.ToInt32(Console.ReadLine());
            switch (choice)
            {
            case 1:
                Console.Clear();
                gf.ParseMunicipality(ms, ns);
                gf.GenerateTestCenter(tcs, 100);
                gf.GenerateCitizens(cs, 100);
                gf.AddCitizenToTestCenter(cs, tcs, tccs);
                gf.GenerateLocation(ls, 100);
                gf.AddCitizenToLocation(cs, ls, lcs, 100);
                gf.GenerateTestCenterManagement(tcms, tcs, 100);
                break;

            case 2:
                Console.Clear();
                break;
            }

            choice = 0;
            do
            {
                Console.Clear();
                Console.WriteLine("Choose an option... \n" +
                                  " 1: Create Citizen\n" +
                                  " 2: Create Test Center\n" +
                                  " 3: Create Management\n" +
                                  " 4: Create Test Case\n" +
                                  " 5: Create Location\n" +
                                  " 6: Create LocationCitizen\n" +
                                  " 7: Search the database\n" +
                                  " 0: Exit");

                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    cf.createCitizen(cs);
                    break;

                case 2:
                    cf.createTestCenter(tcs);
                    break;

                case 3:
                    cf.createManagement(tcms, tcs);
                    break;

                case 4:
                    cf.createTestCase(cs, tcs, tccs, lcs);
                    break;

                case 5:
                    cf.createLocation(ls);
                    break;

                case 6:
                    cf.createLocationCitizen(lcs, cs, ls);
                    break;

                case 7:
                    Console.Clear();
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("What do you want to search by? \n" +
                                          " 1: Search by name\n" +
                                          " 2: Search by age groups\n" +
                                          " 3: Search by gender\n" +
                                          " 4: Search by municipality\n" +
                                          " 0: Exit search");

                        choice2 = Convert.ToInt32(Console.ReadLine());
                        switch (choice2)
                        {
                        case 1:
                            cf.searchForCitizen(cs);
                            break;

                        case 2:
                            cf.searchforAge(tccs);
                            break;

                        case 3:
                            cf.searchforSex(tccs);
                            break;

                        case 4:
                            cf.SearchForMunincipality(tccs);
                            break;

                        case 0:
                            finishedSearch = true;
                            break;
                        }
                    } while (finishedSearch == false);
                    break;

                case 0:
                    finished = true;
                    break;
                }
            } while (finished == false);
        }