コード例 #1
0
        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);
        }
コード例 #2
0
        public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState)
        {
            var result = new AsyncResult<object>(callback, asyncState);
            HandleBeginSubmitResponses(result);

            return result;
        }
コード例 #3
0
        public void WhenAgeIsSetToInvalidValue_ThenQuestionnaireIsNotComplete()
        {
            var questionnaire = new Questionnaire() { MaxAge = 100 };

            questionnaire.Name = "name";
            questionnaire.Age = 200;

            Assert.IsFalse(questionnaire.IsComplete);
        }
コード例 #4
0
        public void WhenNameAndAgeAreSetToValidValues_TheQuestionnaireIsComplete()
        {
            var questionnaire = new Questionnaire();

            questionnaire.Name = "name";
            questionnaire.Age = 25;

            Assert.IsTrue(questionnaire.IsComplete);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 public void ProceedGetQuestionnaire(AsyncResult<Questionnaire> result, Questionnaire questionnaire)
 {
     result.SetComplete(questionnaire, false);
 }
コード例 #9
0
 private void DoSubmitResponses(Questionnaire questionnaire)
 {
     // simulate submitting time
     Thread.Sleep(1000);
 }
コード例 #10
0
        private static Questionnaire CreateQuestionnaire()
        {
            var questionnaire = new Questionnaire(
                            new OpenQuestion("Enter your name") { MaxLength = 100 },
                            new OpenQuestion("Enter your address") { MaxLength = 100 }
            );

            return questionnaire;
        }
コード例 #11
0
        private static IOperationResult<Questionnaire> CreateQuestionnaireResult(Questionnaire questionnaire)
        {
            var result = new Mock<IOperationResult<Questionnaire>>();
            result.Setup(r => r.Result)
                .Returns(questionnaire);

            return result.Object;
        }
コード例 #12
0
        public void WhenCreated_TheQuestionnaireIsNotComplete()
        {
            var questionnaire = new Questionnaire();

            Assert.IsFalse(questionnaire.IsComplete);
        }