public IEnumerator OutOfGameTime_UpdatesOnReload( [ValueSource(nameof(RealSeconds))] double secondsOutOfGame ) { FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_UpdatesOnReload)); //Go to the next frame and then save (to make sure we "discard" the time spent creating the save file) yield return(null); fortuneFountainSaveData.Save(false); //record the time we saved at var saveTime = FrameTime.Now; var outOfGameTime = TimeSpan.FromSeconds(secondsOutOfGame); yield return(TestUtils.WaitFor(outOfGameTime)); fortuneFountainSaveData.Reload(); //record the time we loaded at var loadTime = FrameTime.Now; //make sure that the OOG-time is the difference between loading and saving //NOTE: This value will always be slightly larger than secondsOutOfGame due to the time actually spend saving & loading, etc. Assert.That(fortuneFountainSaveData, Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(loadTime - saveTime)); }
public IEnumerator OutOfGameTime_MultipleSessionsWithoutThrowing() { const float sessionSeconds = 2f; const int numberOfSessions = 2; var sessionSpan = TimeSpan.FromSeconds(sessionSeconds); locations = Locations.None; FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nameof(OutOfGameTime_MultipleSessionsWithoutThrowing)); yield return(null); fortuneFountainSaveData.Save(false); var realTimeNowAtSave = FrameTime.Now; Assert.That(fortuneFountainSaveData, Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)).EqualTo(TimeSpan.Zero), $"We haven't waited yet, so there shouldn't be any {nameof(FortuneFountainSaveData.OutOfGameTimeSinceLastThrow)}!"); Assert.That(fortuneFountainSaveData, Has.Property(nameof(fortuneFountainSaveData.LastSaveTime)).EqualTo(realTimeNowAtSave)); var expectedOutOfGameTime = TimeSpan.Zero; for (int session = 0; session < numberOfSessions; session++) { yield return(TestUtils.WaitForRealtime(sessionSpan)); fortuneFountainSaveData.Reload(); var realTimeNowAtReload = FrameTime.Now; Assert.That(realTimeNowAtReload, Is.Not.EqualTo(realTimeNowAtSave)); var frameTimeDuration = realTimeNowAtReload - realTimeNowAtSave; expectedOutOfGameTime += frameTimeDuration; Assert.That( fortuneFountainSaveData, Has.Property(nameof(fortuneFountainSaveData.OutOfGameTimeSinceLastThrow)) .EqualTo(expectedOutOfGameTime) ); yield return(TestUtils.WaitForRealtime(sessionSpan)); fortuneFountainSaveData.Save(false); realTimeNowAtSave = FrameTime.Now; } }