我需要美国电话号码格式的常规快递.我想用JavaScript替换电话号码字符串到美国电话号码字符串格式.
var number = "4031234789";
Run Code Online (Sandbox Code Playgroud)
我想以下面的格式掩盖它: -
number = number.mask('(000) 000-0000');
Run Code Online (Sandbox Code Playgroud)
任何人都可以在JavaScript中向我展示正则表达式吗?
我有一个.VSDX扩展文件.我没有得到打开它的工具.
我尝试过Visio Viewer(Google Chrome扩展程序).但它没有在chrome工具栏中显示.
任何人都可以建议在线网站或工具打开它吗?
我有一个以下LINQ查询:
var productTypes = from ProductDto e in Product
select new
{
Id = e.Product.ID,
Name = e.Product.name
};
Run Code Online (Sandbox Code Playgroud)
在上面的LINQ查询中,e.Product可能是null.但我没有找到方法.
谁能帮我吗 ?null如果e.Product是,我想在productTypes变量中赋值null.
在单元测试中模拟以下代码的最佳方法是什么:
public ActionResult Products()
{
ViewBag.Title = "Company Product";
IEnumerable<ProductDetailDto> productList = ProductService.GetAllEffectiveProductDetails();
ProductModels.ProductCategoryListModel model = new ProductModels.ProductCategoryListModel
{
//the type of ProductDetails => IEnumerable<productDetailDto>
ProductDetails = ProductService.GetAllEffectiveProductDetails(),
//the type of ProductCategoryList => IEnumerable<selectlistitem>
ProductCategoryList = productList.Select(x => new SelectListItem
{
Value = x.FKProductId.ToString(),
Text = x.Name
})
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
仅供参考,我正在开发VS 2012,MVC 4.0,使用MOQ对象进行单元测试和TFS设置.
任何人都可以帮我解决这个问题,对于上述方法,使用模拟对象的最佳测试方法是什么?
我正在为我的控制器和服务层(C#,MVC)进行单元测试.我正在使用Moq DLL来模拟单元测试中的真实/依赖对象.
但是我对于模拟依赖项或真实对象有点困惑.让我们举一个以下单元测试方法的例子: -
[TestMethod]
public void ShouldReturnDtosWhenCustomersFound_GetCustomers ()
{
// Arrrange
var name = "ricky";
var description = "this is the test";
// setup mocked dal to return list of customers
// when name and description passed to GetCustomers method
_customerDalMock.Setup(d => d.GetCustomers(name, description)).Returns(_customerList);
// Act
List<CustomerDto> actual = _CustomerService.GetCustomers(name, description);
// Assert
Assert.IsNotNull(actual);
Assert.IsTrue(actual.Any());
// verify all setups of mocked dal were called by service
_customerDalMock.VerifyAll();
}
Run Code Online (Sandbox Code Playgroud)
在上面的单元测试方法中,我正在模拟GetCustomers方法并返回一个客户列表.哪个已定义.看起来如下:
List<Customer> _customerList = new List<Customer>
{
new Customer { CustomerID …Run Code Online (Sandbox Code Playgroud) 下面是控制器方法代码(c#)的一部分: -
public ActionResult SelectProduct(string ProdName, int Block, int ProductAddressId = 0)
{
if (ProductAddressId == 0 && Block == 1 && System.Web.HttpContext.Current.Session["ReturnProductAddressID"] != null)
{
ProductAddressId = (int)System.Web.HttpContext.Current.Session["ReturnProductAddressID"];
}
//other stuffs………
}
Run Code Online (Sandbox Code Playgroud)
以下是单元测试方法: -
[TestMethod]
public void SelectProduct_Condition1_Test()
{
//Arrange
var controller = new ProductController();
var prodName = string.Empty;
var block = 1;
var productAddressId = 0;
//section 1
/*var mockControllerContext = new Mock<ControllerContext>();
var mockSession = new Mock<HttpSessionStateBase>();
mockSession.SetupGet(s => s["ReturnProductAddressID"]).Returns("1");
mockControllerContext.Setup(p => p.HttpContext.Session).Returns(mockSession.Object);*/
//section 2
/*int sessionValue …Run Code Online (Sandbox Code Playgroud) 我正在使用Kendo UI网格控件处理ASP.NET MVC4.我正在使用展开折叠功能来显示网格行.
我的问题是在页面加载时只有第一个父行子元素(行)正在展开/显示(根据现有代码).而其他父行(在第一个父行下面)则不是.
但是我希望在页面加载时显示所有父行和子行,而不需要详细说明父行.
下面是父行的代码段:
@(Html.Kendo().Grid<Gts.Core.Dto.CategoryViewModel>()
.Name("CategoryItemsGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.CategoryID))
.Read(read => read.Action("CategoryItems","Category").Data("additionalIDetail"))
)
Run Code Online (Sandbox Code Playgroud)
下面是子行的代码段:
@(Html.Kendo().Grid<Gts.Core.Dto.CategoryViewModel >()
.Name("Categories_#=CategoryID#")
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.CategoryItemID))
.Read(read => read.Action("CategoryChildItems", "Category", new { CategoryItemID = "#=CategoryItemID#", categoryId = "#=FKCategoryID#" }))
.Destroy(update => update.Action("CategoryItemsDestroy", "Category"))
)
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何解决它?
我想为try catch block(C#)编写单元测试。
Public ActionResult Index()
{
try
{
-------------
}
catch(Exception ex)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在控制器的索引方法中使用try-catch块。而在对该方法进行单元测试时,我也想覆盖try-catch块。在catch块中我抛出了异常。但是我没有有任何想法吗?有人可以建议我处理try-catch块的最佳方法吗?仅供参考,我在这里未指定任何异常类型,它将引发/引发任何异常。
我有剑道网格。问题是网格的标题和数据行列没有正确对齐。

以下是剑道网格代码:
@(Html.Kendo().Grid(Model.Product)
.Name("Grid")
.Scrollable(a => a.Height("auto"))
.Columns(columns =>
{
columns.Bound(o => o.ProductId).Sortable(true)
.ClientTemplate("<a href='/Product/ProductEntry/#=ProductID#' target='_blank'>#=Product#</a>")
.Title("Order #");
columns.Bound(p => p.Name);
columns.Bound(p => p.LastName);
columns.Bound(p => p.Insurance);
columns.Bound(p => p.LastUpdate);
})
.Pageable()
.Sortable()
.Resizable(resize => resize.Columns(false))
.Reorderable(reorder => reorder.Columns(false))
)
Run Code Online (Sandbox Code Playgroud) 我想掩盖我的javascript变量值.基本上我在变量中得到电话号码字段值,在得到它之后我想以其他格式掩盖它.
我已经尝试了jquery Mask插件,但是它的掩码是控件的字符串格式.但是我想将字符串掩盖到变量中.
例如:
我有一个电话串"0000000000",我将它存储在一个变量中: -
var number ="0000000000"
Run Code Online (Sandbox Code Playgroud)
之后我想以其他格式掩盖它.喜欢 -
1)number = number.mask('000-0000'); 2)number = number.mask('(000)000-0000');
c# ×4
unit-testing ×4
moq ×3
javascript ×2
kendo-grid ×2
asp.net-mvc ×1
controller ×1
expand ×1
linq ×1
mask ×1
mocking ×1
null ×1
phone-number ×1
regex ×1
try-catch ×1
variables ×1
visio ×1