我angular-ui-router在我的应用程序中使用和嵌套状态,我还有一个导航栏.导航栏是手写的,ui-sref-active用于突出显示当前状态.这是一个两级导航栏.
现在,当我进入时,说Products / Categories我希望两者Products(第1级)和Categories(第2级)都能突出显示.但是,使用ui-sref-active,如果我处于状态,Products.Categories则只突出显示该状态,而不是Products.
有没有办法Products在那个州强调?
我通过添加一个新属性来扩展ApplicationUser类(如教程中所示, 使用Facebook和Google OAuth2和OpenID登录创建一个ASP.NET MVC 5应用程序(C#))
public class ApplicationUser : IdentityUser
{
public DateTime BirthDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个单元测试来验证我的AccountController是否正确保存了BirthDate.
我创建了一个名为TestUserStore的内存用户存储
[TestMethod]
public void Register()
{
// Arrange
var userManager = new UserManager<ApplicationUser>(new TestUserStore<ApplicationUser>());
var controller = new AccountController(userManager);
// This will setup a fake HttpContext using Moq
controller.SetFakeControllerContext();
// Act
var result =
controller.Register(new RegisterViewModel
{
BirthDate = TestBirthDate,
UserName = TestUser,
Password = TestUserPassword,
ConfirmPassword = TestUserPassword
}).Result;
// Assert
Assert.IsNotNull(result);
var addedUser = userManager.FindByName(TestUser);
Assert.IsNotNull(addedUser);
Assert.AreEqual(TestBirthDate, …Run Code Online (Sandbox Code Playgroud) 我使用gmail类,以便我的应用程序可以通过Gmail发送通知.
它是这样做的:
public static void SendMessage(string message)
{
Notification.message = message;
Thread t = new Thread(new ThreadStart(SendMessageThreaded));
t.Start();
}
Run Code Online (Sandbox Code Playgroud)
并且线程函数看起来像这样:
private static void SendMessageThreaded()
{
try
{
if (Notification.message != "")
RC.Gmail.GmailMessage.SendFromGmail("accname", "accpass", "email", "subject", Notification.message);
Notification.message = "";
}
catch
{ }
}
Run Code Online (Sandbox Code Playgroud)
所以在SendMessageThreaded运行之后,它会自行关闭还是必须关闭
t.Start()
t.Abort()
Run Code Online (Sandbox Code Playgroud)
或者其他的东西?
Martin Fowler的Refactoring讨论了创建Null对象以避免大量的问题
if (myObject == null)
Run Code Online (Sandbox Code Playgroud)
试验.这样做的正确方法是什么?我的尝试违反了"构造函数中的虚拟成员调用"规则.这是我的尝试:
public class Animal
{
public virtual string Name { get; set; }
public virtual string Species { get; set; }
public virtual bool IsNull
{
get { return false; }
}
}
public sealed class NullAnimal : Animal
{
public override string Name
{
get{ return "NULL"; }
set { }
}
public override string Species
{
get { return "NULL"; }
set { }
}
public virtual bool IsNull
{
get { …Run Code Online (Sandbox Code Playgroud) OAuth 服务器使用以下不同的声明类型发出角色声明System.Security.Claims.ClaimTypes.Role:
var adminRole = new Claim("CustomRole", "Admin");
context.Ticket.Identity.AddClaim(adminRole);
Run Code Online (Sandbox Code Playgroud)
如何告诉OAuthBearerAuthentication中间件使用我的自定义角色声明类型,以便它使Authorize属性正常工作:
//Startup
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions ...
[Authorize(Roles = "Admin")]
public IHttpActionResult SecureAction()
Run Code Online (Sandbox Code Playgroud)