public void TestSaveLoad() { // Load saved userflow. Does it look the same? // Extract fields from userflow before saving. Userflow example1 = ExampleUserflow(); string firstName = example1.Name(); UserflowState firstState = example1.State(); long firstTimeout = example1.Timeout(); int firstValue = example1.Value(); long firstEyeTime = example1.EyeTime(); string firstBeginTime = example1.BeginTimeString(); string firstEndTime = example1.EndTimeString(); // Save followed by load. UserflowReporter.Background(); UserflowReporter.Foreground(); example1 = Userflow.UserflowForName(firstName); Assert.IsNotNull(example1, "Expecting to find example1 again"); // Extract fields from loaded userflow. string secondName = example1.Name(); UserflowState secondState = example1.State(); long secondTimeout = example1.Timeout(); int secondValue = example1.Value(); long secondEyeTime = example1.EyeTime(); string secondBeginTime = example1.BeginTimeString(); string secondEndTime = example1.EndTimeString(); // Everything is supposed to match now (within limits of persisting doubles). Assert.IsTrue(firstState == secondState, "Expecting firstState==secondState"); Assert.IsTrue(firstName == secondName, "Expecting firstName==secondName"); Assert.IsTrue(firstTimeout == secondTimeout, "Expecting firstTimeout==secondTimeout"); Assert.IsTrue(firstValue == secondValue, "Expecting firstValue==secondValue"); Assert.IsTrue(firstEyeTime == secondEyeTime, "Expecting firstEyeTime==secondEyeTime"); Assert.IsTrue(firstBeginTime == secondBeginTime, "Expecting firstBeginTime==secondBeginTime"); Assert.IsTrue(firstEndTime == secondEndTime, "Expecting firstEndTime==secondEndTime"); //UserflowReporter.Background(); Trace.WriteLine("testSaveLoad EXITING"); Trace.WriteLine(""); }
public void TestPersistence() { // Test Persistence, UserflowForName // Intially, example1 = new Userflow("Purchase Crittercism SDK", 100000); Userflow example1 = ExampleUserflow(); string firstName = example1.Name(); int firstTimeout = example1.Timeout(); int firstValue = example1.Value(); // Test userflowForName Assert.IsTrue(Userflow.UserflowForName(firstName) == example1, "Expecting Userflow.UserflowForName(firstName)==example1"); Assert.IsTrue(Userflow.UserflowForName(firstName).Name() == firstName, "Expecting Userflow.UserflowForName(firstName).Name()==firstName"); // And example2 is example1's identical twin Userflow example2 = ExampleUserflow(); Trace.WriteLine("INITIALLY EQUAL"); //JsonConvert.SerializeObject(example1) Trace.WriteLine("example1 == " + example1); Trace.WriteLine("example2 == " + example2); // Change example1 example1.SetTimeout(example1.Timeout() + 100); example1.SetValue(example1.Value() + 10000); // Confirm members of example1 have been changed. Assert.IsFalse(example1.Timeout() == firstTimeout, "Not expecting example1.Timeout()==firstTimeout"); Assert.IsFalse(example1.Value() == firstValue, "Not expecting example1.Value()==firstValue"); Trace.WriteLine("NO LONGER EQUAL"); Trace.WriteLine("example1 == " + example1); Trace.WriteLine("example2 == " + example2); // Change example1 back example1.SetTimeout(firstTimeout); example1.SetValue(firstValue); Trace.WriteLine("SHOULD BE EQUAL AGAIN"); Trace.WriteLine("example1 == " + example1); Trace.WriteLine("example2 == " + example2); // Confirm members of example1 have been restored. Assert.IsTrue(example1.Name() == firstName, "Expecting example1.Name()==firstName"); Assert.IsTrue(example1.Timeout() == firstTimeout, "Expecting example1.Timeout()==firstTimeout"); Assert.IsTrue(example1.Value() == firstValue, "Expecting example1.Value()==firstValue"); }