root/trunk/src/core/OpenRasta.Tests.Unit/Web/Pipeline/Contributors/HandlerMethodInvoker_Specification.cs @ 426

Revision 426, 6.2 KB (checked in by serialseb, 7 months ago)

New http header parsing implementation, some bug fixes. Not finished but need checkin to merge RC

Line 
1#region License
2/* Authors:
3 *      Sebastien Lambla (seb@serialseb.com)
4 * Copyright:
5 *      (C) 2007-2009 Caffeine IT & naughtyProd Ltd (http://www.caffeine-it.com)
6 * License:
7 *      This file is distributed under the terms of the MIT License found at the end of this file.
8 */
9#endregion
10
11using System;
12using NUnit.Framework;
13using OpenRasta.Testing;
14using OpenRasta.Tests;
15using OpenRasta.Tests.Unit.Fakes;
16using OpenRasta.Web;
17using OpenRasta.Pipeline;
18
19namespace HandlerMethodsInvoker_Specification
20{
21    //public class when_the_method_returns_an_opration_context : openrasta_context
22    //{
23    //    [Test]
24    //    public void the_operation_context_is_assigned_and_executed()
25    //    {
26    //        var handler = new ResourceHandler();
27    //        given_pipeline_contributor<HandlerMethodInvoker>();
28    //        GivenAHandler(handler);
29    //        GivenAFinalMethodInvocation<OperationResult>(handler.GetOp);
30
31    //        when_sending_notification<RequestEntityReader>()
32    //            .ShouldBe(PipelineContinuation.Continue);
33
34    //        Context.OperationResult.ShouldBeOfType<OperationResult.OK>();
35
36    //        Context.Response.Entity.Instance.ShouldBeOfType<Resource>();
37    //    }
38    //}
39
40    //public class when_the_method_returns_another_object : openrasta_context
41    //{
42    //    [Test]
43    //    public void the_result_is_wraped_in_a_no_content_when_returns_null()
44    //    {
45    //        var handler = new ResourceHandler();
46    //        given_pipeline_contributor<HandlerMethodInvoker>();
47    //        GivenAHandler(handler);
48    //        GivenAFinalMethodInvocation<object>(handler.GetNull);
49
50    //        when_sending_notification<RequestEntityReader>()
51    //            .ShouldBe(PipelineContinuation.Continue);
52
53    //        Context.OperationResult.ShouldBeOfType<OperationResult.NoContent>();
54
55    //        Context.Response.Entity.Instance.ShouldBeNull();
56    //    }
57
58    //    [Test]
59    //    public void the_result_is_wraped_in_an_OK_when_there_is_an_entity()
60    //    {
61    //        var handler = new ResourceHandler();
62    //        given_pipeline_contributor<HandlerMethodInvoker>();
63    //        GivenAHandler(handler);
64    //        GivenAFinalMethodInvocation<object>(handler.GetObj);
65
66    //        when_sending_notification<RequestEntityReader>()
67    //            .ShouldBe(PipelineContinuation.Continue);
68
69    //        Context.OperationResult.ShouldBeOfType<OperationResult.OK>();
70
71    //        Context.Response.Entity.Instance.ShouldBeOfType<Resource>();
72    //    }
73    //}
74
75    //public class when_the_method_returns_void : openrasta_context
76    //{
77    //    [Test]
78    //    public void the_result_is_wraped_in_an_OK_when_there_is_an_entity()
79    //    {
80    //        var handler = new ResourceHandler();
81    //        given_pipeline_contributor<HandlerMethodInvoker>();
82    //        GivenAHandler(handler);
83    //        GivenAFinalMethodInvocation(handler.GetVoid);
84
85    //        when_sending_notification<RequestEntityReader>()
86    //            .ShouldBe(PipelineContinuation.Continue);
87
88    //        Context.OperationResult.ShouldBeOfType<OperationResult.NoContent>();
89
90    //        Context.Response.Entity.Instance.ShouldBeNull();
91    //    }
92    //}
93
94    //public class when_the_method_doesnt_have_all_its_parameters_fullfilled : openrasta_context
95    //{
96    //    [Test]
97    //    public void a_bad_request_error_is_returned()
98    //    {
99    //        var handler = new ResourceHandler();
100    //        given_pipeline_contributor<HandlerMethodInvoker>();
101    //        GivenAHandler(handler);
102    //        GivenAFinalMethodInvocation<Customer, OperationResult>(handler.Post);
103
104    //        when_sending_notification<RequestEntityReader>()
105    //            .ShouldBe(PipelineContinuation.RenderNow);
106
107    //        Context.OperationResult.ShouldBeOfType<OperationResult.BadRequest>();
108    //    }
109    //}
110
111    //public class when_the_method_fails : openrasta_context
112    //{
113    //    [Test]
114    //    public void an_error_is_logged_and_the_pipeline_aborts()
115    //    {
116    //        var handler = new ResourceHandler();
117    //        given_pipeline_contributor<HandlerMethodInvoker>();
118    //        GivenAHandler(handler);
119    //        GivenAFinalMethodInvocation(handler.GetError);
120
121    //        when_sending_notification<RequestEntityReader>()
122    //            .ShouldBe(PipelineContinuation.Abort);
123
124    //        Context.ServerErrors[0]
125    //            .ShouldBeOfType<ErrorFrom<HandlerMethodInvoker>>()
126    //            .DiagnosticsMessage
127    //            .ShouldContain("InvalidOperationException");
128    //    }
129    //}
130
131    public class Resource
132    {
133    }
134
135    public class ResourceHandler
136    {
137        public OperationResult GetOp() { return new OperationResult.OK(new Resource()); }
138        public OperationResult Post(Customer customer) { return null; }
139        public void GetVoid() { }
140        public object GetObj() { return new Resource(); }
141        public object GetNull() { return null; }
142        public void GetError() { throw new InvalidOperationException(); }
143    }
144}
145
146#region Full license
147//
148// Permission is hereby granted, free of charge, to any person obtaining
149// a copy of this software and associated documentation files (the
150// "Software"), to deal in the Software without restriction, including
151// without limitation the rights to use, copy, modify, merge, publish,
152// distribute, sublicense, and/or sell copies of the Software, and to
153// permit persons to whom the Software is furnished to do so, subject to
154// the following conditions:
155//
156// The above copyright notice and this permission notice shall be
157// included in all copies or substantial portions of the Software.
158//
159// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
160// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
162// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
163// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
164// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
165// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
166//
167#endregion
Note: See TracBrowser for help on using the browser.