Advertisement
Guest User

Untitled

a guest
Dec 5th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Data.Entity;
  5. using System.Linq;
  6.  
  7. using Moq;
  8.  
  9. using NUnit.Framework;
  10.  
  11. using Pocos;
  12. using Pocos.Context;
  13.  
  14. using TechTalk.SpecFlow;
  15.  
  16. namespace Repository.Specs
  17. {
  18.    [Binding]
  19.    public class GenericRepoSteps
  20.    {
  21.       private readonly IList<Profile> _profilesMock = new List<Profile>
  22.       {
  23.          new Profile { ProfileId = 1 },
  24.          new Profile { ProfileId = 2 }
  25.       };
  26.  
  27.       private IQueryable<Profile> _profile;
  28.       private readonly Mock<DbSet<Profile>> _mockSet;
  29.       private readonly Mock<IDbContext> _mockContext;
  30.  
  31.       public GenericRepoSteps()
  32.       {
  33.          // http://msdn.microsoft.com/en-us/data/dn314431#doubles
  34.          // http://msdn.microsoft.com/en-us/data/dn314429.aspx
  35.  
  36.          var mockProfile = _profilesMock.AsQueryable();
  37.  
  38.          _mockSet = new Mock<DbSet<Profile>>();
  39.          _mockSet.As<IQueryable<Profile>>().Setup(m => m.Provider).Returns(mockProfile.Provider);
  40.          _mockSet.As<IQueryable<Profile>>().Setup(m => m.Expression).Returns(mockProfile.Expression);
  41.          _mockSet.As<IQueryable<Profile>>().Setup(m => m.ElementType).Returns(mockProfile.ElementType);
  42.          _mockSet.As<IQueryable<Profile>>().Setup(m => m.GetEnumerator()).Returns(mockProfile.GetEnumerator());
  43.  
  44.          _mockContext = new Mock<IDbContext>();
  45.          _mockContext.Setup(m => m.Set<Profile>()).Returns(_mockSet.Object);
  46.       }
  47.  
  48.       [Given(@"Im a user")]
  49.       public void GivenImAUser() { }
  50.  
  51.       [Given(@"I want to see my profile\.")]
  52.       public void GivenIWantToSeeMyProfile_() { }
  53.  
  54.       [When(@"I call the Get method with my UserId")]
  55.       public void WhenICallTheGetMethodWithMyUserId()
  56.       {
  57.          var baseRepo = new BaseRepository<Profile>(_mockContext.Object);
  58.  
  59.          _profile = baseRepo.Get(p => p.ProfileId == 1);
  60.       }
  61.  
  62.       [Then(@"the result should be a collection of my profile data\.")]
  63.       public void ThenTheResultShouldBeACollectionOfMyProfileData_()
  64.       {
  65.          Assert.AreEqual(_profile.Count(), 1);
  66.       }
  67.    }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement