Guest User

Untitled

a guest
Aug 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using AutoMoq;
  2. using NUnit.Framework;
  3.  
  4. namespace TestProject1
  5. {
  6. [TestFixture]
  7. public class UnitTest1
  8. {
  9. private AutoMoqer mocker;
  10. private SomeController controller;
  11. private const string Id = "the id";
  12.  
  13. [SetUp]
  14. public void Setup()
  15. {
  16. mocker = new AutoMoqer();
  17. var profile = new Profile();
  18. controller = mocker.Create<SomeController>();
  19. mocker.GetMock<IProfilerGetter>().Setup(p => p.Get(Id)).Returns(profile);
  20. }
  21.  
  22. [Test]
  23. public void CanAMockGeneratedByAutomoqBeCalledOnce()
  24. {
  25. var p1 = controller.Get(Id);
  26. Assert.IsNotNull(p1);
  27. }
  28.  
  29. [Test]
  30. public void CanAMockGeneratedByAutomoqBeCalledTwice()
  31. {
  32. var p2 = controller.Get(Id);
  33. Assert.IsNotNull(p2);
  34. }
  35.  
  36. }
  37. public class SomeController
  38. {
  39. private readonly IProfilerGetter profilerGetter;
  40.  
  41. public SomeController(IProfilerGetter profilerGetter)
  42. {
  43. this.profilerGetter = profilerGetter;
  44. }
  45.  
  46. public Profile Get(string id)
  47. {
  48. return profilerGetter.Get(id);
  49. }
  50. }
  51.  
  52. public interface IProfilerGetter
  53. {
  54. Profile Get(string id);
  55. }
  56.  
  57. public class Profile
  58. {
  59. }
  60. }
Add Comment
Please, Sign In to add comment