public async Task <int> CreateStatsAsync(MonsterCreationOption creationOption) { try { var _monsterStatsGenerator = _monsterStatsGeneratorStrategyFactory.Get(creationOption); var monsterStats = new List <MonsterStats> { _monsterStatsGenerator.GenerateMonsterStats(creationOption) }; ConsoleTableBuilder.From(monsterStats) .WithFormat(ConsoleTableBuilderFormat.MarkDown) .ExportAndWriteLine(); if (creationOption.WriteToFile) { await _fileCreatorService.CreateFile(creationOption.Path, monsterStats); } } catch (Exception ex) { _logger.LogDebug(ex, "Something went wrong..."); return(-1); } return(0); }
public MonsterStats GenerateMonsterStats(MonsterCreationOption monsterCreationOption) { return(new MonsterStats { AC = 13, HP = 24, Attack = 4, Damage = 8, DC = 11, Save = 3 }); }
public MonsterStats GenerateMonsterStats(MonsterCreationOption monsterCreationOption) { return(new MonsterStats { AC = 13 + Convert.ToInt32(Math.Floor(monsterCreationOption.CR / 3)), HP = Convert.ToInt32(15 * monsterCreationOption.CR), Attack = 4 + Convert.ToInt32(Math.Floor(monsterCreationOption.CR / 2)), Damage = Convert.ToInt32(5 * monsterCreationOption.CR), DC = 11 + Convert.ToInt32(Math.Floor(monsterCreationOption.CR / 2)), Save = 3 + Convert.ToInt32(Math.Floor(monsterCreationOption.CR / 2)) }); }
public MonsterStats GenerateMonsterStats(MonsterCreationOption monsterCreationOption) { return(new MonsterStats { AC = 12, HP = 9, Attack = 3, Damage = 3, DC = 10, Save = 2 }); }
public MonsterStats GenerateMonsterStats(MonsterCreationOption monsterCreationOption) { return(new MonsterStats { AC = 12, HP = 3, Attack = 2, Damage = 1, DC = 9, Save = 1 }); }
public IMonsterStatsGeneratorStrategy Get(MonsterCreationOption monsterCreationOptions) { return(monsterCreationOptions.CR switch { 0 => new MonsterWithCRZeroStatsGeneratorStrategy(), 0.125 => new MonsterWithCROneEightStatsGeneratorStrategy(), 0.25 => new MonsterWithCROneQuarterStatsGeneratorStrategy(), 0.5 => new MonsterWithCRHalfStatsGeneratorStrategy(), 1 => new MonsterWithCROneStatsGeneratorStrategy(), double cr when cr >= 2 && cr < 8 => new MonsterWithCRBetweenTwoAndSevenStatsGeneratorStrategy(), double cr when cr >= 8 => new MonsterWithCREightOrHigherStatsGeneratorStrategy(), _ => throw new NotImplementedException(), });
public async Task GivenValidCreationOptionsAndWriteToFile_CreateStatsAsync_ShouldReturnOkStatusAndCallCreateFile(MonsterCreationOption creationOption, Mock <IMonsterStatsGeneratorStrategy> monsterStatsGeneratorStrategy, MonsterStats monsterStats) { creationOption.WriteToFile = true; monsterStatsGeneratorStrategy.Setup(m => m.GenerateMonsterStats(It.Is <MonsterCreationOption>(c => c == creationOption))).Returns(monsterStats); _monsterStatsGeneratorStrategyFactory.Setup(m => m.Get(It.Is <MonsterCreationOption>(o => o == creationOption))).Returns(monsterStatsGeneratorStrategy.Object); var actual = await _sut.CreateStatsAsync(creationOption); actual.Should().Be(0); _fileCreatorService.Verify(c => c.CreateFile(It.IsAny <string>(), It.IsAny <List <MonsterStats> >()), Times.Once); }
public async Task GivenErrorInMonsterStatsGeneratorStrategyFactory_CreateStatsAsync_ShouldReturnErrorAndLog(MonsterCreationOption creationOption) { _monsterStatsGeneratorStrategyFactory.Setup(m => m.Get(It.Is <MonsterCreationOption>(o => o == creationOption))).Throws(new NotImplementedException()); Func <object, Type, bool> state = (v, t) => v?.ToString().CompareTo("Something went wrong...") == 0; var actual = await _sut.CreateStatsAsync(creationOption); actual.Should().Be(-1); _logger.Verify( x => x.Log( It.Is <LogLevel>(l => l == LogLevel.Debug), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => state(v, t)), It.IsAny <NotImplementedException>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once); }