public void RegisterScriptVariableOverwrite() { this.RegisterScriptVariableInManager("scriptVariable"); IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); Assert.AreSame(scriptVariable, this.scriptsManager.GetScriptVariable(scriptVariable.Id)); }
public void UnregisterScriptVariable() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); this.scriptsManager.UnregisterScriptVariable(scriptVariable.Id); Assert.Throws <KeyNotFoundException>(() => this.scriptsManager.GetScriptVariable(scriptVariable.Id)); }
public void FormatStringNoVariables() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); string stringToFormat = "123%scriptVariable%456"; Assert.AreEqual(stringToFormat, this.scriptsManager.FormatString(stringToFormat)); }
public void RegisterScriptVariable() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); CollectionAssert.Contains(this.scriptsManager.GetListOfScriptVariables(), scriptVariable, "Contains"); Assert.AreSame(scriptVariable, this.scriptsManager.GetScriptVariable(scriptVariable.Id), "Equality"); Assert.AreSame(this.scriptsManager, scriptVariable.ScriptsManager, "ScriptsManager"); }
protected virtual IScriptVariable RegisterScriptVariableInManager(string id) { IScriptVariable scriptVariable = Substitute.For <IScriptVariable>(); scriptVariable.Id.Returns(id); this.scriptsManager.RegisterScriptVariable(scriptVariable); return(scriptVariable); }
public void GetCachedVariableResult() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); DynValue expected = DynValue.NewString("Ho ho ho!!"); scriptVariable.CachedVariable.Returns(expected); this.scriptsManager.UseMumbleLinkFile(new Gw2MumbleLinkFile()); // Include more possible ids we need to skip Assert.AreEqual(expected, this.scriptsManager.GetCachedResult(scriptVariable.Id)); }
public void NotifySubscribersToUpdateFromMumbleLink() { MumbleLinkFile mumbleLinkFile = new MumbleLinkFile(); this.scriptsManager.UseMumbleLinkFile(mumbleLinkFile); IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); scriptVariable.Hooks.Returns(new HashSet <string>() { "UIVersion" }); mumbleLinkFile.UIVersion = 10; scriptVariable.Received(1).UpdateCachedVariable(); }
public void GetCachedVariableResult_RunFirstUpdateNoChange() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); scriptVariable.HasCachedVariable.Returns(false); scriptVariable.UpdateCachedVariable().Returns(false); IScriptVariable scriptVariableHooked = this.RegisterScriptVariableInManager("scriptVariableHooked"); scriptVariableHooked.Hooks.Returns(new HashSet <string>() { "scriptVariable" }); this.scriptsManager.GetCachedResult(scriptVariable.Id); scriptVariable.Received(1).UpdateCachedVariable(); scriptVariableHooked.Received(0).UpdateCachedVariable(); }
public void CachedVariableChangedNotifySubscribersToUpdate_ScriptFormatter() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); scriptVariable.Hooks.Returns(new HashSet <string>() { "%scriptFormatterHook%" }); IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter"); scriptFormatter.Hooks.Returns(new HashSet <string>() { "%scriptFormatterHook%" }); IScriptFormatter scriptFormatterHook = this.RegisterScriptFormatterInManager("scriptFormatterHook"); scriptFormatterHook.CachedVariableChanged += Raise.Event <EventHandler <CachedVariableChangedEventArgs> >( scriptFormatterHook, new CachedVariableChangedEventArgs(1, 2)); scriptVariable.Received(0).UpdateCachedVariable(); // Variable does not have access to the cached variable of a formatter scriptFormatter.Received(1).UpdateCachedVariable(); }
public void NotifySubscribersToUpdate_ScriptFormatter() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); scriptVariable.Hooks.Returns(new HashSet <string>() { "%scriptFormatterHook%" }); IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter"); scriptFormatter.Hooks.Returns(new HashSet <string>() { "%scriptFormatterHook%" }); IScriptFormatter scriptFormatterHook = Substitute.For <IScriptFormatter>(); scriptFormatterHook.Id.Returns("scriptFormatterHook"); this.scriptsManager.NotifySubscribersToUpdate(scriptFormatterHook); scriptVariable.Received(0).UpdateCachedVariable(); // Variable does not have access to the cached variable of a formatter scriptFormatter.Received(1).UpdateCachedVariable(); }
public void NotifySubscribersToUpdate_ScriptVariable() { IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable"); scriptVariable.Hooks.Returns(new HashSet <string>() { "scriptVariableHook" }); IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter"); scriptFormatter.Hooks.Returns(new HashSet <string>() { "scriptVariableHook" }); IScriptVariable scriptVariableHook = Substitute.For <IScriptVariable>(); scriptVariableHook.Id.Returns("scriptVariableHook"); this.scriptsManager.NotifySubscribersToUpdate(scriptVariableHook); scriptVariable.Received(1).UpdateCachedVariable(); scriptFormatter.Received(1).UpdateCachedVariable(); }
public virtual object GetCachedResult(string id) { if (!id.StartsWith("%") || !id.EndsWith("%")) { switch (id) { case "UIVersion": return(this.MumbleLinkFile.UIVersion); case "UITick": return(this.MumbleLinkFile.UITick); case "Name": return(this.MumbleLinkFile.Name); case "AvatarPosition": return(this.MumbleLinkFile.AvatarPosition.ToDictionary()); case "AvatarFront": return(this.MumbleLinkFile.AvatarFront.ToDictionary()); case "AvatarTop": return(this.MumbleLinkFile.AvatarTop.ToDictionary()); case "CameraPosition": return(this.MumbleLinkFile.CameraPosition.ToDictionary()); case "CameraFront": return(this.MumbleLinkFile.CameraFront.ToDictionary()); case "CameraTop": return(this.MumbleLinkFile.CameraTop.ToDictionary()); case "Description": return(this.MumbleLinkFile.Description); } if (this.MumbleLinkFile is Gw2MumbleLinkFile) { Gw2MumbleLinkFile gw2MumbleLinkFile = (Gw2MumbleLinkFile)this.MumbleLinkFile; switch (id) { case "CharacterName": return(gw2MumbleLinkFile.CharacterName); case "ProfessionId": return(gw2MumbleLinkFile.ProfessionId); case "MapId": return(gw2MumbleLinkFile.MapId); case "WorldId": return(gw2MumbleLinkFile.WorldId); case "TeamColorId": return(gw2MumbleLinkFile.TeamColorId); case "IsCommander": return(gw2MumbleLinkFile.IsCommander); case "ServerAddress": return(gw2MumbleLinkFile.ServerAddress.GetAddressBytes()); case "MapType": return(gw2MumbleLinkFile.MapType); case "ShardId": return(gw2MumbleLinkFile.ShardId); case "Instance": return(gw2MumbleLinkFile.Instance); case "BuildId": return(gw2MumbleLinkFile.BuildId); } } if (this.scriptVariables.ContainsKey(id)) { IScriptVariable script = this.scriptVariables[id]; if (!script.HasCachedVariable) { script.UpdateCachedVariable(); } return(script.CachedVariable); } } else { id = id.Substring(1, id.Length - 2); if (this.scriptFormatters.ContainsKey(id)) { IScriptFormatter script = this.scriptFormatters[id]; if (!script.HasCachedVariable) { script.UpdateCachedVariable(); } return(script.CachedVariable); } } return(null); }
public virtual void RegisterScriptVariable(IScriptVariable scriptVariable) { this.scriptVariables[scriptVariable.Id] = scriptVariable; scriptVariable.ScriptsManager = this; scriptVariable.CachedVariableChanged += scriptVariable_CachedVariableChanged; }
public virtual void NotifySubscribersToUpdate(IScriptVariable sourceScript) { this.NotifyVariableSubscribersToUpdate(sourceScript.Id); this.NotifyFormatterSubscribersToUpdate(sourceScript.Id); }