Esempio n. 1
0
        public static Foo Create() => Create("A");   // shortcut for tests where all properties are irrelevant

        public static Foo Create(string property1, int?optionalProperty2 = null, IEnumerable <Bar> bars = null)
        {
            bars ??= new[] { TestBar.Create() };
            return(new Foo
            {
                Property1 = property1,
                Property2 = optionalProperty2 ?? 1, // default value can be defined here or as const
                Property3 = Property3Default,       // not relevant in tests (yet)
                Bars = bars.ToList()
            });
        }
        // using test helper
        public void CreateFoo_WithAllPropertiesAndOneBar()
        {
            // Arrange
            var bar = TestBar.Create("Bar");

            // Act
            var testee = TestFoo.Create("Property1", 123, new[] { bar });

            testee.Property3 = 345.67; // let's say this is the only test where Property3 is relevant. don't introduce any test helper param for this!

            // Assert
            testee.Bars.Should().ContainSingle().Which.Property1.Should().Be("Bar");
            testee.Property1.Should().Be("Property1");
            testee.Property2.Should().Be(123);
            testee.Property3.Should().Be(345.67);
        }