PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/Quickstarts/MVVM/MVVM.Test/Mocks/MockQuestionnaireService.cs

#
C# | 70 lines | 42 code | 12 blank | 16 comment | 0 complexity | e0e0ad3537f5bd69d363d81fd17f4b57 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using MVVM.Model;
19
20namespace MVVM.Test.Mocks
21{
22    public class MockQuestionnaireService : IQuestionnaireService
23    {
24        public Action<AsyncResult<object>> HandleBeginSubmitResponses { get; set; }
25        public Action<AsyncResult<Questionnaire>> HandleBeginGetQuestionnaire { get; set; }
26
27        #region IQuestionnaireService
28
29        public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState)
30        {
31            var result = new AsyncResult<object>(callback, asyncState);
32            HandleBeginSubmitResponses(result);
33
34            return result;
35        }
36
37        public virtual void EndSubmitResponses(IAsyncResult asyncResult)
38        {
39            AsyncResult<object>.End((AsyncResult<object>)asyncResult);
40        }
41
42        public IAsyncResult BeginGetQuestionnaire(AsyncCallback callback, object asyncState)
43        {
44            var result = new AsyncResult<Questionnaire>(callback, asyncState);
45            HandleBeginGetQuestionnaire(result);
46
47            return result;
48        }
49
50        public Questionnaire EndGetQuestionnaire(IAsyncResult asyncResult)
51        {
52            var result = (AsyncResult<Questionnaire>)asyncResult;
53            AsyncResult<Questionnaire>.End(result);
54
55            return result.Result;
56
57        }
58        #endregion
59
60        public void ProceedSubmitResponses(AsyncResult<object> result)
61        {
62            result.SetComplete(null, false);
63        }
64
65        public void ProceedGetQuestionnaire(AsyncResult<Questionnaire> result, Questionnaire questionnaire)
66        {
67            result.SetComplete(questionnaire, false);
68        }
69    }
70}