public HomeController(PlanetLogic planetLogic, StarLogic starLogic, SystemLogic systemLogic, StatsLogic statsLogic) { this.planetLogic = planetLogic; this.starLogic = starLogic; this.systemLogic = systemLogic; this.statsLogic = statsLogic; }
public HomeController(CarsLogic carsLogic, SalonsLogic salonsLogic, RentersLogic rentersLogic, StatsLogic statsLogic) { this.carsLogic = carsLogic; this.salonsLogic = salonsLogic; this.rentersLogic = rentersLogic; this.statsLogic = statsLogic; }
public void TestPlanetTypeGrouped() { Mock <IRepository <Planet> > planetRepo = new Mock <IRepository <Planet> >(); Mock <IRepository <Star> > starRepo = new Mock <IRepository <Star> >(); Mock <IRepository <Models.System> > systemRepo = new Mock <IRepository <Models.System> >(); List <Planet> planets = new List <Planet>() { new Planet() { PlanetID = "#1", StarID = "#1", PlanetType = PlanetType.Terran }, new Planet() { PlanetID = "#2", StarID = "#1", PlanetType = PlanetType.Terran }, new Planet() { PlanetID = "#3", StarID = "#2", PlanetType = PlanetType.Jovian }, new Planet() { PlanetID = "#4", StarID = "#3", PlanetType = PlanetType.Neptunian }, new Planet() { PlanetID = "#5", StarID = "#4", PlanetType = PlanetType.Subterran }, }; List <Star> stars = new List <Star>() { new Star() { StarID = "#1", Age = 1500000 }, new Star() { StarID = "#2", Age = 800000 }, new Star() { StarID = "#3", Age = 1000001 }, new Star() { StarID = "#4", Age = 999999 }, }; planetRepo.Setup(r => r.Read()).Returns(planets.AsQueryable()); starRepo.Setup(r => r.Read()).Returns(stars.AsQueryable()); StatsLogic logic = new StatsLogic(planetRepo.Object, starRepo.Object, systemRepo.Object); var result = logic.PlanetTypeGrouped(); Assert.That(result.Single(x => x.Type == PlanetType.Terran).NumberOfStars, Is.EqualTo(1)); Assert.That(result.Single(x => x.Type == PlanetType.Neptunian).NumberOfStars, Is.EqualTo(1)); starRepo.Verify(r => r.Read(), Times.Once); planetRepo.Verify(r => r.Read(), Times.Once); }
public void TestPopulationInSectors() { Mock <IRepository <Planet> > planetRepo = new Mock <IRepository <Planet> >(); Mock <IRepository <Star> > starRepo = new Mock <IRepository <Star> >(); Mock <IRepository <Models.System> > systemRepo = new Mock <IRepository <Models.System> >(); List <Planet> planets = new List <Planet>() { new Planet() { PlanetID = "#1", StarID = "#1", Population = 10 }, new Planet() { PlanetID = "#2", StarID = "#1", Population = 20 }, new Planet() { PlanetID = "#3", StarID = "#2", Population = 30 }, new Planet() { PlanetID = "#4", StarID = "#3", Population = 40 }, new Planet() { PlanetID = "#5", StarID = "#4", Population = 50 }, }; List <Star> stars = new List <Star>() { new Star() { StarID = "#1", SystemID = "#1", Planets = new Planet[] { planets[0], planets[1] } }, new Star() { StarID = "#2", SystemID = "#2", Planets = new Planet[] { planets[2] } }, new Star() { StarID = "#3", SystemID = "#2", Planets = new Planet[] { planets[3] } }, new Star() { StarID = "#4", SystemID = "#3", Planets = new Planet[] { planets[4] } }, }; List <Models.System> systems = new List <Models.System>() { new Models.System() { SystemID = "#1", SectorName = "A", Stars = new Star[] { stars[0] } }, new Models.System() { SystemID = "#2", SectorName = "A", Stars = new Star[] { stars[1], stars[2] } }, new Models.System() { SystemID = "#3", SectorName = "B", Stars = new Star[] { stars[3] } } }; planetRepo.Setup(r => r.Read()).Returns(planets.AsQueryable()); starRepo.Setup(r => r.Read()).Returns(stars.AsQueryable()); systemRepo.Setup(r => r.Read()).Returns(systems.AsQueryable()); StatsLogic logic = new StatsLogic(planetRepo.Object, starRepo.Object, systemRepo.Object); var result = logic.PopulationInSectors(); Assert.That(result.Single(x => x.SectorType == "A").Population, Is.EqualTo(100)); Assert.That(result.Single(x => x.SectorType == "B").Population, Is.EqualTo(50)); systemRepo.Verify(r => r.Read(), Times.Once); starRepo.Verify(r => r.Read(), Times.Once); planetRepo.Verify(r => r.Read(), Times.Once); }
public void TestStarsWithLife() { Mock <IRepository <Planet> > planetRepo = new Mock <IRepository <Planet> >(); Mock <IRepository <Star> > starRepo = new Mock <IRepository <Star> >(); Mock <IRepository <Models.System> > systemRepo = new Mock <IRepository <Models.System> >(); List <Star> stars = new List <Star>() { new Star() { StarID = "#1" }, new Star() { StarID = "#2" }, new Star() { StarID = "#3" }, }; List <Star> expected = new List <Star>() { new Star() { StarID = "#1" }, new Star() { StarID = "#2" }, }; List <Planet> planets = new List <Planet>() { new Planet() { PlanetID = "#1", Habitable = true, StarID = "#1" }, new Planet() { PlanetID = "#2", Habitable = false, StarID = "#1" }, new Planet() { PlanetID = "#3", Habitable = false, StarID = "#2" }, new Planet() { PlanetID = "#4", Habitable = false, StarID = "#2" }, new Planet() { PlanetID = "#5", Habitable = true, StarID = "#2" }, }; planetRepo.Setup(r => r.Read()).Returns(planets.AsQueryable()); starRepo.Setup(r => r.Read()).Returns(stars.AsQueryable()); StatsLogic logic = new StatsLogic(planetRepo.Object, starRepo.Object, systemRepo.Object); var result = logic.StarsWithLife(); Assert.That(result, Is.EquivalentTo(expected)); starRepo.Verify(r => r.Read(), Times.Once); planetRepo.Verify(r => r.Read(), Times.Once); }
static void Main(string[] args) { //create a new instance of DataAccessLayer class DataAccess data = new DataAccess(); DataAccess delete = new DataAccess(); //Creating new instances of the LogicLayer Class TeamsLogic TLogic = new TeamsLogic(); StatsLogic SLogic = new StatsLogic(); string yes; do { // create a console menu for the user Console.WriteLine("What would you like to do?"); Console.WriteLine("(A) Add something"); Console.WriteLine("(D) Delete something"); Console.WriteLine("(U) update something"); Console.WriteLine("(V) View something"); Console.WriteLine("(L) Leave Team"); Console.WriteLine("(J) Join Team"); //String left "Empty" string PST = "Empty"; //create a variable for CRUD, Team //ToUpper to Convert User Input to UpperCase string CRUD = Console.ReadLine().ToUpper().Trim(); if (CRUD.Equals("L") && CRUD.Equals("J")) { //Only applies to the Teams Data } else { PST = whichtable(); } bool success = false; //create a switch case to determine which method will be applied switch (CRUD) { //Adding Case case "A": switch (PST) { //"P" to add a Player to the DB case "P": success = data.AddPlayer(_mapper.Map(PlayerInfo())); //indicate wheather a record was created based on the bool above if (success) { Console.WriteLine("You have added a new Player!"); } else { Console.WriteLine("Sorry, Something went wrong. No Player Was Added."); } break; case "S": PO_Stats NewStats = StatsInfo(); success = SLogic.AddStats(_LLMap.map(_mapper.Map(NewStats))); //indicate wheather a record was created based on the bool above if (success) { Console.WriteLine("You have added a new Stats!"); } else { Console.WriteLine("Sorry, Something went wrong. No Stats Were Added."); } break; case "T": success = data.AddTeams(_mapper.Map(TeamsInfo())); //indicate wheather a record was created based on the bool above if (success) { Console.WriteLine("You have added a new Team!"); } else { Console.WriteLine("Sorry, Something went wrong. No Team Was Added."); } break; } break; //this case deletes case "D": switch (PST) { //this is to delete a book case "P": success = data.DeletePlayer(Name("PlayerName")); if (success) { Console.WriteLine("The Player was successfully deleted."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; case "S": success = data.DeleteStats(Name("PlayerName")); if (success) { Console.WriteLine("The Stat was successfully deleted."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; case "T": success = data.DeleteTeam(Name("Team")); if (success) { Console.WriteLine("The Team was successfully deleted."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; } break; //this case updates case "U": switch (PST) { case "P": PO_Player updatePlayer = PlayerInfo(); updatePlayer.PlayerName = Name("PlayerName"); success = data.UpdatePlayer(_mapper.Map(updatePlayer)); if (success) { Console.WriteLine("The Player was successfully Updated."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; case "S": PO_Stats updateStats = StatsInfo(); updateStats.FKPlayerName = Name("PlayerName"); success = data.UpdateStats(_mapper.Map(updateStats)); if (success) { Console.WriteLine("The Stat was successfully Updated."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; case "T": PO_Teams updateTeam = TeamsInfo(); updateTeam.TeamName = Name("TeamName"); success = data.UpdateTeams(_mapper.Map(updateTeam)); if (success) { Console.WriteLine("The Team was successfully Updated."); } else { Console.WriteLine("Sorry, Something went wrong."); } break; } break; //this case Views case "V": switch (PST) { case "P": List <PO_Player> PlayerToView = new List <PO_Player>(); PlayerToView = _mapper.Map(data.GetAllPlayers()); foreach (PO_Player singlePlayer in PlayerToView) { Console.WriteLine(singlePlayer.PlayerID + " | Player Name: " + singlePlayer.PlayerName + " | First Name: " + singlePlayer.PlayerFirstName + " | Last Name: " + singlePlayer.PlayerLastName + " | City: " + singlePlayer.PlayerCity + " | State: " + singlePlayer.PlayerState + " | Age: " + singlePlayer.PlayerAge); } break; case "S": List <PO_Stats> StatsToView = new List <PO_Stats>(); StatsToView = _mapper.Map(data.GetAllStats()); foreach (PO_Stats SingleStat in StatsToView) { Console.WriteLine(" | Player Name: " + SingleStat.FKPlayerName + " | Kills: " + SingleStat.Kills + " | Deaths: " + SingleStat.Deaths + " | Average: " + SingleStat.Average); } break; case "T": List <PO_Teams> TeamsToView = new List <PO_Teams>(); TeamsToView = _mapper.Map(data.GetAllTeams()); foreach (PO_Teams SingleTeam in TeamsToView) { Console.WriteLine("|` Team name:" + SingleTeam.TeamName + "| Description: " + SingleTeam.TeamDescription + "| Open Slots: " + SingleTeam.PositionsAvaliable + "| Filled Spots:" + SingleTeam.PositionsTaken + "| Team Members:" + SingleTeam.FKPlayerName); } break; } break; // this case checks in case "L": // Get TeamName to find what team to Leave string LeaveTeam = Name("Teams"); TeamsDAO LeaveTeamDAO = data.viewSingleTeam(LeaveTeam); // Makes sure there is is a position to leave if (LeaveTeamDAO.PositionsTaken > 0) { success = TLogic._LeaveTeam(_LLMap.map(LeaveTeamDAO)); } if (success) { Console.WriteLine("You have left the team."); } else { Console.WriteLine("Sorry,Something happend. You were unable to leave the team."); } break; case "J": // Get Team Name to find the team wanting to be joined string JoinTeam = Name("Teams"); TeamsDAO JoinTeamDAO = data.viewSingleTeam(JoinTeam); // Makes sure there is a position to join if (JoinTeamDAO.PositionsAvaliable > 0) { success = TLogic._JoinTeam(_LLMap.map(JoinTeamDAO)); } if (success) { Console.WriteLine("You have successfully Joined the Team! Welcome!."); } else { Console.WriteLine("Sorry The position you are trying to Join is unavaliable. You were Unable to Join the team."); } break; } Console.WriteLine("Do you wish to continue? Y/N"); yes = Console.ReadLine().ToUpper().Trim(); }while (yes.Equals("Y")); Console.ReadLine(); }