Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Data.Entity;
- using System.Linq;
- using Moq;
- using NUnit.Framework;
- using Pocos;
- using Pocos.Context;
- using TechTalk.SpecFlow;
- namespace Repository.Specs
- {
- [Binding]
- public class GenericRepoSteps
- {
- private readonly IList<Profile> _profilesMock = new List<Profile>
- {
- new Profile { ProfileId = 1 },
- new Profile { ProfileId = 2 }
- };
- private IQueryable<Profile> _profile;
- private readonly Mock<DbSet<Profile>> _mockSet;
- private readonly Mock<IDbContext> _mockContext;
- public GenericRepoSteps()
- {
- // http://msdn.microsoft.com/en-us/data/dn314431#doubles
- // http://msdn.microsoft.com/en-us/data/dn314429.aspx
- var mockProfile = _profilesMock.AsQueryable();
- _mockSet = new Mock<DbSet<Profile>>();
- _mockSet.As<IQueryable<Profile>>().Setup(m => m.Provider).Returns(mockProfile.Provider);
- _mockSet.As<IQueryable<Profile>>().Setup(m => m.Expression).Returns(mockProfile.Expression);
- _mockSet.As<IQueryable<Profile>>().Setup(m => m.ElementType).Returns(mockProfile.ElementType);
- _mockSet.As<IQueryable<Profile>>().Setup(m => m.GetEnumerator()).Returns(mockProfile.GetEnumerator());
- _mockContext = new Mock<IDbContext>();
- _mockContext.Setup(m => m.Set<Profile>()).Returns(_mockSet.Object);
- }
- [Given(@"Im a user")]
- public void GivenImAUser() { }
- [Given(@"I want to see my profile\.")]
- public void GivenIWantToSeeMyProfile_() { }
- [When(@"I call the Get method with my UserId")]
- public void WhenICallTheGetMethodWithMyUserId()
- {
- var baseRepo = new BaseRepository<Profile>(_mockContext.Object);
- _profile = baseRepo.Get(p => p.ProfileId == 1);
- }
- [Then(@"the result should be a collection of my profile data\.")]
- public void ThenTheResultShouldBeACollectionOfMyProfileData_()
- {
- Assert.AreEqual(_profile.Count(), 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement