Comments (4)
@RickStrahl Does this project contains any test cases for the "RenderViewToString
" ?
"RenderViewToString
" only allows to work when it contains HTTPContext, how to create a test case with out HTTPContext ?
I have tried to create fake HTTPContext, but it was failing though when FindView()
is executing
HttpContext.Current = new HttpContext( new HttpRequest("", "http://tempuri.org", ""), new HttpResponse(new StringWriter()) );
from westwindtoolkit.
You really need an HttpContext for this to work. If you want to do this outside of ASP.NET, I recommend you look at https://github.com/RickStrahl/Westwind.RazorHosting instead which can be run in any type of project.
from westwindtoolkit.
Looks as if the link is broken. Here is a link that worked as of writing: Westwind.RazorHosting
from westwindtoolkit.
@RickStrahl - I'm trying to use your code to create a controller context from a singleton inside an MVC application. Since there is no httpcontext I am creating a dummy one like this. And then I use it inside the controller context. It seems to work, but I am not sure what the cons of using a dummy httpcontext like this are. Please advise if there is an alternative approach.
HttpContext ctx = new HttpContext(
new HttpRequest("", "http://tempuri.org", ""),
new HttpResponse(new StringWriter())
);
// User is logged in
ctx.User = new GenericPrincipal(
new GenericIdentity("username"),
new string[0]
);
// User is logged out
ctx.User = new GenericPrincipal(
new GenericIdentity(String.Empty),
new string[0]
);
// get context wrapper from HttpContext if available
HttpContextBase wrapper = null;
if (ctx != null)
wrapper = new HttpContextWrapper(ctx);
else
throw new InvalidOperationException(
"Can't create Controller Context if no active HttpContext instance is available.");
from westwindtoolkit.
Related Issues (11)
- Can not Create Controller instance by parameters outside of MVC HOT 2
- ww.jquery.js: Number.prototype.formatNumber incorrect for "n<digits>" format
- SqlDataAccess.InsertEntity returns DbNull for identity key HOT 2
- Parameter Count Mismatch exception when calling PropertyInfo.GetValue (from InstancePropertyInfo)
- Westwind.Utilities Fails to install in VS Community 2017 Web API app HOT 2
- Shouldn't short? be compatible with short?
- MVC ViewRenderer issue HOT 1
- Guid not serialized correctly HOT 1
- ReflectionUtils.SetPropertInternal tries to write to ReadOnly properties HOT 2
- ConfigurationFile provider does not respect configSource attribute HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from westwindtoolkit.