我想了解如何从应用的OAuth用户库DotNetOpenAuth在ASP.NET MVC的背景下.
oAuth对我来说是新的,图书馆看起来并不简单.有没有人在ASP.NET MVC中有一个利用这个库的样本?
我正在寻找一套在实施时使用的最佳实践IModelBinder.
我已经阅读了三本不同的MVC书籍,每一本都在他们的实现中做了一些略有不同的东西而没有任何真正的解释.
IModelBinderDefaultModelBinder而不是直接实施IModelBinder,但我真的没有看到如何利用这些好处ModelState.SetModelValue()遵循惯例.我只是想确保我的模型绑定器遵循约定,并且我正确地理解了整个ModelBindingContext.
任何提示,技巧,GOOD教程推荐?
我有点嫉妒我从CSS和Ruby社区围绕CSS看到的创新.例如,请参阅:
那就是说,我的问题是双重的.这些库可以通过IronRuby和IronPython轻松"移植"到.NET,那么我可以在C#中编写MSBUILD任务或HTTP处理程序吗?
另外,我应该为此烦恼,还是.NET社区中的其他人已经在为此工作?
更新:自从我写这个原始问题以来,在这个领域的.NET社区中已经做了很多工作.查看以下为LESS,SASS甚至CoffeeScript提供帮助的工具:
我正在使用基于.less的Phil Haack的T4CSS T4模板
关于Phil解决方案的一个坏处是visual studio将.less文件作为纯文本文件而不是css文件打开.(因此没有智能感知.)
如何让VS在CSS源代码编辑器中打开.less文件?
我试过了:
可以这样做吗?
我刚刚安装了Glimpse Web Debugger for ASP.NET(Beta) - 版本0.82.我通过Visual Studio 2010中的Package Manager控制台安装它,安装成功.我正在尝试使用ASP.NET开发服务器和使用Razor视图引擎的MVCMusicStore演示站点的ASP.NET MVC 3版本来测试它.
但是,出于某种原因,当我打开Glimpse并尝试测试Web应用程序时,路径选项卡不会出现.我的web.config文件(如下)中的Glimpse设置不显示任何列入黑名单的插件:
On = True
Allowed IP's =
127.0.0.1
::1
Allowed ContentType's =
text/html
Blacklisted Plugins =
Run Code Online (Sandbox Code Playgroud)
这些是Glimpse/Config页面所说的正在运行的插件列表:
Glimpse.Core.Plugin.Request
Glimpse.Core.Plugin.Environment
Glimpse.Core.Plugin.Trace
Glimpse.Core.Plugin.Config
Glimpse.Core.Plugin.Server
Glimpse.Core.Plugin.Session
Run Code Online (Sandbox Code Playgroud)
出现的唯一选项卡是:Ajax/Config/Environment/Remote/Request/Server.将显示"跟踪"选项卡,但显示为灰色.Glimpse似乎是一个有用的工具,我希望能够用它来测试/调试路由,但我无法弄清楚为什么它不能正常工作.我非常感谢任何帮助.
谢谢!
与使用Joe Celko描述的层次结构实现相比,SQL Server 2008的层次结构数据类型的执行情况如下:http://www.intelligententerprise.com/001020/celko.jhtml?
我过去使用Celko的方法效果很好 - 但是不希望为新项目实现它,除非它比Microsoft在SQL Server 2008中提供的更好.
我想使用MSBUILD来检查站点中所有页面的呈现HTML和CSS的有效性,并打破错误的构建.
任何人都可以推荐一种在自动构建中验证HTML和CSS的策略吗?现在有什么任务可以做到这一点吗?
我希望能够从cookie中获取键/值并使用它来绑定模型.
我认为DefaultModelBinder不是构建自定义的ModelBinder,而是开箱即用,选择值来自哪里的最佳方法是设置它使用的IValueProvider.
为此,我不想创建自定义ValueProviderFactory并将其全局绑定,因为我只希望在特定的操作方法中使用此ValueProvider.
我已经构建了一个执行此操作的属性:
/// <summary>
/// Replaces the current value provider with the specified value provider
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class SetValueProviderAttribute : ActionFilterAttribute
{
public SetValueProviderAttribute(Type valueProviderType)
{
if (valueProviderType.GetInterface(typeof(IValueProvider).Name) == null)
throw new ArgumentException("Type " + valueProviderType + " must implement interface IValueProvider.", "valueProviderType");
_ValueProviderType = valueProviderType;
}
private Type _ValueProviderType;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
IValueProvider valueProviderToAdd = GetValueProviderToAdd();
filterContext.Controller.ValueProvider = valueProviderToAdd;
}
private IValueProvider GetValueProviderToAdd()
{ …Run Code Online (Sandbox Code Playgroud) 通过利用MSDN 上的Testing with a Mocking Framework文章中的Testing with async queries部分,我已经能够创建许多成功通过测试.
这是我的测试代码,它使用NSubstitute进行模拟:
var dummyQueryable = locations.AsQueryable();
var mock = Substitute.For<DbSet<Location>, IDbAsyncEnumerable<Location>, IQueryable<Location>>();
((IDbAsyncEnumerable<Location>)mock).GetAsyncEnumerator().Returns(new TestDbAsyncEnumerator<Location>(dummyQueryable.GetEnumerator()));
((IQueryable<Location>)mock).Provider.Returns(new TestDbAsyncQueryProvider<Location>(dummyQueryable.Provider));
((IQueryable<Location>)mock).Expression.Returns(dummyQueryable.Expression);
((IQueryable<Location>)mock).ElementType.Returns(dummyQueryable.ElementType);
((IQueryable<Location>)mock).GetEnumerator().Returns(dummyQueryable.GetEnumerator());
sut.DataContext.Locations = mock;
var result = await sut.Index();
result.Should().BeView();
Run Code Online (Sandbox Code Playgroud)
sut.Index() 没有做太多,但它做了以下查询:
await DataContext.Locations
.GroupBy(l => l.Area)
.ToListAsync());
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,直到我在查询中添加一个投影:
await DataContext.Locations
.GroupBy(l => l.Area)
.Select(l => new LocationsIndexVM{ Area = l.Key }) // added projection
.ToListAsync());
Run Code Online (Sandbox Code Playgroud)
这导致了这个例外:
System.InvalidOperationException
The source IQueryable doesn't implement …Run Code Online (Sandbox Code Playgroud) 刚刚看到了瞥见工具(getglimpse.com),并希望在我的Spark驱动的网站(VS2010,MVC3)上试用它,但是在第一个障碍时就会失败.当我运行我的网站时,我收到以下错误:
Unable to cast object of type 'Glimpse.Net.Plumbing.GlimpseView' to type 'Spark.ISparkView'.
Run Code Online (Sandbox Code Playgroud)
不知道这是一个Glimpse问题还是Spark问题,但是由于Glimpse看起来像一个很酷的工具,所以想要对它进行排序.
我喜欢AutoFixture,但是遇到了一些非常重复的"编排"代码,我觉得它应该能够处理 - 不知何故.
这是我的场景,使用IInterceptor来自Castle Dynamic Proxy的实现进行说明.
首先是被测系统:
public class InterceptorA : IInterceptor
{
public void Intercept(IInvocation context)
{
object proxy = context.Proxy;
object returnValue = context.ReturnValue;
// Do something with proxy and returnValue
}
}
public class InterceptorB : IInterceptor
{
public void Intercept(IInvocation context)
{
object returnValue = context.ReturnValue;
// Do something with different returnValue
}
}
Run Code Online (Sandbox Code Playgroud)
现在进行一些简单的测试,利用xUnit的数据理论支持:
public class InterceptorATests
{
[Theory, CustomAutoData]
public void TestA1(InterceptorA sut, IInvocation context)
{ …Run Code Online (Sandbox Code Playgroud) 在ASP.NET WebForms中,您可以使用以下语法直接在标记中引用appSettings:
<%$ MySettingKey %>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这在ASP.NET MVC中不起作用,因为正如MSDN所指出的,这种语法仅适用于服务器控件.
我遇到过一些我喜欢在ASP.NET MVC视图(WebFormsViewEngine)中使用这种语法糖的情况.有谁知道是否有办法让这个工作?
好像我们可以从WebFormsViewEngine派生出来并将其添加为一个功能,或许?
在我使用AutoFixture的前几天,我可能已经做了以下安排来设置一个名为的服务的单元测试CustomerService:
public void TestName()
{
//Arrange
var fakeResponse = new DerivedHttpResponse();
var fakeHandler = new FakeHttpMessageHandler(fakeResponse); // takes HttpResponse
var httpClient = new HttpClient(fakeHandler);
var sut = new CustomerService(httpClient);
// ...
}
Run Code Online (Sandbox Code Playgroud)
这种冗长的安排似乎是AutoFixture善于解决的问题.我想我可以用AutoFixture重写那个排列,看起来像这样:
public void TestName([Frozen] DerivedHttpResponse response, CustomerService sut)
{
//Nothing to arrange
// ...
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法配置AutoFixture来为我做这个,因为我有很多派生HttpResponse类型,我想从测试方法换成测试方法?
asp.net-mvc ×4
css ×3
.net ×2
asp.net ×2
autofixture ×2
glimpse ×2
less ×2
dotless ×1
hierarchy ×1
html ×1
imodelbinder ×1
mocking ×1
modelbinders ×1
msbuild ×1
oauth ×1
performance ×1
sass ×1
sql ×1
sql-server ×1
web-config ×1
xhtml ×1
xunit ×1