XUnit.NET Extensions, AssumeIdentity

by cristian 7. September 2009 21:01

Una de las excelentes características y habilidades de XUnit.NET es su capacidad de ser extendido en muchas formas. Como parte del “paquete” de XUnit.NET, se incluye una librería adicional con atributos extras para cambiar en cierta manera el comportamiento de un test mientras realizamos las pruebas. A esta librería se le llama XUnit.NET Extensions y viene incluída con el download de XUnit.NET. Veremos algunos de los atributos extras incluídos con XUnit.NET Extensions.

El primero en ver será AssumeIdentity, este atributo permite cambiar el Principal de la actual Thread de ejecución y agregarle el rol indicado por el atributo. Por defecto la thread de ejecución del test corre bajo el principal con la identity de “xunit”.

[Fact]
public void It_should_fail_because_user_has_no_role()
{
    Assert.False(Thread.CurrentPrincipal.IsInRole("fake_role"));
}

[Fact]
[AssumeIdentity("fake_role")]
public void It_should_pass_because_user_is_in_role()
{
    Assert.True(Thread.CurrentPrincipal.IsInRole("fake_role"));
}

Voilà! Luego converaremos de los otros atributos disponibles en este namespace.

Tags: , ,

.Net | Testing

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About me

Hi, My name is Cristian Prieto, I'm a Senior Software Developer living in Guatemala, Central America. I mainly "speak" in .Net languages (like C#, F# and _even_ VB.NET) but I really love programming in Python/Ruby/Erlang. When I'm not programming (or speaking at a .net user group) I enjoy reading and spend my life with my beautiful wife (Emy) and my three cats: Cocco, Motto and Chester

Recent Comments

None

Calendar

<<  December 2009  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar