ok, this might take a bit to explain.
I'm basing my services off of classes that use the CSLA library. Not sure this is relevant, but I'll throw it out there. The CSLA collection classes inherit (after a long chain of subclasses) to System.Collections.ObjectModel.ObservableCollection<T>.
I wrote a service to return one of these read-only collection classes. Here is the outbound DTO:
public class TeamsResponse {
[DataMember]
public Vid.Lib.MajorLeagueTeams Result { get; set; } //CSLA class
public ResponseStatus ResponseStatus { get; set; }
}
And the service.
public class TeamsService : ServiceBase<Teams>
{
protected override object Run(Teams request)
{
return new TeamsResponse { Result = Vid.Lib.MajorLeagueTeams.GetObject() };
}
}
This class returns data as expected when testing via the web page, so I know the CSLA class is working correctly. However, when writing code for a unit test, the service returns null for both the ResponseStatus and the Result, with no error messages or exceptions. My test unit looks something like this:
[TestMethod]
public void Can_I_Get_Teams()
{
var restClient = (IRestClient)new JsonServiceClient("
http://localhost/vidsvc");
restClient.Get<ServiceStack.ServiceInterface.Auth.AuthResponse>("/auth?username=xxx&password=yyy");
var response = restClient.Get<TeamsResponse>("/teams");
Assert.AreEqual(response.Result.Count, 30);
}
In trying to figure out why the collection was not coming across correctly, I changed my outbound DTO to return a normal generic list. This worked!
New Outbound DTO:
[DataContract]
public class TeamsResponse {
[DataMember]
public
List<Vid.Lib.TeamInfo> Result { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
New Service
public class TeamsService : ServiceBase<Teams>
{
protected override object Run(Teams request) {
var tms = Vid.Lib.MajorLeagueTeams.GetObject();
var lst = new List<Vid.Lib.TeamInfo>();
lst.AddRange(tms);
return new TeamsResponse { Result = lst };
}
}
Not totally sure why, but the ObservableCollection doesn't make it across the service in this unit test, unless I change the return result to a normal List<T>.