Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using FakeItEasy;
- using NUnit.Framework;
- using Simple.Data.FakeResult;
- namespace TestingWithSimpleDataFakeResult
- {
- [TestFixture]
- public class RepositoryUsingSimpleDataTests
- {
- [Test]
- public void should_return_faked_data_when_calling_repository()
- {
- // Arrange
- dynamic fakeResult = FakeResult.For.Users.All().OrderByScore().Take().Returns(GetTestResultUsers());
- var dbFactory = A.Fake<ISimpleDataDbFactory>();
- A.CallTo(dbFactory).WithReturnType<dynamic>().Returns(fakeResult);
- var repositoryUnderTest = new UserRepository(dbFactory);
- // Act
- var result = repositoryUnderTest.GetTopUsers();
- // Assert
- Assert.AreEqual(3, result.Count());
- }
- private IList<User> GetTestResultUsers()
- {
- return new List<User>
- {
- new User { Name = "Marcus", Score = 3000},
- new User { Name = "Albert", Score = 30000},
- new User { Name = "The Gu", Score = 4500},
- };
- }
- }
- public class UserRepository
- {
- private readonly ISimpleDataDbFactory _dbFactory;
- public UserRepository(ISimpleDataDbFactory dbFactory)
- {
- _dbFactory = dbFactory;
- }
- public IList<User> GetTopUsers()
- {
- return _dbFactory.DB.Users.All().OrderByScore().Take(3).ToList();
- }
- }
- public interface ISimpleDataDbFactory
- {
- dynamic DB { get; }
- }
- public class User
- {
- public string Name { get; set; }
- public int Score { get; set; }
- }
- }
Add Comment
Please, Sign In to add comment