0% found this document useful (0 votes)
16 views4 pages

Pruebas Unitarias Persona

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)
16 views4 pages

Pruebas Unitarias Persona

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/ 4

using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using MarkCRM.Domain.Models;
using MarkCRM.Domain.Enums;
using MarkCRM.Domain.Exceptions.StageException;

namespace MarkCRM.Domain.Test
{
[TestClass]
public class PersonModelTests
{
private TimeZoneInfo boliviaTimeZone;
private DateTime currentDateTime;

public PersonModelTests()
{
boliviaTimeZone =
TimeZoneInfo.FindSystemTimeZoneById("America/La_Paz");
currentDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,
boliviaTimeZone);
}

private PersonModel CreatePersonModel(int id, string name, EstadoPersona


state, int gender,
int nationality, DateTime createdAt,
DateTime lastModifiedAt,
string dni = null, string
fatherLastName = null, string motherLastName = null,
string email = null, string phone =
null, string address = null,
int? religion = null, int? createdBy =
null, int? lastModifiedBy = null)
{
return new PersonModel(id, name, state, gender, nationality, createdAt,
lastModifiedAt,
dni, fatherLastName, motherLastName, email,
phone, address,
religion, createdBy, lastModifiedBy);
}

[TestMethod]
public void ValidateCreatePersonWithValidData()
{
// Arrange
int id = 1;
string name = "John";
string fatherLastName = "Doe";
string motherLastName = "Smith";
string email = "[email protected]";
string phone = "123456789";
string address = "123 Main St";
EstadoPersona state = EstadoPersona.Activo;
string dni = "12345678";
int gender = 1;
int nationality = 1;
int religion = 1;
int created_by = 1;
DateTime created_at = currentDateTime;
DateTime lastModified = currentDateTime;
int lastModifiedBy = 1;

// Act
PersonModel person = CreatePersonModel(id, name, state, gender,
nationality, created_at, lastModified,
dni, fatherLastName,
motherLastName, email, phone, address,
religion, created_by,
lastModifiedBy);

// Assert
Assert.IsNotNull(person);
Assert.AreEqual(id, person.Id);
Assert.AreEqual(name, person.Name);
Assert.AreEqual(fatherLastName, person.FatherLastName);
Assert.AreEqual(motherLastName, person.MotherLastName);
Assert.AreEqual(email, person.Email);
Assert.AreEqual(phone, person.Phone);
Assert.AreEqual(address, person.Address);
Assert.AreEqual(state, person.State);
Assert.AreEqual(dni, person.Dni);
Assert.AreEqual(gender, person.Gender);
Assert.AreEqual(nationality, person.Nationality);
Assert.AreEqual(religion, person.Religion);
Assert.AreEqual(created_at, person.CreatedAt);
Assert.AreEqual(created_by, person.CreatedBy);
Assert.AreEqual(lastModified, person.LastModifiedAt);
Assert.AreEqual(lastModifiedBy, person.LastModifiedBy);
}

[TestMethod]
[DataRow("")]
[DataRow(" ")]
[DataRow("a")]
public void ValidateCreatePersonWithInvalidName(string name)
{
// Act + Assert
Assert.ThrowsException<InvalidFieldException>(() =>
CreatePersonModel(1, name, EstadoPersona.Activo, 1, 1, currentDateTime,
currentDateTime));
}

[TestMethod]
[DataRow("123456-V")] // DNI válido con letra V
[DataRow("654321-R")] // DNI válido con letra R
[DataRow("789012-M")] // DNI válido con letra M
public void ValidateCreatePersonWithValidDniWithLetter(string dni)
{
// Arrange

// Act
PersonModel person = CreatePersonModel(1, "John", EstadoPersona.Activo,
1, 1, currentDateTime, currentDateTime,
dni: dni);

// Assert
Assert.IsNotNull(person);
Assert.AreEqual(dni, person.Dni);
}
[TestMethod]
[DataRow("123456-")] // DNI inválido sin letra después del guion
[DataRow("123456-VR")] // DNI inválido con más de una letra después del
guion
[DataRow("123-456-V")] // DNI inválido con guion en el lugar incorrecto
public void ValidateCreatePersonWithInvalidDniWithLetter(string dni)
{
// Act + Assert
Assert.ThrowsException<InvalidDniException>(() => CreatePersonModel(1,
"John", EstadoPersona.Activo, 1, 1, currentDateTime, currentDateTime,

dni: dni));
}

[TestMethod]
[DataRow("invalid_email")]
[DataRow("john.doe@")]
[DataRow("john.doe@example")]
public void ValidateCreatePersonWithInvalidEmail(string email)
{
// Act + Assert
Assert.ThrowsException<InvalidFieldException>(() =>
CreatePersonModel(1, "John", EstadoPersona.Activo, 1, 1, currentDateTime,
currentDateTime,

email: email));
}

[TestMethod]
[DataRow("12345")] // DNI inválido por longitud incorrecta
[DataRow("1234567890123")] // DNI inválido por longitud excesiva
public void ValidateCreatePersonWithInvalidDniLength(string dni)
{
// Act + Assert
Assert.ThrowsException<InvalidFieldException>(() =>
CreatePersonModel(1, "John", EstadoPersona.Activo, 1, 1, currentDateTime,
currentDateTime,

dni: dni));
}

[TestMethod]
[DataRow("A123456")] // DNI inválido por formato incorrecto
public void ValidateCreatePersonWithInvalidDniFormat(string dni)
{
// Act + Assert
Assert.ThrowsException<InvalidDniException>(() => CreatePersonModel(1,
"John", EstadoPersona.Activo, 1, 1, currentDateTime, currentDateTime,

dni: dni));
}

[TestMethod]
public void ValidateUpdateNameWithValidName()
{
// Arrange
PersonModel person = CreatePersonModel(1, "John", EstadoPersona.Activo,
1, 1, currentDateTime, currentDateTime);
string newName = "Jane";

// Act
person.UpdateName(newName);

// Assert
Assert.AreEqual(newName, person.Name);
}

[TestMethod]
[DataRow("")]
[DataRow(" ")]
[DataRow("a")]
public void ValidateUpdateNameWithInvalidName(string name)
{
// Arrange
PersonModel person = CreatePersonModel(1, "John", EstadoPersona.Activo,
1, 1, currentDateTime, currentDateTime);

// Act + Assert
Assert.ThrowsException<InvalidFieldException>(() =>
person.UpdateName(name));
}
}
}

You might also like