| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using Diligent.WebAPI.Business.Helper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Diligent.WebAPI.Tests.Helpers
- {
- public class StringGeneratorTests
- {
- [Fact]
- public void GeneratePassword_ShouldReturn_8_Characters_IfOptionsAreNull()
- {
- Assert.Equal(8, StringGenerator.GenerateRandomPassword().Length);
- }
-
- [Fact]
- public void GeneratePassword_ShouldReturn_4_Characters_IfOptionsDefinedLess()
- {
- Assert.Equal(4, StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
- {
- RequiredLength = 3,
- RequiredUniqueChars = 3,
- RequireDigit = true,
- RequireLowercase = true,
- RequireNonAlphanumeric = true,
- RequireUppercase = true
- }).Length);
- }
-
- [Fact]
- public void GeneratePassword_ShouldReturn_15_Characters_IfOptionsHaveDefinedMinLength()
- {
- Assert.Equal(15, StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
- {
- RequiredLength = 15,
- RequiredUniqueChars = 4,
- RequireDigit = true,
- RequireLowercase = true,
- RequireNonAlphanumeric = true,
- RequireUppercase = true
- }).Length);
- }
-
- [Fact]
- public void GeneratePassword_ShouldContainUppercase_IfOptionsAreNull()
- {
- Assert.Contains(StringGenerator.GenerateRandomPassword(), char.IsUpper);
- }
-
- [Fact]
- public void GeneratePassword_ShoulContainNumber_IfOptionsAreNull()
- {
- Assert.Contains(StringGenerator.GenerateRandomPassword(), char.IsDigit);
- }
-
- [Fact]
- public void GeneratePassword_ShouldNotContainNumber_AfterAddingRandomChars()
- {
- Assert.Contains(StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
- {
- RequiredLength = 12,
- RequiredUniqueChars = 4,
- RequireDigit = false,
- RequireLowercase = true,
- RequireNonAlphanumeric = true,
- RequireUppercase = false
- }), char.IsDigit);
- }
-
- [Fact]
- public void GeneratePassword_ShoulContainSpecialChar_IfOptionsAreNull()
- {
- Assert.False(StringGenerator.GenerateRandomPassword().All(char.IsLetterOrDigit));
- }
-
- [Fact]
- public void GeneratePassword_ShouldContainSpecialChar_IfOptionsAreDefinedToAddRandomChars()
- {
- Assert.False(StringGenerator.GenerateRandomPassword(new Microsoft.AspNetCore.Identity.PasswordOptions
- {
- RequiredLength = 12,
- RequiredUniqueChars = 1,
- RequireDigit = true,
- RequireLowercase = true,
- RequireNonAlphanumeric = false,
- RequireUppercase = true
- }).All(char.IsLetterOrDigit));
- }
- }
- }
|