0% found this document useful (0 votes)
2 views2 pages

Messagea

The document contains a unit test class for validating password security in a RegisterViewModel. It includes tests for checking password length, the presence of uppercase characters, and special symbols. The RegisterViewModel class implements methods to determine if a password meets the security criteria.

Uploaded by

titomixterdj5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Messagea

The document contains a unit test class for validating password security in a RegisterViewModel. It includes tests for checking password length, the presence of uppercase characters, and special symbols. The RegisterViewModel class implements methods to determine if a password meets the security criteria.

Uploaded by

titomixterdj5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

```cs

using System.Text;

namespace PruebasUnitarias1;

public class UnitTest1


{
[Fact]
public void
IsPasswordSecure_returns_false_if_password_has_less_than_8_characters()
{
//Arrange
var registerViewModel = new RegisterViewModel();

//Act
bool result = registerViewModel.IsPasswordSecure("1234567");

//Assert
Assert.False(result);

}
[Fact]
public void
IsPasswordSecure_returns_false_if_password_does_not_contains_uppercase_character()
{
//Arrange
var registerViewModel = new RegisterViewModel();

//Act
bool result = registerViewModel.IsPasswordSecure("12345678a");

//Assert
Assert.False(result);

}
[Fact]
public void
IsPasswordSecure_returns_true_if_password_contains_an_uppercase_character_and_a_sym
bol()
{
// Arrange
var registerViewModel = new RegisterViewModel();

// Act
bool result = registerViewModel.IsPasswordSecure("Q23D@45");

// Assert
Assert.False(result);
}
}

internal class RegisterViewModel


{
internal bool IsPasswordSecure(string password)
{
if (password.Length < 8)
{
return false;
}
//1234A5678
if (!ContieneMayuscula(password))
{
return false;
}

if (!ContieneSimbolo(password))
{
return false;
}

return true;
}

private bool ContieneMayuscula(string password)


{
char[] passwordChars = password.ToCharArray();
foreach (char c in passwordChars)
{
if (Char.IsLetter(c) && IsUpper(c))
{
return true;
}
}
return false;
}

private bool IsUpper(char c)


{
int codigoAscii = Convert.ToInt32(c);

return codigoAscii >= 65 && codigoAscii <= 90;

private bool ContieneSimbolo(string password)


{
foreach (char c in password)
{
if (!Char.IsLetterOrDigit(c) && !Char.IsWhiteSpace(c))
{
return true;
}
}
return false;
}
}```

You might also like