示例#1
0
        public async Task ExampleUsage1()
        {
            // First the test produces a state myState1:
            MyClass1 myState1 = new MyClass1()
            {
                myName     = "abc",
                myChildren = new MyClass1[] {
                    new MyClass1()
                    {
                        myName = "def"
                    }
                }
            };

            // The regression test wants to ensure that this state does never change
            // Assertions ensure the correctness of the tested component
            Assert.NotNull(myState1.myName);

            // In addition the state can be persisted to detect any changes caused e.g. by future refactorings
            // To create such a persisted snapshot the PersistedRegression class can be used as follows:

            // The passed myState will be compared to the persisted regression entry stored on disk:
            await new PersistedRegression().AssertEqualToPersisted("PersistedRegressionTests_ExampleUsage1_1", myState1);
            // If the myState1 ever differs from how it was the first time the test was executed this will fail
            // This way changes have to be manually approved by the developer

            // The same regression test can also be triggered through the AssertV2 helper:
            AssertV2.IsEqualToPersisted("PersistedRegressionTests_ExampleUsage1_1", myState1);
        }