2008-11-19 38 views

Respuesta

17

Ver Fluent Assertions. Puede hacer cosas como

"ABCDEFGHI".Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9); 

new[] { 1, 2, 3 }.Should().HaveCount(4, "because we thought we put three items in the 
collection")) 

dtoCollection.Should().Contain(dto => dto.Id != null); 

collection.Should().HaveCount(c => c >= 3); 

dto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer); 

dt1.Should().BeWithin(TimeSpan.FromHours(50)).Before(dt2); 

Action action =() => recipe.AddIngredient("Milk", 100, Unit.Spoon); 
action 
    .ShouldThrow<RuleViolationException>() 
    .WithMessage("Cannot change the unit of an existing ingredient") 
    .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity 
+2

¡Las gafas! ¡Ellos no hacen nada! – bzlm

0

Sobre la base de mi investigación no hay uno, pero si estás dispuesto a sacrificar la mejor reportabilidad por lo que ¿por qué no una aserción y dispuestos a añadir un nuevo archivo DLL puede hacer referencia a nunit y utilizar el suyo ....

5

Ver http://sharptestex.codeplex.com/

NOTA: SharpTestsEx parece ya no ser desarrollado activamente, alternativa recomendada es http://www.fluentassertions.com/.

SharpTestsEx (Sharp Tests Extensions) es un conjunto de extensiones extensibles. El objetivo principal es escribir afirmaciones cortas donde el Visual Studio IDE intellisense es su guía. #TestsEx se puede usar con NUnit, MsTests, xUnit, MbUnit ... incluso en Silverlight.

ejemplo de sintaxis para las aseveraciones inflexible de tipos (tomado de la página web):

true.Should().Be.True(); 
false.Should().Be.False(); 

const string something = "something"; 
something.Should().Contain("some"); 
something.Should().Not.Contain("also"); 
something.ToUpperInvariant().Should().Not.Contain("some"); 

something.Should() 
    .StartWith("so") 
    .And 
    .EndWith("ing") 
    .And 
    .Contain("meth"); 

something.Should() 
    .Not.StartWith("ing") 
    .And 
    .Not.EndWith("so") 
    .And 
    .Not.Contain("body"); 

var ints = new[] { 1, 2, 3 }; 
ints.Should().Have.SameSequenceAs(new[] { 1, 2, 3 }); 
ints.Should().Not.Have.SameSequenceAs(new[] { 3, 2, 1 }); 
ints.Should().Not.Be.Null(); 
ints.Should().Not.Be.Empty(); 

ints.Should() 
    .Contain(2) 
    .And 
    .Not.Contain(4); 

(new int[0]).Should().Be.Empty(); 
+0

Aunque creo que harrydev podría haber agregado información útil, en mi opinión, SharpTestEx parece un poco más maduro que FluentAssertions. Observación preliminar, por supuesto. Alguien puede mostrarme por qué FluentAsertions puede ser mejor. – llaughlin

+0

SharpTestEx está básicamente muerto, mientras que Fluent Assertions se está desarrollando activamente y agrega soporte para todos los principales marcos de pruebas de unidades, así como todas las versiones de .NET Framework, incluidos .NET 4.5, WinRT, Silverlight 5 y WP7/8. –