Best practices for multiple asserts on same result in C#
Posted
by asdseee
on Stack Overflow
See other posts from Stack Overflow
or by asdseee
Published on 2010-01-14T09:40:12Z
Indexed on
2010/05/29
13:02 UTC
Read the original article
Hit count: 215
What do you think is cleanest way of doing multiple asserts on a result? In the past I've put them all the same test but this is starting to feel a little dirty, I've just been playing with another idea using setup.
[TestFixture]
public class GridControllerTests
{
protected readonly string RequestedViewId = "A1";
protected GridViewModel Result { get; set;}
[TestFixtureSetUp]
public void Get_UsingStaticSettings_Assign()
{
var dataRepository = new XmlRepository("test.xml");
var settingsRepository = new StaticViewSettingsRepository();
var controller = new GridController(dataRepository, settingsRepository);
this.Result = controller.Get(RequestedViewId);
}
[Test]
public void Get_UsingStaticSettings_NotNull()
{
Assert.That(this.Result,Is.Not.Null);
}
[Test]
public void Get_UsingStaticSettings_HasData()
{
Assert.That(this.Result.Data,Is.Not.Null);
Assert.That(this.Result.Data.Count,Is.GreaterThan(0));
}
[Test]
public void Get_UsingStaticSettings_IdMatches()
{
Assert.That(this.Result.State.ViewId,Is.EqualTo(RequestedViewId));
}
[Test]
public void Get_UsingStaticSettings_FirstTimePageIsOne()
{
Assert.That(this.Result.State.CurrentPage, Is.EqualTo(1));
}
}
© Stack Overflow or respective owner