Guest User

Untitled

a guest
Mar 5th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. using System;
  2. using Rhino.Mocks;
  3. using Rhino.Mocks.Constraints;
  4. using Unite.Messaging;
  5. using Unite.Messaging.Entities;
  6. using Unite.Messaging.Messages;
  7. using Unite.Messaging.Services;
  8.  
  9. namespace Unite.Specs.FakeSpecObjects
  10. {
  11. public static class ScenarioExtensions
  12. {
  13. public static IMessagingService Assume_it_can_find_any_address(this IMessagingService plugin)
  14. {
  15. plugin.Stub(x => x.CanFind(null))
  16. .IgnoreArguments()
  17. .Return(true);
  18. return plugin;
  19. }
  20.  
  21. public static IPluginFinder Assume_a_single_messaging_service_is_found(this IPluginFinder finder)
  22. {
  23. finder.Stub(x => x.GetAllPlugins())
  24. .Return(new[] { typeof(IMessagingService) });
  25.  
  26. return finder;
  27. }
  28.  
  29. public static IMessagingService Assume_a_message_will_be_sent_and_deliver_the_arguments_to(this IMessagingService plugin, Action<IIdentity, string> callback)
  30. {
  31. plugin.Stub(x => x.SendMessage(null, null))
  32. .Callback<IIdentity, string>((x, y) =>
  33. {
  34. callback(x, y);
  35. return true;
  36. });
  37.  
  38. return plugin;
  39. }
  40.  
  41. /// <summary>
  42. /// This method doesn't care what credentials are provided as long as **something** is.
  43. /// </summary>
  44. /// <param name="gui"></param>
  45. public static IInteractionContext Assume_some_credential_is_provided(this IInteractionContext gui)
  46. {
  47. gui.Stub(x => x.GetCredentials(null))
  48. .Return(new ScenarioRepository().CreateFakeCredentials());
  49. return gui;
  50. }
  51.  
  52. public static IInteractionContext Assume_valid_credentials_are_provided_for_the_correct_service(this IInteractionContext gui)
  53. {
  54. gui.Stub(x => x.GetCredentials(null))
  55. .IgnoreArguments()
  56. .Return(null)
  57. .WhenCalled(x =>
  58. {
  59. var info = (ServiceInformation) x.Arguments[0];
  60. x.ReturnValue = new Credentials()
  61. {
  62. ServiceInformation = info,
  63. UserName = "Test user",
  64. Password = "Test pw"
  65. };
  66. });
  67. return gui;
  68. }
  69.  
  70. public static IPluginFinder Assume_that_two_different_plugins_are_found(this IPluginFinder finder)
  71. {
  72. finder.Stub(x => x.GetAllPlugins())
  73. .Return(new[] { typeof(FakeTwitterPlugin), typeof(FakeGTalkPlugin) });
  74. return finder;
  75. }
  76.  
  77. public static void Assume_code_was_pasted_and_return(this ICodePaste codePaster, string codeSampleUrl)
  78. {
  79. codePaster.Stub(x => x.PasteCode(null))
  80. .Constraints(Is.Anything())
  81. .Return(codeSampleUrl);
  82. }
  83.  
  84. public static void Assume_these_plugins_were_found(this IPluginFinder finder, params Type[] types)
  85. {
  86. finder
  87. .Stub(x => x.GetAllPlugins())
  88. .Return(types);
  89. }
  90. }
  91.  
  92. public class FakeTwitterPlugin : FakePlugin
  93. {
  94. public string MessageSent;
  95.  
  96. public override void SendMessage(IIdentity recipient, string message)
  97. {
  98. MessageSent = message;
  99. }
  100. }
  101.  
  102. public class FakeGTalkPlugin : FakePlugin
  103. {
  104. public string MessageSent;
  105.  
  106. public override void SendMessage(IIdentity recipient, string message)
  107. {
  108. MessageSent = message;
  109. }
  110. }
  111. }
Add Comment
Please, Sign In to add comment