public async Task ReuseSessionWorks() { AkinatorUserSession userSessionFromFirstClient; var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using (IAkinatorClient client = new AkinatorClient(server)) { var question = await client.StartNewGame(); Assert.AreEqual(0, question.Step); question = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(1, question.Step); userSessionFromFirstClient = client.GetUserSession(); } using (IAkinatorClient newClient = new AkinatorClient(server, userSessionFromFirstClient)) { var question = await newClient.Answer(AnswerOptions.Yes); Assert.AreEqual(2, question.Step); } }
private async Task Start() { Console.WriteLine("Starting session..."); using (IAkinatorClient client = new AkinatorClient(Language.German, ServerType.Person)) { var question = await client.StartNewGame(); var answer = GetAnswerFor(question); do { question = await client.Answer(answer); if (client.GuessIsDue(question)) { var guess = await client.GetGuess(); if (VerifyGuess(guess)) { break; } } answer = GetAnswerFor(question); } while (true); } Console.WriteLine("Ending session..."); Console.ReadLine(); }
public async Task SimpleWorkflowTest_English_Object() { using (IAkinatorClient client = new AkinatorClient(Language.English, ServerType.Animal)) { var question = await client.StartNewGame(); while (true) { var nextQuestion = await client.Answer(AnswerOptions.Yes); if (!client.GuessIsDue(nextQuestion)) { continue; } var guess = await client.GetGuess(); if (!guess.Any()) { Assert.Fail("No guess was found"); } else { break; } } } }
public async Task SimpleWorkflowTest_AllLanguages() { var stopwatch = new Stopwatch(); stopwatch.Start(); var allLanguages = Enum.GetValues(typeof(Language)).Cast <Language>(); var tasks = allLanguages.AsParallel().Select(async language => { var elapsedLanguage = stopwatch.ElapsedMilliseconds; var servers = await m_serverLocator.SearchAllAsync(language).ConfigureAwait(false); foreach (var server in servers) { try { Console.WriteLine($"Testing - Language {language}, Type {server.ServerType} - STARTED"); using IAkinatorClient client = new AkinatorClient(server); await client.StartNewGame(); while (true) { var _ = await client.Answer(AnswerOptions.Yes).ConfigureAwait(false); if (!client.GuessIsDue()) { continue; } var guess = await client.GetGuess().ConfigureAwait(false); if (!guess.Any()) { Assert.Fail("No guess was found"); } else { break; } } } catch (Exception e) { Assert.Fail(e.ToString()); } finally { Console.WriteLine($"Testing - Language {language}, Type {server.ServerType} - DONE"); } } elapsedLanguage = stopwatch.ElapsedMilliseconds - elapsedLanguage; Console.WriteLine($"Took: {elapsedLanguage}ms"); }); await Task.WhenAll(tasks); Console.WriteLine($"Test done. Took {stopwatch.Elapsed.TotalSeconds}s."); }
public async Task SearchCharacter_ReturnsValidCharactersForASearchTerm() { var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using IAkinatorClient client = new AkinatorClient(server); await client.StartNewGame(); var chars = await client.SearchCharacter("Brat Pitt"); Assert.IsTrue(chars.Any(p => p.Name.Contains("brat pitt", StringComparison.InvariantCultureIgnoreCase))); }
public async Task ChildModeDoesNotThrowAnyExceptions() { var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using IAkinatorClient client = new AkinatorClient(server, childMode: true); var questionStart = await client.StartNewGame(); var nextQuestion = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(0, questionStart.Step); Assert.AreEqual(1, nextQuestion.Step); }
public async Task StartNewGameThrowsExceptionOnCancelled() { using (IAkinatorClient client = new AkinatorClient(Language.English, ServerType.Person)) { var src = new CancellationTokenSource(); var cancellationToken = src.Token; src.Cancel(); await client.StartNewGame(cancellationToken); } Assert.Fail("No exception was thrown"); }
public async Task StartNewGameThrowsExceptionOnCancelled() { var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using (IAkinatorClient client = new AkinatorClient(server)) { var src = new CancellationTokenSource(); var cancellationToken = src.Token; src.Cancel(); await client.StartNewGame(cancellationToken); } Assert.Fail("No exception was thrown"); }
public async Task CurrentQuestionReturnsCurrentQuestion() { var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using IAkinatorClient client = new AkinatorClient(server); var questionStart = await client.StartNewGame(); Assert.AreEqual(questionStart.Text, client.CurrentQuestion.Text); questionStart = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(questionStart.Text, client.CurrentQuestion.Text); questionStart = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(questionStart.Text, client.CurrentQuestion.Text); questionStart = await client.UndoAnswer(); Assert.AreEqual(questionStart.Text, client.CurrentQuestion.Text); }
public async Task UndoWorksAsExpected() { var server = await m_serverLocator.SearchAsync(Language.English, ServerType.Person).ConfigureAwait(false); using IAkinatorClient client = new AkinatorClient(server); var questionStart = await client.StartNewGame(); Assert.AreEqual(0, questionStart.Step); var question1 = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(1, question1.Step); var question2 = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(2, question2.Step); var questionPrevious = await client.UndoAnswer(); Assert.AreEqual(1, questionPrevious.Step); Assert.AreEqual(question1.Text, questionPrevious.Text); }
public async Task ReuseSessionWorks() { AkinatorUserSession userSessionFromFirstClient; using (IAkinatorClient client = new AkinatorClient(Language.English, ServerType.Person)) { var question = await client.StartNewGame(); Assert.AreEqual(0, question.Step); question = await client.Answer(AnswerOptions.Yes); Assert.AreEqual(1, question.Step); userSessionFromFirstClient = client.GetUserSession(); } using (IAkinatorClient newClient = new AkinatorClient(Language.English, ServerType.Person, userSessionFromFirstClient)) { var question = await newClient.Answer(AnswerOptions.Yes); Assert.AreEqual(2, question.Step); } }