public async Task AssignOnePortrait_PlayerAlreadyHas_TooltipUpdated() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 3 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); var playerTag = "cepheid#1467"; var personalSettings = new PersonalSetting(playerTag); personalSettings.SpecialPictures.Append(new SpecialPicture(3, "initialTestDescription")); await personalSettingsRepository.Save(personalSettings); var portraitsCommand = new PortraitsCommand(); portraitsCommand.Portraits.Add(3); portraitsCommand.BnetTags.Add(playerTag); portraitsCommand.Tooltip = "testTooltip"; await portraitCommandHandler.UpsertSpecialPortraits(portraitsCommand); var settings = await personalSettingsRepository.Load(playerTag); Assert.AreEqual(1, settings.SpecialPictures.Count()); Assert.AreEqual(3, settings.SpecialPictures.First().PictureId); Assert.AreEqual("testTooltip", settings.SpecialPictures.First().Description); }
public async Task UpdateGroups_PortraitDefinitionExists_Success() { var settingsRepo = new PersonalSettingsRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var playeRepo = new PlayerRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(settingsRepo, playeRepo, portraitRepo); int[] portraitIds = { 1, 2, 3, 4 }; string[] portraitGroups = { "brozne", "silver" }; var defineCommand = CreatePortraitsDefinitionCommand(portraitIds.ToList(), portraitGroups.ToList()); await portraitCommandHandler.AddPortraitDefinition(defineCommand); int[] portraitsToUpdate = { 1, 4 }; string[] portraitGroupToUpdate = { "gold" }; var updateCommand = CreatePortraitsDefinitionCommand(portraitsToUpdate.ToList(), portraitGroupToUpdate.ToList()); await portraitCommandHandler.UpdatePortraitDefinition(updateCommand); var portraits = await portraitCommandHandler.GetPortraitDefinitions(); var definitionsWithGold = portraits.FindAll(x => x.Groups.Count() == 1); var definitionsWithBronzeSilver = portraits.FindAll(x => x.Groups.Count() == 2); Assert.AreEqual(4, portraits.Count()); Assert.AreEqual(2, definitionsWithGold.Count()); Assert.AreEqual(2, definitionsWithBronzeSilver.Count()); }
public async Task AssignOnePortrait_PlayerDoesNotHave_CaseInsensitiveTag_Success() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 5 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); var playerTagA = "CePhEiD#1467"; var playerTagB = "cEpHeId#1467"; var personalSettings = new PersonalSetting(playerTagB); await personalSettingsRepository.Save(personalSettings); var portraitsCommand = new PortraitsCommand(); portraitsCommand.Portraits.Add(5); portraitsCommand.BnetTags.Add(playerTagA); portraitsCommand.Tooltip = "testTooltip"; await portraitCommandHandler.UpsertSpecialPortraits(portraitsCommand); var settings = await personalSettingsRepository.Load(playerTagA); Assert.AreEqual(1, settings.SpecialPictures.Count()); Assert.AreEqual(5, settings.SpecialPictures.First().PictureId); Assert.AreEqual("testTooltip", settings.SpecialPictures.First().Description); }
public async Task RemoveSpecialPortraits_PlayersHave_Success() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 5, 50, 500, 5000 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); string[] playerTags = { "cepheid#1467" }; var portraitIds = new List <int>(); portraitIds.Add(5); portraitIds.Add(50); portraitIds.Add(500); portraitIds.Add(5000); var upsertCommand = new PortraitsCommand(); upsertCommand.Portraits = portraitIds; upsertCommand.BnetTags = playerTags.AsEnumerable().ToList(); upsertCommand.Tooltip = "description"; var listOfSettings = new List <PersonalSetting>(); foreach (var tag in playerTags) { listOfSettings.Add(new PersonalSetting(tag)); } await personalSettingsRepository.SaveMany(listOfSettings); await portraitCommandHandler.UpsertSpecialPortraits(upsertCommand); var deleteCommand = new PortraitsCommand(); deleteCommand.Portraits = new List <int>(); deleteCommand.Portraits.Add(500); deleteCommand.BnetTags = playerTags.AsEnumerable().ToList(); deleteCommand.Tooltip = "Multiple Tags Portrait Test Tooltip"; await portraitCommandHandler.DeleteSpecialPortraits(deleteCommand); var settings = await personalSettingsRepository.LoadMany(playerTags); Assert.AreEqual(3, settings.First().SpecialPictures.Count()); CollectionAssert.IsEmpty(settings .FindAll(x => x.SpecialPictures .AsEnumerable() .ToList() .FindAll(x => x.PictureId == 500) .Count() > 0)); }
public async Task RemoveSpecialPortrait_PlayerDoesNotHave_NoExceptionThrown() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 5, 50, 500, 5000 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); string[] playerTags = { "cepheid#1467" }; var portraitIds = new List <int>(); portraitIds.Add(5); portraitIds.Add(50); portraitIds.Add(500); portraitIds.Add(5000); var upsertCommand = new PortraitsCommand(); upsertCommand.Portraits = portraitIds; upsertCommand.BnetTags = playerTags.AsEnumerable().ToList(); upsertCommand.Tooltip = "description"; var listOfSettings = new List <PersonalSetting>(); foreach (var tag in playerTags) { listOfSettings.Add(new PersonalSetting(tag)); } await personalSettingsRepository.SaveMany(listOfSettings); await portraitCommandHandler.UpsertSpecialPortraits(upsertCommand); var deleteCommand = new PortraitsCommand(); deleteCommand.Portraits = new List <int>(); deleteCommand.Portraits.Add(100); deleteCommand.BnetTags = playerTags.AsEnumerable().ToList(); deleteCommand.Tooltip = "this text is irrelevant"; await portraitCommandHandler.DeleteSpecialPortraits(deleteCommand); var settings = await personalSettingsRepository.Load(playerTags[0]); Assert.AreEqual(4, settings.SpecialPictures.Count()); }
public async Task AssignMultiplePortraitsToMultipleTags_SomePlayersAlreadyHave_UpsertsProcessCorrectly() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 1, 50, 500, 5000 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); var listOfSettings = new List <PersonalSetting>(); string[] playerTags = { "cepheid#1467", "modmoto#123", "toxi#4321" }; listOfSettings.Add(new PersonalSetting(playerTags[0])); listOfSettings.Add(new PersonalSetting(playerTags[1])); listOfSettings.Add(new PersonalSetting(playerTags[2])); listOfSettings.First().SpecialPictures.Append(new SpecialPicture(50, "fifty")); await personalSettingsRepository.SaveMany(listOfSettings); var portraitIds = new List <int>(); portraitIds.Add(1); portraitIds.Add(50); portraitIds.Add(500); portraitIds.Add(5000); var portraitsCommand = new PortraitsCommand(); portraitsCommand.Portraits = portraitIds; portraitsCommand.BnetTags = playerTags.AsEnumerable().ToList(); portraitsCommand.Tooltip = "allTagsUpdatedWithThis"; await portraitCommandHandler.UpsertSpecialPortraits(portraitsCommand); var settingsList = await personalSettingsRepository.LoadMany(playerTags); Assert.AreEqual(3, settingsList.Count()); Assert.AreEqual(3, settingsList.FindAll(x => x.SpecialPictures.Length == 4).Count()); Assert.AreEqual("allTagsUpdatedWithThis", settingsList.Find(x => x.Id == "cepheid#1467") .SpecialPictures .AsEnumerable() .ToList() .Find(x => x.PictureId == 50) .Description); }
public async Task AssignMultiplePortraitsToMultipleTags_PlayersDoNotHave_Success() { var personalSettingsRepository = new PersonalSettingsRepository(MongoClient); var playerRepo = new PlayerRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(personalSettingsRepository, playerRepo, portraitRepo); int[] validPortraits = { 1, 50, 500, 5000 }; await portraitCommandHandler.AddPortraitDefinition(CreatePortraitsDefinitionCommand(validPortraits.ToList(), new List <string>())); var listOfSettings = new List <PersonalSetting>(); string[] playerTags = { "cepheid#1467", "modmoto#123", "toxi#4321" }; listOfSettings.Add(new PersonalSetting(playerTags[0])); listOfSettings.Add(new PersonalSetting(playerTags[1])); listOfSettings.Add(new PersonalSetting(playerTags[2])); var portraitIds = new List <int>(); portraitIds.Add(1); portraitIds.Add(50); portraitIds.Add(500); portraitIds.Add(5000); await personalSettingsRepository.SaveMany(listOfSettings); var portraitsCommand = new PortraitsCommand(); portraitsCommand.Portraits = portraitIds; portraitsCommand.BnetTags = playerTags.AsEnumerable().ToList(); portraitsCommand.Tooltip = "Multiple Tags Portrait Test Tooltip"; await portraitCommandHandler.UpsertSpecialPortraits(portraitsCommand); var settingsList = await personalSettingsRepository.LoadMany(playerTags); Assert.AreEqual(3, settingsList.Count()); Assert.AreEqual(4, settingsList.First().SpecialPictures.Count()); Assert.AreEqual(3, settingsList.FindAll(x => x.SpecialPictures.Length == 4).Count()); Assert.AreEqual("Multiple Tags Portrait Test Tooltip", settingsList.Last().SpecialPictures.First().Description); }
public async Task UpdateGroups_PortraitDefinitionDoesntExist_NoError() { var settingsRepo = new PersonalSettingsRepository(MongoClient); var portraitRepo = new PortraitRepository(MongoClient); var playeRepo = new PlayerRepository(MongoClient); var portraitCommandHandler = new PortraitCommandHandler(settingsRepo, playeRepo, portraitRepo); int[] portraitIds = { 1, 2, 3, 4 }; string[] portraitGroups = { "bronze", "silver" }; var defineCommand = CreatePortraitsDefinitionCommand(portraitIds.ToList(), portraitGroups.ToList()); await portraitCommandHandler.AddPortraitDefinition(defineCommand); int[] portraitsToUpdate = { 5 }; string[] portraitGroupToUpdate = { "gold" }; var updateCommand = CreatePortraitsDefinitionCommand(portraitsToUpdate.ToList(), portraitGroupToUpdate.ToList()); await portraitCommandHandler.UpdatePortraitDefinition(updateCommand); var portraits = await portraitCommandHandler.GetPortraitDefinitions(); Assert.AreEqual(4, portraits.Count()); }