public void SubmitQuestionnaireAsync(Questionnaire questionnaire, Action<IOperationResult> callback) { this.service.BeginSubmitResponses( questionnaire, (ar) => { var operationResult = new OperationResult(); try { this.service.EndSubmitResponses(ar); } catch (Exception ex) { operationResult.Error = ex; } synchronizationContext.Post( (state) => { callback(operationResult); }, null); }, null); }
public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState) { var result = new AsyncResult<object>(callback, asyncState); HandleBeginSubmitResponses(result); return result; }
public void WhenAgeIsSetToInvalidValue_ThenQuestionnaireIsNotComplete() { var questionnaire = new Questionnaire() { MaxAge = 100 }; questionnaire.Name = "name"; questionnaire.Age = 200; Assert.IsFalse(questionnaire.IsComplete); }
public void WhenNameAndAgeAreSetToValidValues_TheQuestionnaireIsComplete() { var questionnaire = new Questionnaire(); questionnaire.Name = "name"; questionnaire.Age = 25; Assert.IsTrue(questionnaire.IsComplete); }
public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState) { var result = new AsyncResult<object>(callback, asyncState); ThreadPool.QueueUserWorkItem( state => { DoSubmitResponses(questionnaire); result.SetComplete(null, false); }); return result; }
public void WhenQueryingForQuestionnares_ThenProvidesQuestionnaireResult() { AsyncResult<Questionnaire> ar = null; Questionnaire suppliedQuestionnaire = new Questionnaire(); var serviceMock = new MockQuestionnaireService(); serviceMock.HandleBeginGetQuestionnaire = (r) => ar = r; var repository = new QuestionnaireRepository(serviceMock); IOperationResult<Questionnaire> getResult = null; repository.GetQuestionnaireAsync((result) => getResult = result); serviceMock.ProceedGetQuestionnaire(ar, suppliedQuestionnaire); EnqueueConditional(() => getResult != null); EnqueueCallback(() => { Assert.AreSame(suppliedQuestionnaire, getResult.Result); }); EnqueueTestComplete(); }
private Questionnaire DoGetQuestionnaire() { // simulate loading time Thread.Sleep(1000); var questionnaire = new Questionnaire( new NumericQuestion("How many times do you eat out per month?") { MaxValue = 15 }, new MultipleSelectionQuestion( "Which are your favorite entries? (Max. 2)", new[] { "Pizza", "Pasta", "Steak", "Ribs" }) { MaxSelections = 2 }, new OpenQuestion("What appetizers would you add to the menu?") { MaxLength = 250 }, new OpenQuestion("Do you have any feedback for the management?") { MaxLength = 250 }) { NameMaxLength = 50, MaxAge = 120, MinAge = 16 }; return questionnaire; }
public void ProceedGetQuestionnaire(AsyncResult<Questionnaire> result, Questionnaire questionnaire) { result.SetComplete(questionnaire, false); }
private void DoSubmitResponses(Questionnaire questionnaire) { // simulate submitting time Thread.Sleep(1000); }
private static Questionnaire CreateQuestionnaire() { var questionnaire = new Questionnaire( new OpenQuestion("Enter your name") { MaxLength = 100 }, new OpenQuestion("Enter your address") { MaxLength = 100 } ); return questionnaire; }
private static IOperationResult<Questionnaire> CreateQuestionnaireResult(Questionnaire questionnaire) { var result = new Mock<IOperationResult<Questionnaire>>(); result.Setup(r => r.Result) .Returns(questionnaire); return result.Object; }
public void WhenCreated_TheQuestionnaireIsNotComplete() { var questionnaire = new Questionnaire(); Assert.IsFalse(questionnaire.IsComplete); }