Skip to content

Instantly share code, notes, and snippets.

@mayerwin
Created June 16, 2015 17:55
Show Gist options
  • Save mayerwin/581b230611ce874be6e7 to your computer and use it in GitHub Desktop.
Save mayerwin/581b230611ce874be6e7 to your computer and use it in GitHub Desktop.
Bug report: Empty (but not null) DTO array property being deserialized as null if GET request (bug), but as empty array if POST request (correct).
using System;
using System.Collections.Generic;
using System.Linq;
using Funq;
using ServiceStack;
using Xunit;
namespace Bug {
public class EmptyArrayDtoTest {
public class AppHost : AppHostHttpListenerBase {
public AppHost() : base("EmptyArrayDtoTest", typeof(GetItems).Assembly) { }
public override void Configure(Container container) {
}
}
const string BaseUri = "http://localhost:1337/";
AppHost appHost;
public void TestFixtureSetUp() {
appHost = new AppHost();
appHost.Init();
appHost.Start(BaseUri);
}
public void TestFixtureTearDown() {
appHost.Dispose();
}
[Fact]
public void Run() {
TestFixtureSetUp();
var client = new JsonServiceClient(BaseUri);
client.Post(new PostItems { Ids = new int[] { } }); // Success
client.Get(new GetItems { Ids = new int[] { } }); // Fails!
TestFixtureTearDown();
}
public class PostItems : IReturnVoid {
public int[] Ids { get; set; }
}
public class GetItems : IReturn<List<int>> {
public int[] Ids { get; set; }
}
public class TestService : Service {
public void Post(PostItems e) {
if (e.Ids == null) throw new Exception();
}
public List<int> Get(GetItems e) {
if (e.Ids == null) throw new Exception();
return e.Ids.ToList();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment