public async Task WhenMethodPOST() { // Arrange var context = new DefaultHttpContext(); var middleware = new RequestVerifier((innerHttpContext) => { throw new NotImplementedException("// Some implementation goes here; it's not important for this exercise"); }); middleware.Requestdate = new DateTime(2019, 4, 1); // Passing date April 1 context.Request.Method = "POST"; // Method POST context.Request.Path = "/Coffee/api/1"; // REQUEST PATH Starts with /Coffeee (case-insensitive) context.Response.Body = new MemoryStream(); await middleware.Invoke(context); context.Response.Body.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(context.Response.Body); var streamText = reader.ReadToEnd(); var objResponse = JsonConvert.DeserializeObject <object>(streamText); Assert.Equal(418, context.Response.StatusCode); }
public async Task WhenMethodNot_GETPOSTDELTE() { // Arrange var context = new DefaultHttpContext(); var middleware = new RequestVerifier((innerHttpContext) => { throw new NotImplementedException("// Some implementation goes here; it's not important for this exercise"); }); middleware.Requestdate = new DateTime(2019, 4, 1); // Date is April 1 //CHANGE THIS DATE TO ANY OTHER DATE context.Request.Method = "PUT"; // REQUEST METHOD IS PUT AND NOT MENTIONED IN REQUIREMENT CHANGE THIS METHOD TO TEST OTHER context.Request.Path = "/api/1"; // CHANGE THIS PATH TO ANY OTHER like /Coffee/api/1 context.Response.Body = new MemoryStream(); await middleware.Invoke(context); context.Response.Body.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(context.Response.Body); var streamText = reader.ReadToEnd(); var objResponse = JsonConvert.DeserializeObject <object>(streamText); Assert.Equal((int)HttpStatusCode.OK, context.Response.StatusCode); }