public void Struct() { MockEnv.CreateRequest("/ParameterContract/Struct").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); // lack of param MockEnv.CreateRequest("/ParameterContract/Struct?x=1").GetString().Trim('\"').Is("1"); // ok MockEnv.CreateRequest("/ParameterContract/Struct?x=hoge").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); // can't parse MockEnv.CreateRequest("/ParameterContract/Struct?x=10&x=20&x=30").GetString().Trim('\"').Is("10"); // over parameter }
public void EnumArray() { MockEnv.CreateRequest("/ParameterContract/EnumArray").GetString().Trim('\"').Is("Empty"); MockEnv.CreateRequest("/ParameterContract/EnumArray?fruit=2").GetString().Trim('\"').Is("Orange"); MockEnv.CreateRequest("/ParameterContract/EnumArray?fruit=oRange&fruit=3").GetString().Trim('\"').Is("Empty"); MockEnv.CreateRequest("/ParameterContract/EnumArray?fruit=oRange&fruit=hogemoge").GetString().Trim('\"').Is("Empty"); }
public void Enum() { MockEnv.CreateRequest("/ParameterContract/Enum").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); MockEnv.CreateRequest("/ParameterContract/Enum?fruit=2").GetString().Trim('\"').Is("Orange"); MockEnv.CreateRequest("/ParameterContract/Enum?fruit=Orange").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); MockEnv.CreateRequest("/ParameterContract/Enum?fruit=oRange").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); MockEnv.CreateRequest("/ParameterContract/Enum?fruit=hogemoge").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); }
public void EnumDefaultValue() { MockEnv.CreateRequest("/ParameterContract/EnumDefaultValue").GetString().Trim('\"').Is("Apple"); MockEnv.CreateRequest("/ParameterContract/EnumDefaultValue?fruit=2").GetString().Trim('\"').Is("Orange"); MockEnv.CreateRequest("/ParameterContract/EnumDefaultValue?fruit=10000").GetString().Trim('\"').Is("Apple"); MockEnv.CreateRequest("/ParameterContract/EnumDefaultValue?fruit=oRange").GetString().Trim('\"').Is("Apple"); MockEnv.CreateRequest("/ParameterContract/EnumDefaultValue?fruit=hogemoge").GetString().Trim('\"').Is("Apple"); }
public void Array() { MockEnv.CreateRequest("/ArrayContract/Sum?xs=1&xs=2&xs=3").GetString().Is("6"); MockEnv.CreateRequest("/ArrayContract/Sum?xs=1000").GetString().Is("1000"); // single arg MockEnv.CreateRequest("/ArrayContract/Sum2?x=2&xs=1&xs=2&xs=3&y=30&ys=40&ys=50").GetString().Is("128"); MockEnv.CreateRequest("/ArrayContract/Sum2?x=2&xs=1&y=30&ys=50").GetString().Is("83"); }
public void UrlEncode() { MockEnv.CreateRequest("/Hello/Echo?x=あいうえお").GetString().Is("\"あいうえお\""); MockEnv.CreateRequest("/Hello/Echo").PostAndGetString(new StringKeyValuePairCollection { { "x", "あいうえお" } }) .Is("\"あいうえお\""); }
public void EnumNullable() { MockEnv.CreateRequest("/ParameterContract/EnumNullable").GetString().Trim('\"').Is("null"); MockEnv.CreateRequest("/ParameterContract/EnumNullable?fruit=2").GetString().Trim('\"').Is("Orange"); MockEnv.CreateRequest("/ParameterContract/EnumNullable?fruit=10000").GetString().Trim('\"').Is("null"); MockEnv.CreateRequest("/ParameterContract/EnumNullable?fruit=oRange").GetString().Trim('\"').Is("null"); MockEnv.CreateRequest("/ParameterContract/EnumNullable?fruit=hogemoge").GetString().Trim('\"').Is("null"); }
public void Array() { MockEnv.CreateRequest("/ParameterContract/Array").GetString().Trim('\"').Is("0"); MockEnv.CreateRequest("/ParameterContract/Array?x=100").GetString().Trim('\"').Is("100"); MockEnv.CreateRequest("/ParameterContract/Array?x=1&x=2").GetString().Trim('\"').Is("3"); MockEnv.CreateRequest("/ParameterContract/Array?x=1&x=hoge").GetString().Trim('\"').Is("0"); MockEnv.CreateRequest("/ParameterContract/Array2?x=&y=10").GetString().Trim('\"').Is("10"); }
public void NotFound() { MockEnv.CreateRequest("").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/hello").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/hello/").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/hello/pin").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/hello/pingoo").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/hello/ping/oo").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); }
public void PostBasic() { MockEnv.CreateRequest("/TestContract/Add") .PostAndGetString(new StringKeyValuePairCollection { { "x", "10" }, { "y", "20" } }) .Is("30"); MockEnv.CreateRequest("/TestContract/AddWithDefault") .PostAndGetString(new StringKeyValuePairCollection { { "y", "20" }, { "z", "5" }, { "x", "10" } }) .Is("35"); MockEnv.CreateRequest("/TestContract/AddWithDefault") .PostAndGetString(new StringKeyValuePairCollection { { "y", "20" }, { "x", "10" } }) .Is("330"); MockEnv.CreateRequest("/TestContract/TaskAdd") .PostAndGetString(new StringKeyValuePairCollection { { "x", "10" }, { "y", "20" } }) .Is("30"); MockEnv.CreateRequest("/TestContract/TaskAddWithDefault") .PostAndGetString(new StringKeyValuePairCollection { { "y", "20" }, { "z", "5" }, { "x", "10" } }) .Is("35"); MockEnv.CreateRequest("/TestContract/TaskAddWithDefault") .PostAndGetString(new StringKeyValuePairCollection { { "y", "20" }, { "x", "10" } }) .Is("330"); var guid = Guid.NewGuid().ToString(); TestContract.VoidBeforeAfter[guid] = "Before"; MockEnv.CreateRequest("/TestContract/VoidCheck") .And(x => x.Content = new FormUrlEncodedContent(new StringKeyValuePairCollection { { "guid", guid }, { "after", "After" } })) .PostAsync().Result.Dispose(); TestContract.VoidBeforeAfter[guid].Is("After"); TestContract.VoidBeforeAfter[guid] = "Before"; MockEnv.CreateRequest("/TestContract/TaskVoidCheck") .And(x => x.Content = new FormUrlEncodedContent(new StringKeyValuePairCollection { { "guid", guid }, { "after", "After" } })) .PostAsync().Result.Dispose(); TestContract.VoidBeforeAfter[guid].Is("After"); }
public void StatusCode() { MockEnv.CreateRequest("/StatusCodeContract/Redirect").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.Redirect); MockEnv.CreateRequest("/StatusCodeContract/Unauthrized").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.Unauthorized); var r1 = MockEnv.CreateRequest("/StatusCodeContract/ResonPhrase").GetAsync().Result; r1.StatusCode.Is(System.Net.HttpStatusCode.ServiceUnavailable); r1.ReasonPhrase.Is("Unavailable!!!"); var r2 = MockEnv.CreateRequest("/StatusCodeContract/Content").GetAsync().Result; r2.StatusCode.Is(System.Net.HttpStatusCode.UseProxy); r2.ReasonPhrase.Is("Pro!!!"); r2.Content.ReadAsStringAsync().Result.Is("UseProxy...."); }
public void RawBody() { var sendBytes = Encoding.UTF8.GetBytes("dファdfasfzjew3ふぁzfdfsfうぇw"); // japanese hiragana:) // echo var req = MockEnv.CreateRequest("/TestContract/EchoByte") .And(x => { x.Content = new ByteArrayContent(sendBytes); }); req.PostAsync().Result.Content.ReadAsByteArrayAsync().Result.IsStructuralEqual(sendBytes); // length var req2 = MockEnv.CreateRequest("/TestContract/PostByte") .And(x => { x.Content = new ByteArrayContent(sendBytes); }); req2.PostAsync().Result.Content.ReadAsStringAsync().Result.Is(sendBytes.Length.ToString()); }
public void GetBasic() { MockEnv.CreateRequest("/TestContract/Add?x=10&y=20").GetString().Is("30"); MockEnv.CreateRequest("/TestContract/AddWithDefault?y=20&z=5&x=10").GetString().Is("35"); MockEnv.CreateRequest("/TestContract/AddWithDefault?x=10&y=20").GetString().Is("330"); MockEnv.CreateRequest("/TestContract/TaskAdd?x=10&y=20").GetString().Is("30"); MockEnv.CreateRequest("/TestContract/TaskAddWithDefault?y=20&z=5&x=10").GetString().Is("35"); MockEnv.CreateRequest("/TestContract/TaskAddWithDefault?x=10&y=20").GetString().Is("330"); var guid = Guid.NewGuid().ToString(); TestContract.VoidBeforeAfter[guid] = "Before"; MockEnv.CreateRequest("/TestContract/VoidCheck?after=After&guid=" + guid).GetAsync().Result.Dispose(); TestContract.VoidBeforeAfter[guid].Is("After"); TestContract.VoidBeforeAfter[guid] = "Before"; MockEnv.CreateRequest("/TestContract/TaskVoidCheck?after=After&guid=" + guid).GetAsync().Result.Dispose(); TestContract.VoidBeforeAfter[guid].Is("After"); }
public void String() { MockEnv.CreateRequest("/ParameterContract/String").GetAsync().Result.StatusCode.Is(HttpStatusCode.BadRequest); MockEnv.CreateRequest("/ParameterContract/String?x=hoge").GetString().Trim('\"').Is("hoge"); using (var server = Microsoft.Owin.Testing.TestServer.Create((Action <Owin.IAppBuilder>)(app => { Owin.AppBuilderLightNodeMiddlewareExtensions.UseLightNode( app, new LightNodeOptions(AcceptVerbs.Get | AcceptVerbs.Post, new JavaScriptContentFormatter(), new TextContentFormatter()) { ParameterStringImplicitNullAsDefault = true } , typeof(MockEnv).Assembly); }))) { server.CreateRequest("/ParameterContract/String").GetString().Trim('\"').Is("null"); } }
public void Hello() { MockEnv.CreateRequest("/Hello/Say").GetString().Is("\"Hello LightNode\""); MockEnv.CreateRequest("/Hello/Say").PostAndGetString(new StringKeyValuePairCollection()).Is("\"Hello LightNode\""); }
public void VerbOption() { MockEnv.CreateRequest("/TestContract/PutOnly").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.MethodNotAllowed); MockEnv.CreateRequest("/TestContract/PutOnly").SendAsync("PUT").Result.StatusCode.Is(System.Net.HttpStatusCode.NoContent); MockEnv.CreateRequest("/TestContract/PatchOnly").SendAsync("PATCH").Result.StatusCode.Is(System.Net.HttpStatusCode.NoContent); }
public void Nullable() { MockEnv.CreateRequest("/ParameterContract/Nullable").GetString().Trim('\"').Is("null"); MockEnv.CreateRequest("/ParameterContract/Nullable?x=1").GetString().Trim('\"').Is("1"); MockEnv.CreateRequest("/ParameterContract/Nullable?x=hoge").GetString().Trim('\"').Is("null"); }
public void ParameterMismatch() { MockEnv.CreateRequest("/TestContract/Add").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.BadRequest); MockEnv.CreateRequest("/TestContract/Add?x=10").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.BadRequest); MockEnv.CreateRequest("/TestContract/Add?x=10&x=20").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.BadRequest); }
public void DefaultValue() { MockEnv.CreateRequest("/ParameterContract/DefaultValue").GetString().Trim('\"').Is("100"); MockEnv.CreateRequest("/ParameterContract/DefaultValue?x=1").GetString().Trim('\"').Is("1"); MockEnv.CreateRequest("/ParameterContract/DefaultValue?x=hoge").GetString().Trim('\"').Is("100"); }
public void StringDefaultValue() { MockEnv.CreateRequest("/ParameterContract/StringDefaultValue").GetString().Trim('\"').Is("hogehoge"); MockEnv.CreateRequest("/ParameterContract/StringDefaultValue?x=hoge").GetString().Trim('\"').Is("hoge"); MockEnv.CreateRequest("/ParameterContract/StringDefaultValue?x=hoge&x=huga").GetString().Trim('\"').Is("hoge"); }
public void CaseSensitive() { MockEnv.CreateRequest("/heLLo/pInG").GetString().Is("\"Pong\""); }
public void Ignore() { MockEnv.CreateRequest("/IgnoreContract/Hoge").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/IgnoreMethod/Hoge").GetAsync().Result.StatusCode.Is(System.Net.HttpStatusCode.NotFound); MockEnv.CreateRequest("/IgnoreMethod/Huga").GetString().Is("1"); }