public IEnumerator multiAskTest() { AnswerManager manager = new GameObject("AnswerManager").AddComponent <AnswerManager>(); TestRequest requestA = new TestRequest(); var taskA = manager.ask(0, requestA, 3); yield return(new WaitForSeconds(2)); TestRequest requestB = new TestRequest(); var taskB = manager.ask(0, requestB, 3); yield return(new WaitForSeconds(2)); TestRequest requestC = new TestRequest(); var taskC = manager.ask(0, requestC, 3); yield return(new WaitForSeconds(2)); TestResponse responseC = new TestResponse(); Assert.True(manager.answer(0, responseC).Result); TestResponse responseB = new TestResponse(); Assert.True(manager.answer(0, responseB).Result); yield return(new WaitForSeconds(1)); TestResponse responseA = new TestResponse(); Assert.False(manager.answer(0, responseA).Result); Assert.AreEqual(responseC, taskC.Result); Assert.AreEqual(responseB, taskB.Result); Assert.AreNotEqual(responseA, taskA.Result); }
public IEnumerator askAnyTest() { AnswerManager manager = new GameObject("AnswerManager").AddComponent <AnswerManager>(); TestRequest request = new TestRequest(); var task = manager.askAny(new int[] { 1, 2, 3 }, request, 3, r => r is TestResponse tr && tr.boolean == true);//询问123,必须回应tr且boolean为true Assert.False(manager.answer(3, new TestResponse() { boolean = false }).Result); //3回复false,不通过 yield return(new WaitForSeconds(1)); TestResponse response = new TestResponse() { boolean = true }; Assert.True(manager.answer(2, response).Result);//2回复true,通过 yield return(new WaitForSeconds(1)); Assert.False(manager.answer(1, response).Result);//1回复true,但是已经有2回复了 Assert.True(task.IsCompleted); Assert.AreEqual(response, task.Result); }
public IEnumerator answerTest() { AnswerManager manager = new GameObject("AnswerManager").AddComponent <AnswerManager>(); TestRequest request = new TestRequest(); var task = manager.ask(0, request, 3); TestResponse response = new TestResponse(); Assert.True(manager.answer(0, response).Result); Assert.True(task.IsCompleted); Assert.AreEqual(response, task.Result); yield break; }
public IEnumerator timeOutAnswerTest() { AnswerManager manager = new GameObject("AnswerManager").AddComponent <AnswerManager>(); TestRequest request = new TestRequest(); var task = manager.ask(0, request, 3); TestResponse response = new TestResponse() { boolean = true }; yield return(new WaitForSeconds(3)); Assert.False(manager.answer(0, response).Result); Assert.True(task.IsCompleted); Assert.False((task.Result as TestResponse).boolean); yield break; }