public async void CampaignDetailsWorks(int id, string name) { var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>() .UseInMemoryDatabase("campaign_details_test").Options; using (var db = new Data.D20CharacterDatabaseContext(options)) { Lib.IRepo sut = new Data.D20Repo(db); Lib.Campaign camp = new Lib.Campaign(); if (await db.Campaign.FirstOrDefaultAsync(c => c.CampaignId == 1) == null) { camp.CampID = 0; camp.Name = "No Campaign"; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); db.Campaign.Add(camp); db.SaveChanges(); } camp.CampID = id; camp.Name = name; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); sut.CreateCampaign(camp); Data.Campaign testCamp = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == name); bool actual = (testCamp != null && testCamp.CampaignName == name); Assert.True(actual); camp = sut.CampDetails(testCamp.CampaignId); actual = camp.Name == name; Assert.True(actual); } }
public async void JoinCampWorks() { var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>() .UseInMemoryDatabase("join_campaign_test").Options; using (var db = new Data.D20CharacterDatabaseContext(options)) { Lib.IRepo sut = new Data.D20Repo(db); Lib.Campaign camp = new Lib.Campaign(); if (await db.Campaign.FirstOrDefaultAsync(c => c.CampaignId == 1) == null) { camp.CampID = 0; camp.Name = "No Campaign"; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); db.Campaign.Add(camp); db.SaveChanges(); } camp.CampID = 0; camp.Name = "Test Campaign"; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); sut.CreateCampaign(camp); Data.Campaign testCamp = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == camp.Name); Lib.Character testChar = new Lib.Character(); if (await db.Characters.FirstOrDefaultAsync(c => c.CharacterId == 1) == null) { testChar.CharID = 0; testChar.Name = "No Character"; testChar.CampID = 1; testChar.UserID = 1; db.Characters.Add(testChar); db.SaveChanges(); } testChar.CharID = 0; testChar.Name = "Test Character"; testChar.CampID = 0; testChar.UserID = 1; sut.CreateCharacter(testChar); Data.Characters test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar.Name); bool actual = (testCamp != null && testCamp.CampaignName == camp.Name && test != null && test.CampaignId != testCamp.CampaignId); Assert.True(actual); sut.JoinCamp(testCamp.CampaignId, test.CharacterId); test = await db.Characters.FirstOrDefaultAsync(c => c.CharacterName == testChar.Name); actual = (test.CampaignId == testCamp.CampaignId); Assert.True(actual); } }
public async void CampaignListWorks() { var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>() .UseInMemoryDatabase("campaign_list_test").Options; using (var db = new Data.D20CharacterDatabaseContext(options)) { Lib.IRepo sut = new Data.D20Repo(db); Lib.Campaign camp = new Lib.Campaign(); if (await db.Campaign.FirstOrDefaultAsync(c => c.CampaignId == 1) == null) { camp.CampID = 0; camp.Name = "No Campaign"; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); db.Campaign.Add(camp); db.SaveChanges(); } camp.CampID = 0; camp.Name = "Test Campaign"; camp.Characters = new List <Lib.Character>(); camp.GMs = new List <Lib.User>(); sut.CreateCampaign(camp); Lib.Campaign camp2 = new Lib.Campaign(); camp2.CampID = 0; camp2.Name = "Test Campaign2"; camp2.Characters = new List <Lib.Character>(); camp2.GMs = new List <Lib.User>(); sut.CreateCampaign(camp2); Data.Campaign testCamp = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == camp.Name); Data.Campaign testCamp2 = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == camp2.Name); bool actual = (testCamp != null && testCamp.CampaignName == camp.Name && testCamp2 != null && testCamp2.CampaignName == camp2.Name); Assert.True(actual); IList <Lib.Campaign> campList = (List <Lib.Campaign>)sut.CampList(); actual = (campList.Count == 3 && campList[1].Name == camp.Name && campList[2].Name == camp2.Name); Assert.True(actual); } }