public void ValueTest() { var shared = new SharedProps(); shared.AddOrUpdate("Foo", "Bar"); Assert.Single(shared.Value); Assert.Equal("Bar", shared.GetValue("Foo")); shared.AddOrUpdate("Foo", "Bar"); Assert.Single(shared.Value); Assert.Equal("Bar", shared.GetValue("Foo")); shared.AddOrUpdate("Foo", "Bar1"); Assert.Single(shared.Value); Assert.Equal("Bar1", shared.GetValue("Foo")); shared.AddOrUpdate("Foo", () => "Bar"); Assert.Single(shared.Value); Assert.Equal("Bar", shared.GetValue("Foo")); shared.AddOrUpdate("Foo1", () => "Bar1"); Assert.Equal(2, shared.Value.Count); Assert.Equal("Bar", shared.GetValue("Foo")); Assert.Equal("Bar1", shared.GetValue("Foo1")); }
public void ValueIsDictionaryAndEmpty() { var shared = new SharedProps(); Assert.IsType <Dictionary <string, object> >(shared.Value); Assert.Empty(shared.Value); }
public override void UpdateListenedFriends() { Collider[] cols = Physics.OverlapSphere(GameObject.transform.position, ListenMessageRadius, FriendMask); foreach (Collider col in cols) { if (col.gameObject == GameObject) { continue; } SharedProps sp = col.GetComponent <SharedProps>(); if (sp && sp.memory != null) { if (Vector3.Distance(GameObject.transform.position, sp.transform.position) < ListenMessageRadius && sp.GetComponent <Health>() && sp.GetComponent <Health>().health > 0) { // Listen sp.memory.onMessageSendToListeners -= OnMessageReceived; sp.memory.onMessageSendToListeners += OnMessageReceived; if (!Friends.Contains(sp.memory)) { Friends.Add(sp.memory); } } else { // Don't Listen if (Friends.Contains(sp.memory)) { Friends.Find(x => x == sp.memory).onMessageSendToListeners -= OnMessageReceived; Friends.Remove(sp.memory); } sp.memory.onMessageSendToListeners -= OnMessageReceived; } } } }
public void CanAddOrUpdateDelegateAndObjectWithTheSameKey() { var shared = new SharedProps(); const string Key = "Foo"; shared.AddOrUpdate(Key, "Foo"); shared.AddOrUpdate(Key, () => "Bar"); Assert.Equal("Bar", shared.GetValue(Key)); }
public void CanAddStringWithDelegateAndGetValue() { const string Key1 = "Foo1"; const string Key2 = "Foo2"; Func <object> value1 = () => "Bar1"; Func <object> value2 = () => "Bar2"; var shared = new SharedProps(); shared.AddOrUpdate(Key1, value1); shared.AddOrUpdate(Key2, value2); Assert.Equal(2, shared.Value.Count); Assert.Equal(value1(), shared.GetValue(Key1)); Assert.Equal(value2(), shared.GetValue(Key2)); }
public void CanAddStringWithObjectAndGetValue() { const string Key1 = "Foo1"; const string Key2 = "Foo2"; object value1 = "Bar1"; object value2 = "Bar2"; var shared = new SharedProps(); shared.AddOrUpdate(Key1, value1); shared.AddOrUpdate(Key2, value2); Assert.Equal(2, shared.Value.Count); Assert.Equal(value1, shared.GetValue(Key1)); Assert.Equal(value2, shared.GetValue(Key2)); }
public void KeyDoesNotExistException() { var shared = new SharedProps(); Assert.Throws <KeyDoesNotExistException>(() => shared.GetValue("Key")); }