Sha256: 360c35bd9a7982294a4b9f2df3fc2353a08b4c0f91628bf1495675a643f00dc8

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

load_assembly 'System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
load_assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
load_assembly 'System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

include System::Web
include System::Web::Routing
include System::Web::Mvc

class String

  def to_url_filename
    return self.gsub(/\?.*/, '') if self =~ /\?/
    self
  end

  def to_qs_parameters
    if self =~ /\?/
      parameters = NameValueCollection.new
      self.split('?')[1].split("&").each do |pair|
        parts = pair.split('=')
        parameters.add pair.first, pair.last
      end
      return parameters
    end
    nil
  end

end

def http_context_isolation(url="")

  context = Caricature::Isolation.for(HttpContextBase)
  request = Caricature::Isolation.for(HttpRequestBase)
  response = Caricature::Isolation.for(HttpResponseBase)
  session = Caricature::Isolation.for(HttpSessionStateBase)
  server = Caricature::Isolation.for(HttpServerUtilityBase)

  context.when_receiving(:request).return(request)
  context.when_receiving(:response).return(response)
  context.when_receiving(:session).return(session)
  context.when_receiving(:server).return(server)

  setup_request_url(context.request, url) unless url.nil? or url.empty?

  context
end

def setup_request_url(request, url)
  raise ArgumentError.new("url should not be nil") if url.nil? or url.empty?
  raise ArgumentError.new("we expect a url to start with '~/'.") unless url =~ /^~\//

  request.when_receiving(:query_string).return(url.to_s.to_qs_parameters)
  request.when_receiving(:app_relative_current_execution_file_path).return(url.to_s.to_url_filename)
  request.when_receiving(:path_info).return("")
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
caricature-0.7.2 lib/caricature/clr/aspnet_mvc.rb
caricature-0.7.1 lib/caricature/clr/aspnet_mvc.rb
caricature-0.7.0 lib/caricature/clr/aspnet_mvc.rb
caricature-0.6.3 lib/caricature/clr/aspnet_mvc.rb