public async Task Test_TokenController_Default_Fail() { //Arrange SecuritySettings securitySettings = new SecuritySettings() { Secret = "a secret that needs to be at least 16 characters long", Issuer = "your app", Audience = "the client of your app", IdType = IdType.Name, TokenExpiryInHours = 1.2, }; var securityService = new SecurityService(securitySettings); //Authenticator returns a false, token is not generated. var authenticator = new DefaultAuthenticator(false); var controller = new TokenController(securityService, authenticator); User user = new User { Id = "John Doe", Password = "******" }; //Act var result = await controller.Create(user); //Assert Assert.IsType <BadRequestResult>(result); }
public async Task Test_TokenController_Default_Pass() { //Arrange SecuritySettings securitySettings = new SecuritySettings() { Secret = "a secret that needs to be at least 16 characters long", Issuer = "your app", Audience = "the client of your app", IdType = IdType.Name, TokenExpiryInHours = 1.2, }; var securityService = new SecurityService(securitySettings); //Authenticator returns a true, token is generated. var authenticator = new DefaultAuthenticator(true); var controller = new TokenController(securityService, authenticator); User user = new User { Id = "John Doe", Password = "******" }; //Act var result = await controller.Create(user); //Assert Assert.IsType <ObjectResult>(result); Assert.True((result as ObjectResult).Value.ToString().IsValidJwtToken()); }