- How can I avoid multiple asserts in this unit test?
- public class TestPoco
- {
- public string StringValue { get; set; }
- public int Int32Value { get; set; }
- public bool BoolValue { get; set; }
- }
- [Fact]
- public void TheTest()
- {
- var input = new List<TestPoco>();
- input.Add(new TestPoco { BoolValue = true, Int32Value = 1, StringValue = "foo" });
- var actual = input.ToRecordset();
- Assert.Equal(actual.BoolValue, true);
- Assert.Equal(actual.Int32Value, 1);
- Assert.Equal(actual.StringValue, "foo");
- }
- // this probably doesn't actually compile, the actual conversion method
- // doesn't exist yet and this is just to show the idea
- var expected = new ADODB.RecordsetClass();
- expected.Fields.Append("BoolValue", ADODB.DataTypeEnum.adBoolean);
- expected.Fields.Append("Int32Value", ADODB.DataTypeEnum.adInteger);
- expected.Fields.Append("StringValue", ADODB.DataTypeEnum.adVarWChar);
- expected.AddNew();
- expected.BoolValue = true;
- expected.Int32Value = 1;
- expected.StringValue = "foo";
- expected.Update();
- public class ClassWithProperities
- {
- public string Foo { get; set; }
- public int Bar { get; set; }
- }
- public static class Converter
- {
- public static ClassWithProperities Convert(string foo, int bar)
- {
- return new ClassWithProperities {Foo=foo, Bar=bar};
- }
- }
- [TestClass]
- public class PropertyTestsWhenFooIsTestAndBarIsOne
- {
- private static ClassWithProperities classWithProperties;
- [ClassInitialize]
- public static void ClassInit(TestContext testContext)
- {
- //Arrange
- string foo = "test";
- int bar = 1;
- //Act
- classWithProperties = Converter.Convert(foo, bar);
- //Assert
- }
- [TestMethod]
- public void AssertFooIsTest()
- {
- Assert.AreEqual("test", classWithProperties.Foo);
- }
- [TestMethod]
- public void AssertBarIsOne()
- {
- Assert.AreEqual(1, classWithProperties.Bar);
- }
- }
- [TestClass]
- public class PropertyTestsWhenFooIsXyzAndBarIsTwoThousand
- {
- private static ClassWithProperities classWithProperties;
- [ClassInitialize]
- public static void ClassInit(TestContext testContext)
- {
- //Arrange
- string foo = "Xyz";
- int bar = 2000;
- //Act
- classWithProperties = Converter.Convert(foo, bar);
- //Assert
- }
- [TestMethod]
- public void AssertFooIsXyz()
- {
- Assert.AreEqual("Xyz", classWithProperties.Foo);
- }
- [TestMethod]
- public void AssertBarIsTwoThousand()
- {
- Assert.AreEqual(2000, classWithProperties.Bar);
- }
- }
- public class When_converting_a_TestPoco_to_Recordset
- {
- protected static List<TestPoco> inputs;
- protected static Recordset actual;
- Establish context = () => inputs = new List<TestPoco> { new TestPoco { /* set values */ } };
- Because of = () => actual = input.ToRecordset ();
- It should_have_copied_the_bool_value = () => actual.BoolValue.ShouldBeTrue ();
- It should_have_copied_the_int_value = () => actual.Int32Value.ShouldBe (1);
- It should_have_copied_the_String_value = () => actual.StringValue.ShouldBe ("foo");
- }
- Assert.That (actual.BoolValue == true && actual.Int32Value == 1 && actual.StringValue == "foo");