我有一个测试类,下面我从测试类发布了一个示例测试
namespace AdminPortal.Tests.Controller_Test.Customer
{
[TestClass]
public class BusinessUnitControllerTests
{
private IBusinessUnitRepository _mockBusinessUnitRepository;
private BusinessUnitController _controller;
[TestInitialize]
public void TestInitialize()
{
_mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>();
_controller = new BusinessUnitController(_mockBusinessUnitRepository);
}
[TestCleanup]
public void TestCleanup()
{
_mockBusinessUnitRepository = null;
_controller.Dispose();
_controller = null;
}
#region Index Action Tests
[TestMethod]
public void Index_Action_Calls_GetAllBusinessUnit()
{
_mockBusinessUnitRepository.Stub(x => x.GetAllBusinessUnit());
_controller.Index();
_mockBusinessUnitRepository.AssertWasCalled(x=>x.GetAllBusinessUnit());
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行项目时,我得到了以下屏幕

我检查了引用,测试项目引用了主项目.知道为什么测试没有运行或说它们没有结果?
编辑1:
我在这里看到了一个帖子并将我的测试设置的默认处理器架构更改为X64,但它仍然无效.
我最近更新Asp.Net Identity Core了我的申请表1.0到2.0.
有一些我想尝试的新功能GenerateEmailConfirmationToken,等等.
我正在使用这个项目作为参考.
当用户尝试注册时,我在执行Register方法时遇到错误
private readonly UserManager<ApplicationUser> _userManager;
public ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var ifUserEXists = _userManager.FindByName(model.EmailId);
if (ifUserEXists == null) return View(model);
var confirmationToken = _userRepository.CreateConfirmationToken();//this is how i'm generating token currently.
var result = _userRepository.CreateUser(model,confirmationToken);
var user = _userManager.FindByName(model.EmailId);
if (result)
{
var code = _userManager.GenerateEmailConfirmationToken(user.Id);//error here
_userRepository.SendEmailConfirmation(model.EmailId, model.FirstName, confirmationToken);
//Information("An email is sent to your email address. Please follow the link to activate your account.");
return …Run Code Online (Sandbox Code Playgroud) 在我看来,我有一个enumdropdownlist(Asp.Net MVC 5.1中的一个新功能).
@Html.EnumDropDownListFor(m => m.SelectedLicense,new { @class="form-control"})
Run Code Online (Sandbox Code Playgroud)
如果我执行上面的代码,我会得到以下枚举的下拉列表.
public enum LicenseTypes
{
Trial = 0,
Paid = 1
}
Run Code Online (Sandbox Code Playgroud)
但默认情况下,我希望我的下拉列表有一个值(自定义文本),这就是我尝试过的
@Html.EnumDropDownListFor(m => m.SelectedLicense,"Select a license" ,new { @class="form-control"})
Run Code Online (Sandbox Code Playgroud)
但现在问题是当我运行它时,我的下拉列表看起来像这样
因此,默认情况下不显示我想显示的默认文本.如果用户选择"选择许可证"并尝试提交表单,则会显示错误"选择许可证",但不会显示为默认文本.我需要改变什么?
Ps:图像是加载时页面的屏幕截图.默认情况下,它会将"试用"显示为选定选项.
我有这个模型
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个验证,其中FirstName或LastName必须由用户填写.我安装FluentValidation并创建了一个customvalidator类
public class PersonValidator:AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor((person=>person.FirstName)//don't know how to check if one is empty
}
}
Run Code Online (Sandbox Code Playgroud)
要检查我可以做的一个字段 RuleFor(person => person.FirstName).NotNull();
但是我如何检查其中一个是否为空.
此外,一旦通过验证创建,是否有可能fluentValidation在客户端使用它来显示错误?
EDIT1
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
FluentValidationModelValidatorProvider.Configure();
}
//creating validation
namespace WebApplication1.Models.CustomValidator
{
public class PersonValidator:AbstractValidator<Person>
{
public PersonValidator() …Run Code Online (Sandbox Code Playgroud) 目前正在链接中
Customer/businessunit/RepresentativeDetails?RepresentativeId=cd3a7263-78f7-41bd-9eb0-12b30bc1059a
我有以下代码供查看
@Html.ActionLink("Back to List", "Index")
Run Code Online (Sandbox Code Playgroud)
它带我到这个链接
customer/businessunit/index
Run Code Online (Sandbox Code Playgroud)
而是转到索引页面我想在单击actionlink时转到上一页,这是
Customer/businessunit/BusinessUnitDetails/c4a86253-a287-441e-b83d-71fbb6a588bc
Run Code Online (Sandbox Code Playgroud)
如何创建指向上一页的动作链接?就像是@Html.ActionLink("Back to Details", //go to previous page)
MVC 5是否有默认验证,我可以设置日期的最小值和最大值?
在我的模型中,我想要日期验证
public class MyClass
{
[Required(ErrorMessage="Start date and time cannot be empty")]
//validate:Must be greater than current date
[DataType(DataType.DateTime)]
public DateTime StartDateTime { get; set; }
[Required(ErrorMessage="End date and time cannot be empty")]
//validate:must be greater than StartDate
[DataType(DataType.DateTime)]
public DateTime EndDateTime { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Ps:根据这个Asp.Net网站,使用RangeDateTime验证器时出现问题,不推荐使用.
注意:jQuery验证不适用于Range属性和DateTime.例如,以下代码将始终显示客户端验证错误,即使日期在指定范围内:
[Range(typeof(DateTime), "1/1/1966", "1/1/2020")]您需要禁用jQuery日期验证才能将Range属性与DateTime一起使用.在模型中编译硬日期通常不是一个好习惯,因此不鼓励使用Range属性和DateTime.
我也知道有一些像Fluent Validation和Foolproof这样的Nuget软件包可以验证和检查一个日期是否比其他日期更大,但我想知道默认情况下是否有东西可以检查日期的最小值和最大值.
从我在MVC 5.1中的Whats new中看到的,有支持MaxLength和MinLength验证.
我试图学习Asp.Net Identity,在本教程中,
在Models\AppModels中创建实体框架代码First ToDo模型,cs part MyUser类继承自IdentityUser类并MyDbContext继承自IdentityDbContext<MyUser>类.这是为什么?
假设我有一个User类,它包含我的Web应用程序用户的所有信息,如果该类继承自IdentityUser,我应该DbContext继承IdentityDbContext<User>吗?
此外,继承IdentityDbContext<TClass>普通DbContext类的dbcontext类与MVC 4 中的优点相同
我有这些枚举
public enum QuestionStart
{
[Display(Name="Repeat till common match is found")]
RepeatTillCommonIsFound,
[Display(Name="Repeat once")]
RepeatOnce,
[Display(Name="No repeat")]
NoRepeat
}
public enum QuestionEnd
{
[Display(Name="Cancel Invitation")]
CancelInvitation,
[Display(Name="Plan with participants on first available common date")]
FirstAvailableCommon,
[Display(Name="Plan with participants on my first available common date")]
YourFirstAvailableCommon
}
Run Code Online (Sandbox Code Playgroud)
我有一个帮助类来显示枚举中每个字段的所有单选按钮
@model Enum
@foreach (var value in Enum.GetValues(Model.GetType()))
{
@Html.RadioButtonFor(m => m, value)
@Html.Label(value.ToString())
<br/>
}
Run Code Online (Sandbox Code Playgroud)
现在标签设置为值名称,而不是我为值给出的显示名称.
例如:
[Display(Name="Cancel Invitation")]
CancelInvitation
Run Code Online (Sandbox Code Playgroud)
我CancelInvitation旁边有单选按钮.
如何让它显示我给它的显示名称(Cancel Invitation)?
我创建了一个新的MVC4互联网应用程序.我只是关注ASP.NET MVC4 in Action一书.本章是Ajax是MVC中的ASP.NET.索引的视图是这样的
@section head{
<script type ="text/javascript"
src="@Url.Content("~/Scripts/AjaxDemo.js")"></script>
}
@Html.ActionLink("Show the privacy policy", "PrivacyPolicy", null, new{id="privacyLink"})
<div id="privacy"></div>
Run Code Online (Sandbox Code Playgroud)
部分视图包含一些非常基本的标记.
<h2>Our Commitment to privacy</h2>
This is sample priavcy policy.
Run Code Online (Sandbox Code Playgroud)
在AjaxDemo.js文件中,其路径在index.cshtml文件中给出,我的代码很小
$(document).ready(function() {
$('privacyLink').click(function(event) {
event.preventDefault();
var url = $(this).attr('href');
$('#privacy').load(url);
});
});
Run Code Online (Sandbox Code Playgroud)
现在,当我运行此应用程序并手动将链接指定为 http://localhost:19208/customajax
我得错误说
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "head".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack …Run Code Online (Sandbox Code Playgroud) 我以前曾问过这个问题.这个想法是一样的,除了我必须找到确定的所有共同时间TimeSpan.
背景
让我们假设,
我想见到一些人,我说我希望在Datetime X(2014-02-16 09:00:00.000)到DateTime Y(2014-02-26 05:00:00.000)之间遇到某些人.而且我说我希望会议能够持续至少N几个小时.
然后我想见的人将回复说我将在以下日期提供:
Date1(Certain date from certain start time to certain end time),
Date2(certain date from certain time to certain time),
...
Run Code Online (Sandbox Code Playgroud)
等等.
目的
然后我必须找出是否存在包含在所有用户响应中的时间范围.
让我们考虑这些是回应
Attendee1(一些GuidId):Response1:Start Time = 2014-02-23 09:00 AM,EndTime = 2014-02-23 11:00 AM,
Response2:Start Time = 2014-02-24 10:00 AM,EndTime = 2014-02-24 12:00 PM,
Response3:开始时间= 2014-02-25 10:00 AM,EndTime = 2014-02-25 11:00 AM,
Response4:Start Time = 2014-02-23 01:00 PM,EndTime = 2014-02-17 5:00 PM
Attendee2(一些GuidId): …
asp.net-mvc ×8
c# ×8
.net ×1
algorithm ×1
asp.net ×1
enums ×1
linq ×1
resharper ×1
routing ×1
unit-testing ×1
validation ×1