public void TestTimeProperties() { // Testing beginTime, endTime, eyeTime Userflow example = ExampleUserflow(); Assert.IsTrue(example.State() == UserflowState.CREATED, "Expecting UserflowState.CREATED ."); example.SetTimeout(Int32.MaxValue); { example.Begin(); Assert.IsTrue(example.State() == UserflowState.BEGUN, "Expecting UserflowState.BEGUN ."); } // Call "yield" here so CLR can operate example's timer . const int positiveTime = 100; long yieldTime; { long yieldBeginTime = DateTime.UtcNow.Ticks; Thread.Sleep(positiveTime); long yieldEndTime = DateTime.UtcNow.Ticks; yieldTime = yieldEndTime - yieldBeginTime; } { example.End(); Assert.IsTrue(example.State() == UserflowState.ENDED, "Expecting UserflowState.ENDED ."); } // All the above is mainly just to get some interesting // beginTime, endTime, eyeTime play around with. Now, // it is play time. { long beginTime = example.BeginTime(); long endTime = example.EndTime(); long eyeTime = example.EyeTime(); // Test beginTime, endTime, eyeTime wrt the actual "yieldTime" Assert.IsTrue(beginTime < endTime, "Expecting beginTime < endTime ."); // The test is run entirely in foreground, so // endTime - beginTime should be close to eyeTime // allowing a little bit of deviation due to use // of "yield". Assert.IsTrue((0.8 * yieldTime) < eyeTime, String.Format("Expecting eyeTime == {0} to be close to {1} .", eyeTime, yieldTime)); Assert.IsTrue(eyeTime < (1.2 * yieldTime), String.Format("Expecting eyeTime == {0} to be close to {1} .", eyeTime, yieldTime)); Assert.IsTrue((0.8 * yieldTime) < (endTime - beginTime), String.Format("Expecting (endTime - beginTime) == {0} to be close to {1} .", endTime - beginTime, yieldTime)); Assert.IsTrue((endTime - beginTime) < (1.2 * yieldTime), String.Format("Expecting (endTime - beginTime) == {0} to be close to {1} .", endTime - beginTime, yieldTime)); } }
public void TestBegin() { // Test "Begin"'s resulting state is correct. Userflow example = ExampleUserflow(); example.Begin(); Assert.IsTrue(example.State() == UserflowState.BEGUN, "Confirm Begin changes state to UserflowState.BEGUN"); }
public void TestStateProperty() { // Check state is correct UserflowState after // various Userflow method calls. { Userflow example1 = ExampleUserflow(); Assert.IsTrue(example1.State() == UserflowState.CREATED, "Expecting UserflowState.CREATED ."); { example1.Begin();; Assert.IsTrue(example1.State() == UserflowState.BEGUN, "Expecting UserflowState.BEGUN ."); } Thread.Sleep(100); { example1.End();; Assert.IsTrue(example1.State() == UserflowState.ENDED, "Expecting UserflowState.ENDED ."); } } { Userflow example2 = ExampleUserflow(); Assert.IsTrue(example2.State() == UserflowState.CREATED, "Expecting UserflowState.CREATED ."); { example2.Begin();; Assert.IsTrue(example2.State() == UserflowState.BEGUN, "Expecting UserflowState.BEGUN ."); } Thread.Sleep(100); { example2.Fail(); Assert.IsTrue(example2.State() == UserflowState.FAILED, "Expecting UserflowState.FAILED ."); } } { Userflow example3 = ExampleUserflow(); Assert.IsTrue(example3.State() == UserflowState.CREATED, "Expecting UserflowState.CREATED ."); const int timeout = 100; example3.SetTimeout(timeout); { example3.Begin(); Assert.IsTrue(example3.State() == UserflowState.BEGUN, "Expecting UserflowState.BEGUN ."); } // Yield here so CLR can operate example3's timer . Thread.Sleep(2 * timeout); Assert.IsTrue(example3.State() == UserflowState.TIMEOUT, "Expecting UserflowState.TIMEOUT ."); } }
public void TestFail() { // Test "Fail"'s resulting state is correct. It's required to "begin" first. Userflow example = ExampleUserflow(); example.Begin(); Assert.IsTrue(example.State() == UserflowState.BEGUN, "Confirm Begin changes state to UserflowState.BEGUN"); example.Fail(); Assert.IsTrue(example.State() == UserflowState.FAILED, "Confirm Fail changes state to UserflowState.FAILED"); }
public void TestSuccess() { // Test "End"'s resulting state is correct. It's required to "Begin" first. Userflow example = ExampleUserflow(); example.Begin(); Assert.IsTrue(example.State() == UserflowState.BEGUN, "Confirm Begin changes state to UserflowState.BEGUN"); example.End(); Assert.IsTrue(example.State() == UserflowState.ENDED, "Confirm End changes state to UserflowState.ENDED"); }
public void TestTimeoutProperty() { // Userflow should TIMEOUT if run in excess of it's timeout. Userflow example = ExampleUserflow(); Assert.IsTrue(example.State() == UserflowState.CREATED, "Expecting UserflowState.CREATED ."); const int timeout = 100; example.SetTimeout(timeout); { example.Begin(); Assert.IsTrue(example.State() == UserflowState.BEGUN, "Expecting UserflowState.BEGUN ."); } // Yield here so CLR can operate example3's timer . Thread.Sleep(2 * timeout); Assert.IsTrue(example.State() == UserflowState.TIMEOUT, "Expecting UserflowState.TIMEOUT ."); }