Guest User

Untitled

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using FakeItEasy;
  4. using NUnit.Framework;
  5. using Simple.Data.FakeResult;
  6.  
  7. namespace TestingWithSimpleDataFakeResult
  8. {
  9. [TestFixture]
  10. public class RepositoryUsingSimpleDataTests
  11. {
  12. [Test]
  13. public void should_return_faked_data_when_calling_repository()
  14. {
  15. // Arrange
  16. dynamic fakeResult = FakeResult.For.Users.All().OrderByScore().Take().Returns(GetTestResultUsers());
  17. var dbFactory = A.Fake<ISimpleDataDbFactory>();
  18. A.CallTo(dbFactory).WithReturnType<dynamic>().Returns(fakeResult);
  19.  
  20. var repositoryUnderTest = new UserRepository(dbFactory);
  21.  
  22. // Act
  23. var result = repositoryUnderTest.GetTopUsers();
  24.  
  25. // Assert
  26. Assert.AreEqual(3, result.Count());
  27. }
  28.  
  29. private IList<User> GetTestResultUsers()
  30. {
  31. return new List<User>
  32. {
  33. new User { Name = "Marcus", Score = 3000},
  34. new User { Name = "Albert", Score = 30000},
  35. new User { Name = "The Gu", Score = 4500},
  36. };
  37. }
  38. }
  39.  
  40. public class UserRepository
  41. {
  42. private readonly ISimpleDataDbFactory _dbFactory;
  43.  
  44. public UserRepository(ISimpleDataDbFactory dbFactory)
  45. {
  46. _dbFactory = dbFactory;
  47. }
  48.  
  49. public IList<User> GetTopUsers()
  50. {
  51. return _dbFactory.DB.Users.All().OrderByScore().Take(3).ToList();
  52. }
  53. }
  54.  
  55. public interface ISimpleDataDbFactory
  56. {
  57. dynamic DB { get; }
  58. }
  59.  
  60. public class User
  61. {
  62. public string Name { get; set; }
  63. public int Score { get; set; }
  64. }
  65. }
Add Comment
Please, Sign In to add comment