public void TestMLAgentsSettingsProviderCreateAsset() { var mockProvider = new MockSettingsProvider(); mockProvider.CreateMLAgentsSettingsProvider(); Assert.AreNotEqual(null, mockProvider.Instance); // mimic MLAgentsSettingsProvider.OnActivate() MLAgentsSettingsManager.OnSettingsChange += mockProvider.Reinitialize; mockProvider.Instance.InitializeWithCurrentSettings(); Assert.AreEqual(0, mockProvider.FindSettingsInProject().Length); var tempSettingsAssetPath1 = tempSettingsRootPath + "/test.mlagents.settings.asset"; mockProvider.CreateNewSettingsAsset(tempSettingsAssetPath1); Assert.AreEqual(1, mockProvider.FindSettingsInProject().Length); Assert.AreEqual(5004, mockProvider.Settings.EditorPort); MLAgentsSettingsManager.Settings.EditorPort = 6000; // change to something not default // callback should update the field in provider Assert.AreEqual(6000, mockProvider.Settings.EditorPort); var tempSettingsAssetPath2 = tempSettingsRootPath + "/test2.mlagents.settings.asset"; mockProvider.CreateNewSettingsAsset(tempSettingsAssetPath2); Assert.AreEqual(2, mockProvider.FindSettingsInProject().Length); // manager should set to the new (default) one, not the previous modified one Assert.AreEqual(5004, MLAgentsSettingsManager.Settings.EditorPort); // mimic MLAgentsSettingsProvider.OnDeactivate() MLAgentsSettingsManager.OnSettingsChange -= mockProvider.Reinitialize; mockProvider.Instance.Dispose(); }
public void TestMLAgentsSettingsProviderLoadAsset() { var mockProvider = new MockSettingsProvider(); var tempSettingsAssetPath1 = tempSettingsRootPath + "/test.mlagents.settings.asset"; mockProvider.CreateNewSettingsAsset(tempSettingsAssetPath1); MLAgentsSettingsManager.Settings.EditorPort = 8000; // change to something not default mockProvider.Instance?.Dispose(); MLAgentsSettingsManager.Destroy(); mockProvider.CreateMLAgentsSettingsProvider(); Assert.AreEqual(8000, MLAgentsSettingsManager.Settings.EditorPort); }