public void TestInitialiseWithoutCustomClassPresent() { ContentNode contentNode = new ContentNode(); ESTrainingAtom atom = buildDefaultAtom(); ESAtomPhysicsInterface physics = contentNode.LocatePhysics(atom); Assert.AreEqual("EyeSkills.ESTrainingDefaultPhysics", physics.GetType().ToString()); //https://www.devjoy.com/blog/unit-testing-events-and-callbacks-in-csharp/ ESTrainingDefaultPhysics physicsConcrete = physics as ESTrainingDefaultPhysics; //physics.Initialise(atom); //Now we overwrite the initialised settings with mocks physics.Atom = atom; //We skip initialisation because it has GameObject dependencies. //Specify a different audio manager so that the ESTrainingAtom can re-route audio to our mock AudioManagerMock audioMock = new AudioManagerMock(); physicsConcrete.audioManager = audioMock; //SubTitlesVisualiserMock visMock = new SubTitlesVisualiserMock(); //physicsConcrete.subsVisualiser = visMock; //VoiceVisualiserMock subsMock = new VoiceVisualiserMock(); //physicsConcrete.voiceVisualiser = subsMock; callbackCompleted = false; physics.Start(TestCallback); Assert.True(callbackCompleted); Assert.AreEqual(audioMock.providedKey, atom.audioFile); //We don't actually initialise these anymore //Assert.True(visMock.called); //Assert.True(subsMock.called); }
/// <summary> /// Spins the atom. Asks the user whether to carry on if they wish, or start from the first atom of this day. /// /// </summary> /// <param name="atom">Atom.</param> public void Play(ESTrainingAtom atom) { //TODO: If the atom isn't the very first, we should ask if the user wishes to start from the first atom, or continue from where they are physics = LocatePhysics(atom); //We start the atom, passing it our callback hook so we know when to load the next one physics.Initialise(atom, PostInit); }
public void TestInitialiseWithCustomClassPresent() { ContentNode contentNode = new ContentNode(); ESTrainingAtom atom = buildCustomAtom(); ESAtomPhysicsInterface physics = contentNode.LocatePhysics(atom); physics.Initialise(atom, delegate(bool success){ Assert.True(success); }); //Now we overwrite the initialised settings with mocks Assert.NotNull(physics); Assert.AreEqual("EyeSkills.ESAtomPhysicsTESTINGPHYSICS", physics.GetType().ToString()); }
/// <summary> /// Look for any custom physics matching the paragraph - we might want a physics type rather than id matching /// </summary> /// <returns>The physics.</returns> /// <param name="atom">Atom.</param> public ESAtomPhysicsInterface LocatePhysics(ESTrainingAtom atom) { Type t; try { //Look for custom physics... string classname = "EyeSkills.ESAtomPhysics" + atom.preferredPhysics; t = Type.GetType(classname, true); physics = (ESAtomPhysicsInterface)Activator.CreateInstance(t); } catch (TypeLoadException) { //This is expected behaviour if (atom.preferredPhysics != "") { Debug.Log("Could not load physics [" + atom.preferredPhysics + "]"); } Debug.Log("Loading default physics"); physics = new ESTrainingDefaultPhysics(); } return(physics); }