Created
November 16, 2011 03:41
-
-
Save hotgazpacho/1369173 to your computer and use it in GitHub Desktop.
WCF Service Test - Refactored
This file contains 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; | |
namespace WCFService | |
{ | |
[ServiceContract] | |
public interface ILenderService | |
{ | |
[OperationContract] | |
[WebInvoke(Method = "GET", | |
RequestFormat = WebMessageFormat.Json, | |
ResponseFormat = WebMessageFormat.Json, | |
UriTemplate = "lender")] | |
IList<string> GetLenders(string partialText); | |
[OperationContract] | |
[WebInvoke(Method = "GET", | |
RequestFormat = WebMessageFormat.Json, | |
ResponseFormat = WebMessageFormat.Json, | |
UriTemplate = "lenders")] | |
Lender GetLender(string lenderName); | |
} | |
} | |
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 LenderService : ILenderService, IDisposable | |
{ | |
readonly ILenderDAL _lenderDAL; | |
public LenderService(ILenderDAL lenderDAL) | |
{ | |
_lenderDAL = lenderDAL; | |
} | |
public IList<string> GetLenders(string partialText) | |
{ | |
return _lenderDAL.GetLenders(partialText) | |
} | |
public Lender GetLender(string lenderName) | |
{ | |
return _lenderDAL.GetLender(lenderName) | |
} | |
public void Dispose() | |
{ | |
_lenderDAL.Dispose(); | |
} | |
} | |
} | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Data; | |
using System.Data.SqlClient; | |
using ElmSelect.DomainModel; | |
namespace DataAccessLayer | |
{ | |
public interface ILenderDAL : IDisposable | |
{ | |
IList<string> GetLenders(string partialText) | |
Lender GetLender(string lenderName) | |
} | |
public class LenderDAL : ILenderDAL | |
{ | |
public List<string> GetLenders(string partialText) | |
{ | |
return new List<string> { "Key Bank", "Chase" }; | |
} | |
public Lender GetLender(string lenderName) | |
{ | |
return new Lender(lenderName); | |
} | |
#region Garbage Collection | |
~LenderDAL() | |
{ | |
this.Dispose(false); | |
} | |
//Dispose of the balance object | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
//Remove the event handlers | |
private bool isDisposed = false; | |
private void Dispose(bool disposing) | |
{ | |
if (!this.isDisposed) | |
{ | |
if (disposing) | |
{ | |
} | |
isDisposed = true; | |
} | |
} | |
#endregion | |
} | |
} | |
using System; | |
namespace ElmSelect.DomainModel | |
{ | |
[Serializable] | |
public class Lender | |
{ | |
public Lender(string lenderName) | |
{ | |
LenderName = lenderName; | |
} | |
public string LenderName { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment