public async Task CreateSkillAsync_AlreadyExists_ReturnNameAlreadyExists() { var charProvider = new MockCharacterProvider(); var statProvider = new MockStatisticProvider(); var controller = new StatisticController(charProvider, statProvider, null); var result = await controller.CreateSkillAsync("Powerlifting", "Strength"); Assert.Equal(StatisticResult.NameAlreadyExists(), result); }
/// <summary> /// Creates a new Skill in the database. /// </summary> /// <param name="statName">The name for the new skill.</param> /// <param name="attribName">The name of the attribute to go with the skill. Must exist in the database beforehand.</param> /// <returns> /// A result detailing if the operation was successful or why it failed. /// </returns> public async Task <IResult> CreateSkillAsync(string statName, string attribName) { if (await _statProvider.GetStatisticAsync(statName) != null) { return(StatisticResult.NameAlreadyExists()); } var result = await _statProvider.CreateSkillAsync(statName, attribName); if (result == null) { return(StatisticResult.StatisticCreationFailed()); } return(StatisticResult.StatisticCreatedSuccessfully()); }
/// <summary> /// Adds an alias to an already existing statistic. /// </summary> /// <param name="statName">The name of the statistic to add an alias to.</param> /// <param name="alias">The new alias to add.</param> /// <returns>A result detailing if the operation was successful or why it failed.</returns> public async Task <IResult> AddAliasAsync(string statName, string alias) { var stat = await _statProvider.GetStatisticAsync(statName); if (stat == null) { return(StatisticResult.StatisticNotFound()); } if (await _statProvider.GetStatisticAsync(alias) != null) { return(StatisticResult.NameAlreadyExists()); } stat.Aliases += alias + "/"; await _statProvider.UpdateStatisticAsync(stat); return(StatisticResult.StatisticUpdatedSucessfully()); }
/// <summary> /// Renames an already existing statistic. /// </summary> /// <param name="statName">The name of the statistic to rename.</param> /// <param name="newName">The new name of the statistic.</param> /// <returns>A result detailing if the operation was successful or why it failed.</returns> /// <remarks>This method will also clear its aliases.</remarks> public async Task <IResult> RenameStatisticAsync(string statName, string newName) { var stat = await _statProvider.GetStatisticAsync(statName); if (stat == null) { return(StatisticResult.StatisticNotFound()); } if (await _statProvider.GetStatisticAsync(newName) != null) { return(StatisticResult.NameAlreadyExists()); } stat.Name = newName; stat.Aliases = newName + "/"; await _statProvider.UpdateStatisticAsync(stat); return(StatisticResult.StatisticUpdatedSucessfully()); }