我对Asp.net页面中静态变量的使用存在疑问.
我有一页说UserDetails.aspx.在这个页面中,我有一个静态变量来存储特定于用户的一些数据.那么,这个变量是否会在多个用户之间共享,或者为每个用户创建一个单独的变量?
public partial class UserDetails : System.Web.UI.Page
{
static int numberOfReviews=0;
protected void Page_Load(object sender, EventArgs e)
{
numberOfReviews= GetReviews();
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,numberOfReviews是特定于每个用户还是将被共享?
numberOfReviews
我问一个问题,我有一个逗号分隔的数值在这里.
鉴于一些回复,我试图尝试实现我自己的模型绑定器,如下所示:
namespace MvcApplication1.Core
{
public class PropertyModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
object objectModel = new object();
if (bindingContext.ModelType == typeof(PropertyModel))
{
HttpRequestBase request = controllerContext.HttpContext.Request;
string price = request.Form.Get("Price").Replace(",", string.Empty);
ModelBindingContext newBindingContext = new ModelBindingContext()
{
ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(
() => new PropertyModel()
{
Price = Convert.ToInt32(price)
},
typeof(PropertyModel)
),
ModelState = bindingContext.ModelState,
ValueProvider = bindingContext.ValueProvider
};
// call the default model binder this new binding context
return base.BindModel(controllerContext, newBindingContext); …Run Code Online (Sandbox Code Playgroud) 我在我的单元测试项目中使用Moq.我在网上看到的大多数单元测试示例结束时,someMock.VerifyAll(); 我想知道是否可以断言VerifyAll().所以,例如,
//Arrange
var student = new Student{Id = 0, Name="John Doe", IsRegistered = false};
var studentRepository = new Mock<IStudentRepository>();
var studentService= new StudentService(studentRepository.Object);
//Act
studentService.Register(student); //<-- student.IsRegistered = true now.
//Verify and assert
studentRepository.VerifyAll();
Assert.IsTrue(student.IsRegistered);
Run Code Online (Sandbox Code Playgroud)
任何想法?谢谢.
所以,我们可以从控制器返回一个局部视图,如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
public PartialViewResult Address()
{
Address a = new Address { Line1 = "111 First Ave …Run Code Online (Sandbox Code Playgroud) 在TDD或BDD中,我们从未通过单元测试开始,然后修复测试中的方法以使单元测试通过.
通常,在新工作中,我们需要为现有方法编写单元测试.可能不是一个好的做法,但这确实发生了.这就是我现在的情况.
所以,这是我的问题:我应该让现有方法的单元测试失败吗?谢谢.
我遇到querySelectorAll了IE7的这个polyfill :
https://gist.github.com/connrs/2724353
我以为我在JavaScript中是Okayish,但我从来没有见过像polyfill第9行中的引用部分:
{x:expression(document.__qsaels.push(this))}
Run Code Online (Sandbox Code Playgroud)
显然,它是一个具有键x和价值的JavaScript对象expression(document.__qsaels.push(this)),但除此之外,我知道,这对我来说是神秘的.这个expression功能有什么作用?我无法通过谷歌找到任何东西.
命名单元测试方法的一般规则是什么?我相信很多人都对这个问题感到疑惑.假设,一个被测试的方法是
public Customer GetCustomerById(int id)
Run Code Online (Sandbox Code Playgroud)
您如何命名单元测试方法?
GetCustomerById?
GetCustomerByIdTest?
GetCustomerByIdShouldReturnCustomer?
GetCustomerByIdShoudReturnCustomerWhenItSucceeds?
GetCustomerByIdShouldReturnNullWhenNotFound?
Get_Customer_By_Id?
..等等等等.
有什么想法吗?谢谢.
似乎没有多少人在测试asp.net vNext MVC 6,因为我无法挖掘出太多资源.我很感兴趣,所以这些天我一直在测试它.
在Scott的文章中,他说
所以不要写这个:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
你可以写这个:
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="UserName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserName" class="form-control" />
<span asp-validation-for="UserName" class="text-danger"></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我在运行Windows Server 2012和Visual Studio 2015 CTP的azure虚拟机中尝试过它.新的HTML标记没有用.我使用新语法对这些输入字段进行回发时获得空值,input asp-for …
我的数据库是:
Oracle 数据库 10g 企业版版本 10.1.0.5.0 - 64 位
公司刚刚给了我一个装有 Windows 10 的新桌面。我安装了 SQL Developer 版本 18.1.0.095 Build 095.1630。除了 dbms_output.put_line 不再打印任何内容之外,一切正常。例如这个简单的脚本:
SET SERVEROUTPUT ON;
BEGIN
dbms_output.put_line('hola');
END;
Run Code Online (Sandbox Code Playgroud)
只是给了我这个:
而在 Windows 7 Professional 机器上,SQL Developer 版本 4.2.0.17.089 Build 17.089.1709 连接到同一个 Oracle 实例,完全相同的脚本可以很好地打印出 Hola。看:
此外,Toad 版本 12.12.0.39 执行此脚本并打印出 Hola 也没有问题。
我看到有人在这里使用相同版本的 SQL Developer 遇到同样的问题: https: //www.thatjeffsmith.com/archive/2012/03/dbms_output-in-sql-developer/ 检查评论部分。
这可能是版本 18.1.0.095 的错误吗?
所以我已经通过实体框架5设置了.我在数据库中有一个Customers表.获得给定邮政编码的客户最有效的方法是什么?例如94023?我有这个:
var customersOfLosAltos =
(myDbContext.CreateObjectSet<Customer>()).Where(c=>c.Zip == "94023");
Run Code Online (Sandbox Code Playgroud)
但是,直观地说,这似乎效率很低,因为据我所知,它基本上从数据源中检索所有客户,然后通过给定的zip过滤掉它.如果我只有几百个客户,那可能没问题,如果我有一百万客户怎么办?
有什么想法吗?谢谢.
我正在阅读mssqltips上的文章,想尝试正则表达式中的插入符号。我非常了解正则表达式并且经常使用它,尽管在 SQl Server 查询中使用得不多。
对于以下名称列表,我原以为 1) select * from people where name like '%[^m]%;'会返回那些不包含“m”的名称。但事实并非如此。我知道我可以做得到2) select * from people where name not like '%m%';我想要的结果,但我只是困惑为什么 1) 不能按预期工作。
我正在使用 SQL Server 2017,但这里有一个小提琴:
unit-testing ×3
asp.net-mvc ×2
c# ×2
razor ×2
asp.net ×1
asp.net-core ×1
dbms-output ×1
expression ×1
javascript ×1
moq ×1
sql ×1
sql-like ×1
sql-server ×1
t-sql ×1
validation ×1