PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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. //===================================================================================
  17. using System;
  18. using MVVM.Model;
  19. namespace MVVM.Test.Mocks
  20. {
  21. public class MockQuestionnaireService : IQuestionnaireService
  22. {
  23. public Action<AsyncResult<object>> HandleBeginSubmitResponses { get; set; }
  24. public Action<AsyncResult<Questionnaire>> HandleBeginGetQuestionnaire { get; set; }
  25. #region IQuestionnaireService
  26. public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState)
  27. {
  28. var result = new AsyncResult<object>(callback, asyncState);
  29. HandleBeginSubmitResponses(result);
  30. return result;
  31. }
  32. public virtual void EndSubmitResponses(IAsyncResult asyncResult)
  33. {
  34. AsyncResult<object>.End((AsyncResult<object>)asyncResult);
  35. }
  36. public IAsyncResult BeginGetQuestionnaire(AsyncCallback callback, object asyncState)
  37. {
  38. var result = new AsyncResult<Questionnaire>(callback, asyncState);
  39. HandleBeginGetQuestionnaire(result);
  40. return result;
  41. }
  42. public Questionnaire EndGetQuestionnaire(IAsyncResult asyncResult)
  43. {
  44. var result = (AsyncResult<Questionnaire>)asyncResult;
  45. AsyncResult<Questionnaire>.End(result);
  46. return result.Result;
  47. }
  48. #endregion
  49. public void ProceedSubmitResponses(AsyncResult<object> result)
  50. {
  51. result.SetComplete(null, false);
  52. }
  53. public void ProceedGetQuestionnaire(AsyncResult<Questionnaire> result, Questionnaire questionnaire)
  54. {
  55. result.SetComplete(questionnaire, false);
  56. }
  57. }
  58. }