public void GetLessonsForStudent_StudentHasNoEnrolments() { var context = InMemoryContextFactory.CreateSchoolContext(); var testStudent = new Student() { Name = "Testee", Email = "*****@*****.**", Degree = "Bachelor of Testing" }; var testStaff = new Staff() { Name = "Tester", Email = "*****@*****.**", JobTitle = "Lead tester" }; var testSubject1 = new Subject() { Code = "TES101", Name = "Intro to testing", Description = "The basics of good unit testing" }; var testSubject2 = new Subject() { Code = "TES102", Name = "Testing fundamentals", Description = "The next steps for good unit testing" }; context.Add(testStudent); context.Add(testStaff); context.AddRange(testSubject1, testSubject2); context.SaveChanges(); Assert.That(TimetableHelper.GetLessonsForStudent(testStudent), Is.Empty, "Student timetable should be empty"); }
private GameContext GetTestContext(string testDb) { //Prep a context and controller GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb)); //Add the civilization seed data gameContext.Civs.Add(new Civ { Id = 1, Name = "test", AstStone = 4, AstEarlyBronze = 7, AstLateBronze = 10, AstEarlyIron = 13, AstLateIron = 16 }); //Add a sample activeCiv gameContext.ActiveCivs.Add(new ActiveCiv { Id = 1, CivId = 1, GameName = "controller unit test", CurrentPhase = (int)ActiveCiv.Phases.TaxToSupport }); gameContext.SaveChanges(); return(gameContext); }
public void CreatorTest() { var contextFactory = new InMemoryContextFactory(); var context = contextFactory.CreateContext <TestDataContext>((string)null); Assert.NotNull(context); }
public void CanResolveCalculateSpendLimit(int treasury, Commodity[] commodities, int expectedSpendLimit) { int expectedPhase = (int)ActiveCiv.Phases.BuyAdvances; //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("calculate_spend_limit"); GameContext context = new GameContext(options); //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { OwnedAdvancements = new Collection <OwnedAdvancement> { } }) .Entity; context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act testLoop.ResolveCalculateSpendLimit(treasury, commodities); //Assert Assert.Equal(expectedSpendLimit, testLoop.ActiveCiv.SpendLimit); Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase); }
public void CanResolveMoveAst(int astPosition, int cities, int expectedResult) { //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("move_ast"); GameContext context = new GameContext(options); //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { Civ = new Civ { AstStone = 5, AstEarlyBronze = 8, AstLateBronze = 11, AstEarlyIron = 14, AstLateIron = 16 }, Cities = cities, AstPosition = astPosition, OwnedAdvancements = new Collection <OwnedAdvancement> { } }) .Entity; context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act int actualResult = testLoop.ResolveMoveAst(); //Assert Assert.Equal(expectedResult, actualResult); }
public void CanCheckForGameEnd(int astPosition, bool expectedResult, int expectedPhase) { //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("game_end"); GameContext context = new GameContext(options); //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { CurrentPhase = (int)ActiveCiv.Phases.MoveAST, Civ = new Civ { AstLateIron = 16 }, AstPosition = astPosition, }) .Entity; context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act bool actualResult = testLoop.CheckForGameEnd(); //Assert Assert.Equal(expectedResult, actualResult); Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase); }
public void CanCheckPlayerCanAffordAdvancements(string dbString, int spendLimit, int[] advancements, bool expectedResult) { //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions(dbString); GameContext context = new GameContext(options); //Add advancements foreach (int advancementId in advancements) { context.Advancements.Add(new Advancement { Id = advancementId, BaseCost = 50 }); } //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { SpendLimit = spendLimit, OwnedAdvancements = new Collection <OwnedAdvancement> { } }) .Entity; context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act bool actualResult = testLoop.CheckPlayerCanAffordAdvancements(advancements); //Assert Assert.Equal(expectedResult, actualResult); }
public void CanResolveTaxToSupport() { int expectedCities = 4; int expectedPhase = (int)ActiveCiv.Phases.CalculateSpendLimit; //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions("Tax_to_support"); GameContext context = new GameContext(options); //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { OwnedAdvancements = new Collection <OwnedAdvancement> { } }) .Entity; context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act testLoop.ResolveTaxToSupport(expectedCities); //Assert Assert.Equal(expectedCities, testLoop.ActiveCiv.Cities); Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase); }
public CompraServiceTestes() { _context = InMemoryContextFactory.Create(); _revendedorRepository = new RevendedorRepository(_context); _revendedorService = new RevendedorService(_revendedorRepository, null); _configuration = InMemoryContextFactory.CreateConfiguration(); _repository = new CompraRepository(_context); _service = new CompraService(_configuration, _repository, _revendedorRepository, null); }
public AdministratorControllerTests() { this.contextFactory = new InMemoryContextFactory(); this.loggerMock = new Mock <ILogger <AdministratorController> >(); this.helperMock = new Mock <ILanguageHelper>(); this.helperMock .Setup(h => h.LanguagePathFolder) .Returns("./../../../../../data/Language/"); }
private GameContext GetTestContext(string testDb) { //Prep a context and controller GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb)); foreach (Advancement advancement in Iteration1Seeder.GetSeedAdvancements()) { gameContext.Advancements.Add(advancement); } gameContext.SaveChanges(); return(gameContext); }
private GameContext GetTestContext(string testDb) { //Prep a context and controller GameContext gameContext = new GameContext(InMemoryContextFactory.GetContextOptions(testDb)); //Add the civilization seed data foreach (Civ civ in Iteration1Seeder.GetSeedCivilizations()) { gameContext.Civs.Add(civ); } //Add a sample activeCiv gameContext.ActiveCivs.Add(new ActiveCiv { Id = 1, CivId = 4, GameName = "controller unit test" }); gameContext.SaveChanges(); return(gameContext); }
public void GetLessonsForStudent() { var context = InMemoryContextFactory.CreateSchoolContext(); var testStudent = new Student() { Name = "Testee", Email = "*****@*****.**", Degree = "Bachelor of Testing" }; var testStaff = new Staff() { Name = "Tester", Email = "*****@*****.**", JobTitle = "Lead tester" }; var testSubject1 = new Subject() { Code = "TES101", Name = "Intro to testing", Description = "The basics of good unit testing" }; var testSubject2 = new Subject() { Code = "TES102", Name = "Testing fundamentals", Description = "The next steps for good unit testing" }; var testSubject3 = new Subject() { Code = "TES103", Name = "Advanced Testing", Description = "Advanced theory unit testing" }; var testClass1 = new Lesson() { Subject = testSubject1, Teacher = testStaff, StartTime = "MON 10:00", EndTime = "MON 11:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var testClass2 = new Lesson() { Subject = testSubject1, Teacher = testStaff, StartTime = "TUE 10:00", EndTime = "TUE 11:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var testClass3 = new Lesson() { Subject = testSubject1, Teacher = testStaff, StartTime = "WED 10:00", EndTime = "WED 11:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var testClass4 = new Lesson() { Subject = testSubject2, Teacher = testStaff, StartTime = "MON 11:00", EndTime = "MON 12:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var testClass5 = new Lesson() { Subject = testSubject2, Teacher = testStaff, StartTime = "TUE 11:00", EndTime = "TUE 12:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var testClass6 = new Lesson() { Subject = testSubject3, Teacher = testStaff, StartTime = "MON 13:00", EndTime = "TUE 14:00", LessonType = LessonType.Lecture, RoomNumber = "123" }; var enrolment1 = new Enrolment() { Student = testStudent, Subject = testSubject1 }; var enrolment2 = new Enrolment() { Student = testStudent, Subject = testSubject3 }; context.Add(testStudent); context.Add(testStaff); context.AddRange(testSubject1, testSubject2, testSubject3); context.AddRange(testClass1, testClass2, testClass3, testClass4, testClass5, testClass6); context.AddRange(enrolment1, enrolment2); context.SaveChanges(); Assert.That(TimetableHelper.GetLessonsForStudent(testStudent), Is.EquivalentTo(new[] { testClass1, testClass2, testClass3, testClass6 }), "Student timetable should contain 4 lessons"); }
public void CanResolveBuyAdvances(string dbString, int[] newAdvances, int[] existingAdvances, bool expectedAffordability) { int expectedPhase = (int)ActiveCiv.Phases.MoveAST; //Build the list of expected advancements after purchase List <int> expectedAdvancements = new List <int>(existingAdvances); if (expectedAffordability) { foreach (int newAdvance in newAdvances) { expectedAdvancements.Add(newAdvance); } } //Prep the context DbContextOptions <GameContext> options = InMemoryContextFactory.GetContextOptions(dbString); GameContext context = new GameContext(options); //Add advancements foreach (int advancementId in newAdvances) { context.Advancements.Add(new Advancement { Id = advancementId, BaseCost = 50 }); } foreach (int advancementId in existingAdvances) { context.Advancements.Add(new Advancement { Id = advancementId, BaseCost = 50 }); } //Create an active civ ActiveCiv activeCiv = context.ActiveCivs .Add(new ActiveCiv { SpendLimit = 100, OwnedAdvancements = new Collection <OwnedAdvancement> { } }) .Entity; //Add the existing advancements to the active civ and build the list of expected advancements after buying the new ones foreach (int existingAdvance in existingAdvances) { activeCiv.OwnedAdvancements.Add(new OwnedAdvancement { AdvancementId = existingAdvance }); } context.SaveChanges(); //Make the game loop GameLoop testLoop = new GameLoop(context, activeCiv.Id); //Act bool result = testLoop.ResolveBuyAdvances(newAdvances); //Assert //Assert that the advances were bought (or not) as expected Assert.Equal(expectedAffordability, result); //Assert correct phase Assert.Equal(expectedPhase, testLoop.ActiveCiv.CurrentPhase); //Assert expected number of owned advancements Assert.Equal(expectedAdvancements.Count, testLoop.ActiveCiv.OwnedAdvancements.Count); /* Assert that all of the expected owned advancements are present * (and with the previous assertion, only those advancements) */ foreach (int expectedAdvancementId in expectedAdvancements) { Assert.Equal( expectedAdvancementId, testLoop.ActiveCiv.OwnedAdvancements.Single(a => a.AdvancementId == expectedAdvancementId).AdvancementId ); } }
public RevendedorServiceTestes() { _context = InMemoryContextFactory.Create(); _repository = new RevendedorRepository(_context); _service = new RevendedorService(_repository, null); }