Пример #1
0
        public void DoesNotContainNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse(lookup.Contains(null));
        }
Пример #2
0
        public void AddMultipleNull()
        {
            var values = new [] { "Foo", "Foobar" };
            var lookup = new MutableLookup<string, string>();
            lookup.Add (null, values);
            Assert.AreEqual (1, lookup.Count);
            Assert.IsTrue (values.SequenceEqual (lookup[null]), "S");

            Assert.Throws<ArgumentNullException> (() => lookup.Add ("foo", (IEnumerable<string>)null));
        }
Пример #3
0
 public void AddNull()
 {
     var lookup = new MutableLookup<string, string>();
     lookup.Add (null, "Foo");
     Assert.AreEqual (1, lookup.Count);
     Assert.AreEqual (1, lookup[null].Count());
     lookup.Add (null, null);
     Assert.AreEqual (1, lookup.Count);
     Assert.AreEqual (2, lookup[null].Count());
 }
Пример #4
0
 public void Add()
 {
     var lookup = new MutableLookup<string, string>();
     lookup.Add ("F", "Foo");
     Assert.AreEqual (1, lookup.Count);
     Assert.AreEqual ("Foo", lookup["F"].First());
     lookup.Add ("F", "Foobar");
     Assert.AreEqual (1, lookup.Count);
     Assert.AreEqual (2, lookup["F"].Count());
 }
Пример #5
0
        public void AddMultipleNull()
        {
            var values = new [] { "Foo", "Foobar" };
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, values);
            Assert.AreEqual(1, lookup.Count);
            Assert.IsTrue(values.SequenceEqual(lookup[null]), "S");

            Assert.Throws <ArgumentNullException> (() => lookup.Add("foo", (IEnumerable <string>)null));
        }
Пример #6
0
        public void Add()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add("F", "Foo");
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual("Foo", lookup["F"].First());
            lookup.Add("F", "Foobar");
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(2, lookup["F"].Count());
        }
Пример #7
0
        public void AddNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "Foo");
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(1, lookup[null].Count());
            lookup.Add(null, (string)null);
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(2, lookup[null].Count());
        }
Пример #8
0
        public void DoesNotContain()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse(lookup.Contains("D"));
        }
Пример #9
0
        public void ContainsNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsTrue(lookup.Contains(null));
        }
Пример #10
0
        public void IndexerNotFound()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.AreEqual(0, lookup["D"].Count());
        }
Пример #11
0
 public void AddMultiple()
 {
     var values = new [] { "Foo", "Foobar" };
     var lookup = new MutableLookup<string, string>();
     lookup.Add ("key", values);
     Assert.AreEqual (1, lookup.Count);
     Assert.Contains (values[0], lookup["key"].ToList());
     Assert.Contains (values[1], lookup["key"].ToList());
     lookup.Add ("key2", values);
     Assert.AreEqual (2, lookup.Count);
     Assert.Contains (values[0], lookup["key2"].ToList());
     Assert.Contains (values[1], lookup["key2"].ToList());
 }
Пример #12
0
        public void ClearWithNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add("F", "Foo");

            lookup.Clear();

            Assert.AreEqual(0, lookup.Count);
            Assert.IsFalse(lookup.Contains(null));
            Assert.IsFalse(lookup.Contains("F"));
        }
Пример #13
0
        public void ClearWithoutNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            lookup.Clear();
            Assert.AreEqual(0, lookup.Count);
            Assert.IsFalse(lookup.Contains("F"));
            Assert.IsFalse(lookup.Contains("B"));
        }
Пример #14
0
        public void AddMultiple()
        {
            var values = new [] { "Foo", "Foobar" };
            var lookup = new MutableLookup <string, string>();

            lookup.Add("key", values);
            Assert.AreEqual(1, lookup.Count);
            Assert.Contains(values[0], lookup["key"].ToList());
            Assert.Contains(values[1], lookup["key"].ToList());
            lookup.Add("key2", values);
            Assert.AreEqual(2, lookup.Count);
            Assert.Contains(values[0], lookup["key2"].ToList());
            Assert.Contains(values[1], lookup["key2"].ToList());
        }
Пример #15
0
        public void CountRefType()
        {
            var lookup = new MutableLookup <string, string>();

            Assert.AreEqual(0, lookup.Count);
            lookup.Add(null, "blah");
            Assert.AreEqual(1, lookup.Count);
            lookup.Add("F", "Foo");
            Assert.AreEqual(2, lookup.Count);
            lookup.Add("F", "Foobar");
            Assert.AreEqual(2, lookup.Count);

            lookup.Remove(null, "blah");
            Assert.AreEqual(1, lookup.Count);
        }
Пример #16
0
        public void EnumeratorNull()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.AreEqual(3, lookup.Count());
            Assert.IsTrue(lookup.Any(g => g.Key == null));
            Assert.IsTrue(lookup.Any(g => g.Key == "F"));
            Assert.IsTrue(lookup.Any(g => g.Key == "B"));
        }
Пример #17
0
        public void CountValueType()
        {
            var lookup = new MutableLookup <int, int>();

            Assert.AreEqual(0, lookup.Count);
            lookup.Add(1, 10);
            Assert.AreEqual(1, lookup.Count);
            lookup.Add(2, 20);
            Assert.AreEqual(2, lookup.Count);
            lookup.Add(2, 21);
            Assert.AreEqual(2, lookup.Count);

            lookup.Remove(1, 10);
            Assert.AreEqual(1, lookup.Count);
        }
Пример #18
0
        private void SetupNotifications()
        {
            if (this.notifications != null)
            {
                this.notifications.Close();
                this.notifications = null;
            }

            this.notifications = new NotificationHandler(this.gablarski);

            var enabledSpeech = new MutableLookup <ITextToSpeech, NotificationType>();

            foreach (var enabled in Settings.EnabledNotifications)
            {
                Type type = Type.GetType(enabled.Key);
                if (type == null)
                {
                    LogManager.GetLogger("Notifications").WarnFormat("Notifier {0} not found", enabled.Key);
                    continue;
                }

                object n = Activator.CreateInstance(type);

                var notifier = n as INotifier;
                if (notifier != null)
                {
                    this.notifications.AddNotifier(notifier, enabled);
                }
                else if (n is ITextToSpeech)
                {
                    enabledSpeech.Add((ITextToSpeech)n, enabled);
                }
            }

            if (enabledSpeech.Count > 0)
            {
                foreach (var enabled in enabledSpeech)
                {
                    ITextToSpeech tts = enabled.Key;
                    tts.Media = this.mediaPlayerIntegration;

                    var format = tts.SupportedFormats.OrderByDescending(af => af.SampleRate).FirstOrDefault();
                    if (format == null)
                    {
                        format = new AudioFormat(WaveFormatEncoding.LPCM, 1, 16, 44100);
                    }

                    var source = this.gablarski.Sources.CreateFake("speech", format, (short)(format.SampleRate / 100));
                    this.speechSources.Add(tts, source);
                    tts.AudioSource = source;
                    this.gablarski.Audio.Attach(this.audioPlayback, source, new AudioEnginePlaybackOptions());

                    this.notifications.AddNotifier(tts, enabled);
                }

                this.notifications.SpeechReceiver = this.gablarski.Sources;
            }

            this.notifications.MediaController = this.mediaPlayerIntegration;
        }
Пример #19
0
        public void RemoveNonExisting()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse(lookup.Remove("D"));
            Assert.AreEqual(3, lookup.Count);

            Assert.IsFalse(lookup.Remove("F", "asdf"));
            Assert.AreEqual(3, lookup.Count);

            lookup.Remove(null);
            Assert.IsFalse(lookup.Remove(null));
            Assert.AreEqual(2, lookup.Count);
        }
Пример #20
0
 public override bool Autoload(ref string name, ref string texture)
 {
     if (Plants == null)
     {
         Plants = new MutableLookup <int, PlantTile>();
     }
     foreach (var tileType in GrowthTiles)
     {
         Plants.Add(tileType, this);
     }
     return(base.Autoload(ref name, ref texture));
 }
Пример #21
0
        public void UpdateSettings()
        {
            Settings.EnableNotifications = NotificationsEnabled;

            var notifications = new MutableLookup <string, NotificationType>();

            foreach (var notifier in Notifiers.Where(vm => vm.IsEnabled))
            {
                string name = notifier.Notifier.GetType().GetSimpleName();
                notifications.Add(name, this.globalNotifications[name].Where(vm => vm.IsEnabled).Select(vm => vm.Type));
            }

            Settings.EnabledNotifications = notifications;
        }
Пример #22
0
        public void Test()
        {
            MutableLookup <string, int> lookup = new MutableLookup <string, int>();

            lookup.Add("A", 001);
            lookup.Add("A", 002);
            lookup.Add("A", 003);
            lookup.Add("B", 004);
            lookup.Add("B", 005);
            lookup.Add("A", 006);
            lookup.Add("C", 007);
            lookup.Add("C", 008);
            lookup.Add(null, 008);

            List <int> list = lookup["A"].ToList();

            Assert.AreEqual(4, list.Count);
            Assert.AreEqual(1, list[0]);
            Assert.AreEqual(2, list[1]);
            Assert.AreEqual(3, list[2]);
            Assert.AreEqual(6, list[3]);
        }
Пример #23
0
        public MutableLookup <string, string> GetTestLookup()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, (string)null);
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            return(lookup);
        }
Пример #24
0
        public void ClearValueType()
        {
            var lookup = new MutableLookup<int, int>();
            lookup.Add (1, 10);
            lookup.Add (1, 12);
            lookup.Add (1, 13);
            lookup.Add (2, 21);
            lookup.Add (2, 22);
            lookup.Add (2, 23);

            lookup.Clear();
            Assert.AreEqual (0, lookup.Count);
            Assert.IsFalse (lookup.Contains (1));
            Assert.IsFalse (lookup.Contains (2));
        }
Пример #25
0
        public void NullGroupingEnumerator()
        {
            var lookup = new MutableLookup <string, string>();

            lookup.Add(null, null);
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.AreEqual(3, lookup[null].Count());
            Assert.IsTrue(lookup[null].Any(s => s == "blah"));
            Assert.IsTrue(lookup[null].Any(s => s == "monkeys"));
            Assert.IsTrue(lookup[null].Any(s => s == null));
        }
Пример #26
0
        public void ClearValueType()
        {
            var lookup = new MutableLookup <int, int>();

            lookup.Add(1, 10);
            lookup.Add(1, 12);
            lookup.Add(1, 13);
            lookup.Add(2, 21);
            lookup.Add(2, 22);
            lookup.Add(2, 23);

            lookup.Clear();
            Assert.AreEqual(0, lookup.Count);
            Assert.IsFalse(lookup.Contains(1));
            Assert.IsFalse(lookup.Contains(2));
        }
Пример #27
0
        public void RemoveNonExisting()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse (lookup.Remove ("D"));
            Assert.AreEqual(3, lookup.Count);

            Assert.IsFalse (lookup.Remove ("F", "asdf"));
            Assert.AreEqual(3, lookup.Count);

            lookup.Remove (null);
            Assert.IsFalse (lookup.Remove (null));
            Assert.AreEqual (2, lookup.Count);
        }
Пример #28
0
        public void ContainsNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsTrue (lookup.Contains (null));
        }
Пример #29
0
        public void EnumeratorNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add (null, "blah");
            lookup.Add (null, "monkeys");
            lookup.Add ("F", "Foo");
            lookup.Add ("F", "Foobar");
            lookup.Add ("B", "Bar");

            Assert.AreEqual (3, lookup.Count());
            Assert.IsTrue (lookup.Any (g => g.Key == null));
            Assert.IsTrue (lookup.Any (g => g.Key == "F"));
            Assert.IsTrue (lookup.Any (g => g.Key == "B"));
        }
Пример #30
0
        public void IndexerNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.AreEqual (2, lookup[null].Count());
        }
Пример #31
0
        public void NullGroupingEnumerator()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add (null, null);
            lookup.Add (null, "blah");
            lookup.Add (null, "monkeys");
            lookup.Add ("F", "Foo");
            lookup.Add ("F", "Foobar");
            lookup.Add ("B", "Bar");

            Assert.AreEqual (3, lookup[null].Count());
            Assert.IsTrue (lookup[null].Any (s => s == "blah"));
            Assert.IsTrue (lookup[null].Any (s => s == "monkeys"));
            Assert.IsTrue (lookup[null].Any (s => s == null));
        }
Пример #32
0
        public void ClearWithoutNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            lookup.Clear();
            Assert.AreEqual (0, lookup.Count);
            Assert.IsFalse (lookup.Contains ("F"));
            Assert.IsFalse (lookup.Contains ("B"));
        }
Пример #33
0
        public void ClearWithNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add (null, "blah");
            lookup.Add ("F", "Foo");

            lookup.Clear();

            Assert.AreEqual (0, lookup.Count);
            Assert.IsFalse (lookup.Contains (null));
            Assert.IsFalse (lookup.Contains ("F"));
        }
Пример #34
0
        public void CountRefType()
        {
            var lookup = new MutableLookup<string, string>();
            Assert.AreEqual (0, lookup.Count);
            lookup.Add (null, "blah");
            Assert.AreEqual (1, lookup.Count);
            lookup.Add ("F", "Foo");
            Assert.AreEqual (2, lookup.Count);
            lookup.Add ("F", "Foobar");
            Assert.AreEqual (2, lookup.Count);

            lookup.Remove (null, "blah");
            Assert.AreEqual (1, lookup.Count);
        }
Пример #35
0
        public void CountValueType()
        {
            var lookup = new MutableLookup<int, int>();
            Assert.AreEqual (0, lookup.Count);
            lookup.Add (1, 10);
            Assert.AreEqual (1, lookup.Count);
            lookup.Add (2, 20);
            Assert.AreEqual (2, lookup.Count);
            lookup.Add (2, 21);
            Assert.AreEqual (2, lookup.Count);

            lookup.Remove (1, 10);
            Assert.AreEqual(1, lookup.Count);
        }
Пример #36
0
		private void SetupNotifications ()
		{
			if (this.notifications != null)
			{
				this.notifications.Close();
				this.notifications = null;
			}

			this.notifications = new NotificationHandler (this.gablarski);

			var enabledSpeech = new MutableLookup<ITextToSpeech, NotificationType>();
			foreach (var enabled in Settings.EnabledNotifications) {
				Type type = Type.GetType (enabled.Key);
				if (type == null) {
					LogManager.GetLogger ("Notifications").WarnFormat ("Notifier {0} not found", enabled.Key);
					continue;
				}

				object n = Activator.CreateInstance (type);

				var notifier = n as INotifier;
				if (notifier != null)
					this.notifications.AddNotifier (notifier, enabled);
				else if (n is ITextToSpeech)
					enabledSpeech.Add ((ITextToSpeech) n, enabled);
			}

			if (enabledSpeech.Count > 0) {
				foreach (var enabled in enabledSpeech) {
					ITextToSpeech tts = enabled.Key;
					tts.Media = this.mediaPlayerIntegration;

					var format = tts.SupportedFormats.OrderByDescending (af => af.SampleRate).FirstOrDefault();
					if (format == null)
						format = new AudioFormat (WaveFormatEncoding.LPCM, 1, 16, 44100);

					var source = this.gablarski.Sources.CreateFake ("speech", format, (short)(format.SampleRate / 100));
					this.speechSources.Add (tts, source);
					tts.AudioSource = source;
					this.gablarski.Audio.Attach (this.audioPlayback, source, new AudioEnginePlaybackOptions());

					this.notifications.AddNotifier (tts, enabled);
				}
				
				this.notifications.SpeechReceiver = this.gablarski.Sources;
			}

			this.notifications.MediaController = this.mediaPlayerIntegration;
		}
Пример #37
0
        public void DoesNotContain()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add(null, "blah");
            lookup.Add(null, "monkeys");
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse (lookup.Contains ("D"));
        }
Пример #38
0
        public void DoesNotContainNull()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add("F", "Foo");
            lookup.Add("F", "Foobar");
            lookup.Add("B", "Bar");

            Assert.IsFalse (lookup.Contains (null));
        }
Пример #39
0
        internal MutableLookup<string, string> GetTestLookup()
        {
            var lookup = new MutableLookup<string, string>();
            lookup.Add (null, (string)null);
            lookup.Add (null, "blah");
            lookup.Add (null, "monkeys");
            lookup.Add ("F", "Foo");
            lookup.Add ("F", "Foobar");
            lookup.Add ("B", "Bar");

            return lookup;
        }
        public void UpdateSettings()
        {
            Settings.EnableNotifications = NotificationsEnabled;

            var notifications = new MutableLookup<string, NotificationType>();
            foreach (var notifier in Notifiers.Where (vm => vm.IsEnabled))
            {
                string name = notifier.Notifier.GetType().GetSimpleName();
                notifications.Add (name, this.globalNotifications[name].Where (vm => vm.IsEnabled).Select (vm => vm.Type));
            }

            Settings.EnabledNotifications = notifications;
        }