Advertisement
Guest User

mocking

a guest
Jul 27th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. // namespace and your usings
  2. using Telerik.JustMock;
  3.  
  4. // class name and private lists
  5. [Test]
  6. public void HomeIndexPicturesShouldWorkCorrectly()
  7. {
  8. // no idea just copy/paste
  9. var autoMapperConfig = new AutoMapperConfig();
  10. autoMapperConfig.Execute(typeof(HomeController).Assembly);
  11.  
  12. // var mediaContentFetcherServiceMock = new Mock<IMediaContentFetcherService>();
  13. // mediaContentFetcherServiceMock
  14. // .Setup(x => x.GetLast(ContentType.Picture, 3)).Verifiable();
  15.  
  16.  
  17. // mocking
  18. var mediaContentFetcherServiceMock = Mock.Create<IMediaContentFetcherService>();
  19.  
  20. // arrange mock - line below mean: this method with this param should be called once!
  21. Mock.Arrange(() => mediaContentFetcherServiceMock.GetLast(ContentType.Picture)).OccursOnce();
  22. // .MustBeCalled();
  23. // .OccoursExatly(1);
  24. // .OccoursAtLeast(1);
  25. // .OccoursAtMost(1);
  26. // hope you got the idea
  27.  
  28. var controller = new HomeController(mediaContentFetcherServiceMock);
  29.  
  30. // no idea what this do BUT here have to place your act without any assert
  31. // just in way you exapect to be called
  32.  
  33. // controller.WithCallTo(x => x.Index())
  34. // .ShouldRenderView("Index")
  35. // .WithModel<HomeViewModel>(
  36. // viewModel =>
  37. // {
  38. // Assert.AreEqual(this.pictures, viewModel.Pictures);
  39. // }).AndNoModelErrors();
  40.  
  41. Mock.Assert(() => mediaContentFetcherServiceMock);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement