Ejemplo n.º 1
0
        public async Task SetMethods()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var repo             = new PilotRepo(AccountContextProvider, Logger, null);

            // stage 1
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        Name      = "Pilot1",
                        Skills    = new List <Skill>(),
                        EveId     = 1,
                        KeyInfoId = 10,
                    },
                    new Pilot()
                    {
                        EveId     = 2,
                        Name      = "Pilot2",
                        Skills    = new List <Skill>(),
                        KeyInfoId = 11
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await repo.Update(userid, userData);

            Assert.AreNotEqual(0, userData.Pilots[0].PilotId);

            await repo.SetFreeManufacturingJobsNofificationCount(userData.Pilots[0].PilotId, 10);

            await repo.SetFreeResearchJobsNofificationCount(userData.Pilots[1].PilotId, 20);

            var pilots = await repo.GetAll(userid);

            Assert.AreEqual(2, pilots.Count);

            var p1 = pilots.FirstOrDefault(x => x.PilotId == userData.Pilots[0].PilotId);
            var p2 = pilots.FirstOrDefault(x => x.PilotId == userData.Pilots[1].PilotId);

            Assert.IsNotNull(p1);
            Assert.IsNotNull(p2);
            Assert.AreEqual(10, p1.FreeManufacturingJobsNofificationCount);
            Assert.AreEqual(0, p1.FreeResearchJobsNofificationCount);
            Assert.AreEqual(20, p2.FreeResearchJobsNofificationCount);
            Assert.AreEqual(0, p2.FreeManufacturingJobsNofificationCount);
        }
        public async Task TestPilotGetAll()
        {
            /// ARRANGE

            var repo   = new PilotRepo(_context);
            var pilot  = CreatePilot("*****@*****.**");
            var pilot2 = CreatePilot("*****@*****.**");

            /// ACT

            await AddForTest(pilot);
            await AddForTest(pilot2);

            var pilots = await repo.GetAll();

            /// ASSERT

            Assert.IsTrue(pilots.ToList().Count == 2);
        }
        public async Task TestPilotGetUser()
        {
            /// ARRANGE

            // setup PilotRepo to be tested
            var repo = new PilotRepo(_context);
            // setup pilot with name, email, aircraft and a password
            var pilot = CreatePilot("*****@*****.**");

            /// ACT

            await AddForTest(pilot);

            var foundPilot = repo.GetUser(pilot.EmailId).Result;

            /// ASSERT

            Assert.IsNotNull(foundPilot);
        }
        public async Task TestWhetherPilotGotAdded()
        {
            /// ARRANGE

            // setup PilotRepo to be tested
            var repo = new PilotRepo(_context);
            // setup pilot with name, email, aircraft and a password
            var pilot = CreatePilot("*****@*****.**");

            /// ACT

            // call the method to be tested
            await repo.Add(pilot);

            var result = await(_context.Pilots.Where(p => p.EmailId == pilot.EmailId).FirstOrDefaultAsync());

            /// ASSERT

            // if pilot was successfully added, testResult shouldn't be null
            Assert.IsNotNull(result);
        }
        public async Task TestWhetherPilotWasDeleted()
        {
            /// ARANGE

            // setup PilotRepo to be tested
            var repo = new PilotRepo(_context);
            //Aircraft aircraft = _context.Aircrafts.Find("F-16");
            // setup pilot with name, email, aircraft and a password
            var pilot = CreatePilot("*****@*****.**");

            /// ACT

            await AddForTest(pilot);

            await repo.Delete(pilot.EmailId);

            var result = await(_context.Pilots.Where(p => p.EmailId == pilot.EmailId).FirstOrDefaultAsync());

            /// ASSERT

            Assert.IsNull(result);
        }
        public async Task TestWhetherPilotUpdated()
        {
            /// ARRAGNE

            var repo     = new PilotRepo(_context);
            var pilot    = CreatePilot("*****@*****.**");
            var oldPilot = pilot;

            /// ACT

            await AddForTest(pilot);

            pilot.Name = "UPDATED NAME";
            await repo.Update(pilot);

            var pilots = await _context.Pilots.ToListAsync();

            var foundPilot = pilots.Where(p => p.Name == pilot.Name).FirstOrDefault();

            /// ASSERT

            Assert.IsTrue(foundPilot.Name == pilot.Name && foundPilot.EmailId == oldPilot.EmailId);
        }
Ejemplo n.º 7
0
        public async Task SinglePilot()
        {
            // MicioGatto key
            long   code  = 3645238;
            string vcode = "sLOD3pSHwuzKtml3inm59qvVWHiKA3rULJY7KRsuWmmHrZ0c8qAZlftLDQIHvxBq";

            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var keyRepo = new KeyInfoRepo(Logger, AccountContextProvider);
            await keyRepo.AddKey(userid, code, vcode);

            var pilotRepo           = new PilotRepo(AccountContextProvider, Logger, EveApi);
            var corpoRepo           = new CorporationRepo(AccountContextProvider, Logger, EveApi);
            var notificationRepo    = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo           = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var skillInQueueRepo    = new SkillInQueueRepo(AccountContextProvider, Logger);
            var evePilotDataService = new EvePilotDataService(keyRepo, EveApi, Logger, TypeNameDict);

            var backgroundUpdate = new BackgroundUpdate(evePilotDataService, pilotRepo, corpoRepo, skillRepo, skillInQueueRepo);

            await backgroundUpdate.Update(userid);

            var pilots = await pilotRepo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);

            var p = pilots.First();

            Assert.AreEqual("MicioGatto", p.Name);
            Assert.IsTrue(p.Skills.Count > 0);
            Assert.IsTrue(p.SkillsInQueue.Count > 0);

            Assert.IsTrue(p.Skills.Any(x => x.SkillName == "Interceptors"));
        }
Ejemplo n.º 8
0
        public async Task SkillsNotificationLevelUp()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var pilotRepo        = new PilotRepo(AccountContextProvider, Logger, null);

            // stage 1 - skills firstly seen - no notification expected
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = 1,
                        Name      = "Pilot1",
                        Skills    = new Skill[] { new Skill()
                                                  {
                                                      SkillName = "skilla", Level = 1
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skillb", Level = 2
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skill ", Level = 3
                                                  } }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData);

            await skillRepo.Update(userid, userData);

            var skills = await skillRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(3, skills.Count);

            var notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(0, notifications.Count());

            // stage 2 - level up
            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = 1,
                        Name      = "Pilot1",
                        Skills    = new Skill[] { new Skill()
                                                  {
                                                      SkillName = "skilla", Level = 1
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skillb", Level = 2
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skill ", Level = 4
                                                  } }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData2);

            await skillRepo.Update(userid, userData2);

            skills = await skillRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(3, skills.Count);

            notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(1, notifications.Count);
            var n = notifications.First(x => x.Message2.Contains("skill  4"));

            Assert.AreEqual("Pilot1", n.Message);
            Assert.AreEqual("skill  4 trained", n.Message2);
            await notificationRepo.Remove(n.NotificationId);
        }
Ejemplo n.º 9
0
        public async Task PilotDeleteByKey()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var repo             = new PilotRepo(AccountContextProvider, Logger, null);
            var keyRepo          = new KeyInfoRepo(Logger, AccountContextProvider);

            long keyid1 = await keyRepo.AddKey(userid, 1, "");

            long keyid2 = await keyRepo.AddKey(userid, 2, "");

            // stage 1
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = keyid1,
                        Name      = "Pilot1",
                        Skills    = new List <Skill>()
                    },
                    new Pilot()
                    {
                        EveId     = 2,
                        KeyInfoId = keyid2,
                        Name      = "Pilot2",
                        Skills    = new List <Skill>()
                    },
                    new Pilot()
                    {
                        EveId     = 3,
                        KeyInfoId = keyid2,
                        Name      = "Pilot3",
                        Skills    = new List <Skill>()
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await repo.Update(userid, userData);

            var pilots = await repo.GetAll(userid);

            Assert.AreEqual(3, pilots.Count);

            await repo.DeleteByKey(keyid2);

            pilots = await repo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
            Assert.AreEqual("Pilot1", pilots.First().Name);

            // delete using non existing key
            await repo.DeleteByKey(keyid1 + keyid2 + 1);

            pilots = await repo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
        }
Ejemplo n.º 10
0
        public async Task UpdatePilotsAndCorporations2()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var repo = new CorporationRepo(AccountContextProvider, Logger, null);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var pilotrepo        = new PilotRepo(AccountContextProvider, Logger, null);
            var corporepo        = new CorporationRepo(AccountContextProvider, Logger, null);

            // stage 1
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = 1,
                        Name      = "Pilot1",
                        Skills    = new List <Skill>()
                    }
                }.ToList(),
                Corporations = new Corporation[]
                {
                    new Corporation()
                    {
                        EveId = 1, Name = "Corpo1", KeyInfoId = 2
                    }
                }.ToList(),
                Jobs = new List <Job>(),
            };

            await pilotrepo.Update(userid, userData);

            await corporepo.Update(userid, userData);

            var pilots = await pilotrepo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
            Assert.AreEqual("Pilot1", pilots.First().Name);

            var corporations = await corporepo.GetAll(userid);

            Assert.AreEqual(1, corporations.Count);
            Assert.AreEqual("Corpo1", corporations.First().Name);

            // stage 2
            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                }.ToList(),
                Corporations = new Corporation[]
                {
                }.ToList(),
                Jobs = new List <Job>(),
            };

            await pilotrepo.Update(userid, userData2);

            await corporepo.Update(userid, userData2);

            pilots = await pilotrepo.GetAll(userid);

            Assert.AreEqual(0, pilots.Count);
            corporations = await corporepo.GetAll(userid);

            Assert.AreEqual(0, corporations.Count);

            // No notifications expected
            var notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(0, notifications.Count);
        }
Ejemplo n.º 11
0
        public async Task UpdatePilots1()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var repo             = new PilotRepo(AccountContextProvider, Logger, null);


            // stage 1
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = 2,
                        Name      = "Pilot1",
                        Skills    = new List <Skill>()
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await repo.Update(userid, userData);

            Assert.AreNotEqual(0, userData.Pilots[0].PilotId);

            var pilots = await repo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
            Assert.AreEqual("Pilot1", pilots.First().Name);

            // stage 2
            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 2,
                        KeyInfoId = 3,
                        Name      = "Pilot2",
                        Skills    = new List <Skill>()
                    },
                    new Pilot()
                    {
                        EveId     = 3,
                        KeyInfoId = 3,
                        Name      = "Pilot3",
                        Skills    = new List <Skill>()
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await repo.Update(userid, userData2);

            Assert.AreNotEqual(0, userData2.Pilots[0].PilotId);
            Assert.AreNotEqual(0, userData2.Pilots[1].PilotId);
            Assert.AreNotEqual(userData2.Pilots[0].PilotId, userData2.Pilots[1].PilotId);

            pilots = await repo.GetAll(userid);

            Assert.AreEqual(2, pilots.Count);
            Assert.AreEqual("Pilot2", pilots.First(x => x.Name == "Pilot2").Name);
            Assert.AreEqual("Pilot3", pilots.First(x => x.Name == "Pilot3").Name);

            // No notifications expected
            var notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(0, notifications.Count);
        }
Ejemplo n.º 12
0
 /*set pilot repo pattern upon instantiation of flights controller*/
 public FlightsController(FlightRepo db_flights, RouteRepo db_route, PilotRepo db_pilot)
 {
     _db_flights = db_flights;
     _db_route   = db_route;
     _db_pilot   = db_pilot;
 }
Ejemplo n.º 13
0
 /* Set pilot repo upon instantiation of controller */
 public SignUpController(PilotRepo db)
 {
     _db = db;
 }
Ejemplo n.º 14
0
        public async Task SkillInQueueOperations()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var skillInQueueRepo = new SkillInQueueRepo(AccountContextProvider, Logger);
            var pilotRepo        = new PilotRepo(AccountContextProvider, Logger, null);

            // stage 1 - skills firstly seen - no notification expected
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId         = 1,
                        KeyInfoId     = 1,
                        Name          = "Pilot1",
                        Skills        = new List <Skill>(),
                        SkillsInQueue =
                            new SkillInQueue[]
                        {
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 1, Order = 1
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skillb", Level = 2, Order = 2
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skillc", Level = 3, Order = 3
                            }
                        }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData);

            await skillInQueueRepo.Update(userid, userData);

            var skills = await skillInQueueRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(3, skills.Count);
            foreach (var s in skills)
            {
                Assert.IsTrue(s.Order > 0);
            }

            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId         = 1,
                        KeyInfoId     = 1,
                        Name          = "Pilot1",
                        Skills        = new List <Skill>(),
                        SkillsInQueue =
                            new SkillInQueue[]
                        {
                            new SkillInQueue()
                            {
                                SkillName = "skilld", Level = 1
                            },
                        }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData2);

            await skillInQueueRepo.Update(userid, userData2);

            skills = await skillInQueueRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(1, skills.Count);
            Assert.AreEqual("skilld", skills[0].SkillName);
        }
Ejemplo n.º 15
0
 /*set pilot repo pattern upon instantiation of about controller*/
 public HomeController(PilotRepo db)
 {
     _db_ = db;
 }
Ejemplo n.º 16
0
        public async Task DeleteKey()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var pilotRepo        = new PilotRepo(AccountContextProvider, Logger, null);
            var keyRepo          = new KeyInfoRepo(Logger, AccountContextProvider);

            long keyid1 = await keyRepo.AddKey(userid, 1, "");

            long keyid2 = await keyRepo.AddKey(userid, 2, "");

            // stage 1 - skills firstly seen - no notification expected
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId     = 1,
                        KeyInfoId = keyid1,
                        Name      = "Pilot1",
                        Skills    = new Skill[] { new Skill()
                                                  {
                                                      SkillName = "skill", Level = 1
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skill", Level = 2
                                                  } }.ToList(),
                    },
                    new Pilot()
                    {
                        EveId     = 2,
                        KeyInfoId = keyid2,
                        Name      = "Pilot2",
                        Skills    = new Skill[] { new Skill()
                                                  {
                                                      SkillName = "skill", Level = 1
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skill", Level = 2
                                                  } }.ToList(),
                    },
                    new Pilot()
                    {
                        EveId     = 3,
                        KeyInfoId = keyid2,
                        Name      = "Pilot3",
                        Skills    = new Skill[] { new Skill()
                                                  {
                                                      SkillName = "skilla", Level = 1
                                                  }, new Skill()
                                                  {
                                                      SkillName = "skilla", Level = 2
                                                  } }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData);

            await skillRepo.Update(userid, userData);

            var skills = await skillRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(2, skills.Count);

            await pilotRepo.DeleteByKey(keyid2);

            skills = await skillRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(2, skills.Count);

            using (var ctx = AccountContextProvider.Context)
            {
                var c = ctx.Skills.Count(p => p.PilotId == userData.Pilots[1].PilotId);
                Assert.AreEqual(0, c);
                c = ctx.Skills.Count(p => p.PilotId == userData.Pilots[2].PilotId);
                Assert.AreEqual(0, c);
            }
        }
Ejemplo n.º 17
0
 /* Set context upon instantiation of controller */
 public ScheduleController(PilotRepo db_pilots, FlightRepo db_flights, RouteRepo db_route)
 {
     _db_pilots  = db_pilots;
     _db_flights = db_flights;
     _db_route   = db_route;
 }
Ejemplo n.º 18
0
        public async Task MultipleLevels3()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var skillInQueueRepo = new SkillInQueueRepo(AccountContextProvider, Logger);
            var pilotRepo        = new PilotRepo(AccountContextProvider, Logger, null);

            // stage 1 - skills firstly seen - no notification expected
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId         = 1,
                        KeyInfoId     = 1,
                        Name          = "Pilot1",
                        Skills        = new List <Skill>(),
                        SkillsInQueue =
                            new SkillInQueue[]
                        {
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 1
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 2
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 3
                            }
                        }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData);

            await skillInQueueRepo.Update(userid, userData);

            var skills = await skillInQueueRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(3, skills.Count);

            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId         = 1,
                        KeyInfoId     = 1,
                        Name          = "Pilot1",
                        Skills        = new List <Skill>(),
                        SkillsInQueue =
                            new SkillInQueue[]
                        {
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 1
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 2
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 3
                            },
                            new SkillInQueue()
                            {
                                SkillName = "skilla", Level = 4
                            }
                        }.ToList(),
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotRepo.Update(userid, userData2);

            await skillInQueueRepo.Update(userid, userData2);

            skills = await skillInQueueRepo.GetForPilot(userData.Pilots[0].PilotId);

            Assert.AreEqual(4, skills.Count);
        }
Ejemplo n.º 19
0
        public async Task JobsNotification()
        {
            var accrepo = AccountRepo;
            var skey    = await accrepo.RegisterUser("*****@*****.**", "123");

            var userid = await accrepo.CheckSession(skey);

            var notificationRepo = new NotificationRepo(AccountContextProvider, Logger);
            var skillRepo        = new SkillRepo(AccountContextProvider, Logger, notificationRepo);
            var pilotsRepo       = new PilotRepo(AccountContextProvider, Logger, null);
            var jobsRepo         = new JobRepo(AccountContextProvider, Logger, notificationRepo, pilotsRepo);

            // stage 1
            var userData = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId                = 1,
                        KeyInfoId            = 1,
                        Name                 = "Pilot1",
                        Skills               = new List <Skill>(),
                        MaxManufacturingJobs = 1,
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new List <Job>(),
            };

            await pilotsRepo.Update(userid, userData);

            await jobsRepo.Update(userid, userData);

            var notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(1, notifications.Count);
            var n = notifications.First();

            Assert.AreEqual("Pilot1", n.Message);
            Assert.AreEqual("1 free manufacturing slots", n.Message2);
            await notificationRepo.Remove(n.NotificationId);

            // stage 2
            // Same info provided and expected no further notifications
            await pilotsRepo.Update(userid, userData);

            await jobsRepo.Update(userid, userData);

            notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(0, notifications.Count);
            var pilots = await pilotsRepo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
            Assert.AreEqual(1, pilots.First().FreeManufacturingJobsNofificationCount);

            // stage 3
            // First job started - still no notification - but notification flag shoud be reset
            var userData2 = new UserDataDto()
            {
                Pilots = new Pilot[]
                {
                    new Pilot()
                    {
                        EveId                = 1,
                        KeyInfoId            = 1,
                        Name                 = "Pilot1",
                        Skills               = new List <Skill>(),
                        MaxManufacturingJobs = 1,
                    }
                }.ToList(),
                Corporations = new List <Corporation>(),
                Jobs         = new Job[]
                {
                    new Job()
                    {
                        IsManufacturing = true, Owner = "Pilot1"
                    }
                }.ToList(),
            };
            await pilotsRepo.Update(userid, userData2);

            await jobsRepo.Update(userid, userData2);

            notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(0, notifications.Count());
            pilots = await pilotsRepo.GetAll(userid);

            Assert.AreEqual(1, pilots.Count);
            Assert.AreEqual(0, pilots.First().FreeManufacturingJobsNofificationCount);

            // stage 4
            // No running jobs - notification expected
            await pilotsRepo.Update(userid, userData);

            await jobsRepo.Update(userid, userData);

            notifications = await notificationRepo.GetAll(userid);

            Assert.AreEqual(1, notifications.Count());
            n = notifications.First();
            Assert.AreEqual("Pilot1", n.Message);
            Assert.AreEqual("1 free manufacturing slots", n.Message2);
            await notificationRepo.Remove(n.NotificationId);
        }
Ejemplo n.º 20
0
 /* Set context upon instantiation of controller */
 public LoginController(PilotRepo db)
 {
     _db = db;
 }