Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StringGeneratorTests.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Diligent.WebAPI.Business.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Diligent.WebAPI.Tests.Helpers
  8. {
  9. public class StringGeneratorTests
  10. {
  11. [Fact]
  12. public void GeneratePassword_ShouldReturn_8_Characters_IfOptionsAreNull()
  13. {
  14. Assert.Equal(8, StringGenerator.GenerateRandomPassword().Length);
  15. }
  16. [Fact]
  17. public void GeneratePassword_ShouldReturn_4_Characters_IfOptionsDefinedLess()
  18. {
  19. Assert.Equal(4, StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
  20. {
  21. RequiredLength = 3,
  22. RequiredUniqueChars = 3,
  23. RequireDigit = true,
  24. RequireLowercase = true,
  25. RequireNonAlphanumeric = true,
  26. RequireUppercase = true
  27. }).Length);
  28. }
  29. [Fact]
  30. public void GeneratePassword_ShouldReturn_15_Characters_IfOptionsHaveDefinedMinLength()
  31. {
  32. Assert.Equal(15, StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
  33. {
  34. RequiredLength = 15,
  35. RequiredUniqueChars = 4,
  36. RequireDigit = true,
  37. RequireLowercase = true,
  38. RequireNonAlphanumeric = true,
  39. RequireUppercase = true
  40. }).Length);
  41. }
  42. [Fact]
  43. public void GeneratePassword_ShouldContainUppercase_IfOptionsAreNull()
  44. {
  45. Assert.Contains(StringGenerator.GenerateRandomPassword(), char.IsUpper);
  46. }
  47. [Fact]
  48. public void GeneratePassword_ShoulContainNumber_IfOptionsAreNull()
  49. {
  50. Assert.Contains(StringGenerator.GenerateRandomPassword(), char.IsDigit);
  51. }
  52. [Fact]
  53. public void GeneratePassword_ShouldNotContainNumber_AfterAddingRandomChars()
  54. {
  55. Assert.Contains(StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
  56. {
  57. RequiredLength = 12,
  58. RequiredUniqueChars = 4,
  59. RequireDigit = false,
  60. RequireLowercase = true,
  61. RequireNonAlphanumeric = true,
  62. RequireUppercase = false
  63. }), char.IsDigit);
  64. }
  65. [Fact]
  66. public void GeneratePassword_ShoulContainSpecialChar_IfOptionsAreNull()
  67. {
  68. Assert.False(StringGenerator.GenerateRandomPassword().All(char.IsLetterOrDigit));
  69. }
  70. [Fact]
  71. public void GeneratePassword_ShouldContainSpecialChar_IfOptionsAreDefinedToAddRandomChars()
  72. {
  73. Assert.False(StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
  74. {
  75. RequiredLength = 12,
  76. RequiredUniqueChars = 1,
  77. RequireDigit = true,
  78. RequireLowercase = true,
  79. RequireNonAlphanumeric = false,
  80. RequireUppercase = true
  81. }).All(char.IsLetterOrDigit));
  82. }
  83. }
  84. }