Created
November 16, 2011 02:52
-
-
Save hotgazpacho/1369116 to your computer and use it in GitHub Desktop.
WCF Service Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Serialization; | |
using System.ServiceModel; | |
using System.ServiceModel.Web; | |
using System.Text; | |
using ElmSelect.DomainModel; | |
using DataAccessLayer; | |
namespace WCFService | |
{ | |
public class ElmResourcesService : IElmResourcesService | |
{ | |
readonly IQueryable<School> _schools; | |
readonly IQueryable<Lender> _lenders; | |
public ElmResourcesService(IQueryable<School> schools, IQueryable<Lender> lenders) | |
{ | |
_schools = schools; | |
_lenders = lenders; | |
} | |
public IList<string> GetSchools(string partialText) | |
{ | |
return _schools.Where(x => x.Name.Contains(partialText)).Select(x => x.Name).ToList(); | |
} | |
public School GetSchool(string schoolName) | |
{ | |
return _schools.SingleOrDefault(x => x.Name == schoolName); | |
} | |
public IList<string> GetLenders(string partialText) | |
{ | |
return _lenders.Where(x => x.Name.Contains(partialText)).Select(x => x.Name).ToList(); | |
} | |
public Lender GetLender(string lenderName) | |
{ | |
return _lenders.SingleOrDefault(x => x.Name == lenderName); | |
} | |
} | |
} | |
namespace WCFService.Test | |
{ | |
class FakeSchools : List<School> | |
{ | |
} | |
class FakeLenders : List<Lender> | |
{ | |
} | |
[TestFixture] | |
public class WCFServiceTests | |
{ | |
[Test] | |
public void GetSchools_PartialTextMatch_ListOfSchoolsWithPartialMatch() | |
{ | |
//Arrange | |
var schools = new FakeSchools(new[]{new School("Ohio State University"), new School("Florida State University")}); | |
var service = new WCFService(schools, null); | |
//Act | |
var result = service.GetSchools("Ohio"); | |
//Assert | |
CollectionAssert.AreEquivalent(new[] {"Ohio State University"}, result) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
technically, to compile, you probably need to instantiate new lists from the ILists