public void SelectMany_ObservableSourceSubSourceRemoved_Updates() { var update = false; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new ObservableCollection <Dummy <ICollection <Dummy <string> > > >(); var dummy = new Dummy <string>() { Item = "23" }; var dummy2 = new Dummy <ICollection <Dummy <string> > >() { Item = new List <Dummy <string> >() { dummy } }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual(NotifyCollectionChangedAction.Remove, e.Action); Assert.AreEqual("23", e.OldItems[0]); }; Assert.IsTrue(Sys.Contains(test, "23")); Assert.IsFalse(update); coll.Remove(dummy2); Assert.IsTrue(update); Assert.IsTrue(!test.Any()); }
public void Select_NoObservableSourceItemRemoved_KeepOrder_NoUpdate() { ObservableExtensions.KeepOrder = true; var update = false; ICollection <Dummy <string> > coll = new List <Dummy <string> >(); var dummy = new Dummy <string>() { Item = "42" }; coll.Add(dummy); var test = coll.WithUpdates().Select(d => d.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsTrue(Sys.Contains(test, "42")); Assert.IsFalse(update); coll.Remove(dummy); Assert.IsFalse(Sys.Contains(test, "42")); Assert.IsFalse(update); }
public void SelectMany_NoObservableSubSourceItemAdded_NoUpdates() { var update = false; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new List <Dummy <ICollection <Dummy <string> > > >(); var dummy = new Dummy <string>() { Item = "23" }; var dummy2 = new Dummy <ICollection <Dummy <string> > >() { Item = new List <Dummy <string> >() }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsFalse(Sys.Contains(test, "23")); Assert.IsFalse(update); dummy2.Item.Add(dummy); Assert.IsFalse(update); }
public void SelectMany_ObservableSubSourceItemAdded_Updates() { var update = 0; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new List <Dummy <ICollection <Dummy <string> > > >(); var dummy = new Dummy <string>() { Item = "23" }; var dummy2 = new Dummy <ICollection <Dummy <string> > >() { Item = new ObservableCollection <Dummy <string> >() }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => { update++; Assert.AreEqual("23", e.NewItems[0]); }; Assert.IsFalse(Sys.Contains(test, "23")); Assert.AreEqual(0, update); dummy2.Item.Add(dummy); Assert.AreEqual(1, update); Assert.IsTrue(Sys.Contains(test, "23")); }
public void Select_ObservableSourceItemAdded_Update() { var update = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var test = coll.WithUpdates().Select(d => d.Item); test.CollectionChanged += (o, e) => { Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action); Assert.IsTrue(e.NewItems.Contains("42")); Assert.AreEqual(1, e.NewItems.Count); update = true; }; Assert.IsTrue(!test.Any()); Assert.IsFalse(update); coll.Add(new Dummy <string>() { Item = "42" }); Assert.IsTrue(update); Assert.IsFalse(!test.Any()); Assert.IsTrue(Sys.Contains(test, "42")); }
public void Where_ObservableSourceItemAdded_Updates() { var update = false; ICollection <Dummy <bool> > coll = new ObservableCollection <Dummy <bool> >(); var dummy = new Dummy <bool>() { Item = true }; var test = coll.WithUpdates().Where(d => d.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action); Assert.AreEqual(dummy, e.NewItems[0]); }; Assert.IsFalse(Sys.Any(test)); Assert.IsFalse(update); coll.Add(dummy); Assert.IsTrue(update); Assert.IsTrue(Sys.Contains(test, dummy)); }
public void Where_ObservableItem_Updates() { var update = false; ICollection <Dummy <bool> > coll = new List <Dummy <bool> >(); var dummy = new ObservableDummy <bool>() { Item = true }; coll.Add(dummy); var test = coll.WithUpdates().Where(d => d.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual(dummy, e.OldItems[0]); }; Assert.IsTrue(Sys.Contains(test, dummy)); Assert.IsFalse(update); dummy.Item = false; Assert.IsFalse(test.Any()); Assert.IsTrue(update); }
public void GroupBy_ObservableKeyChangesEraseGroup_Update() { var update = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var dummy1 = new Dummy <string>("A"); var dummy2 = new ObservableDummy <string>("B"); coll.Add(dummy1); coll.Add(dummy2); var test = coll.WithUpdates().GroupBy(d => d.Item); test.CollectionChanged += (o, e) => { Assert.IsTrue(ContainsGroup(e.OldItems, "B")); update = true; }; Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy1)); Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "B"), dummy2)); Assert.IsFalse(update); dummy2.Item = "A"; Assert.IsTrue(update); Assert.AreEqual(1, test.Count()); Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy2)); }
public void GroupBy_NoObservableKeyChangesToNewGroup_NoUpdate() { var update = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var dummy1 = new Dummy <string>("A"); var dummy2 = new Dummy <string>("A"); coll.Add(dummy1); coll.Add(dummy2); var test = coll.WithUpdates().GroupBy(d => d.Item); test.CollectionChanged += (o, e) => update = true; var group = Sys.Single(test); Assert.IsTrue(Sys.Contains(group, dummy1)); Assert.IsTrue(Sys.Contains(group, dummy2)); Assert.IsFalse(update); dummy2.Item = "B"; Assert.IsFalse(update); }
public void Select_ObservableItem_Update() { var update = false; ICollection <Dummy <string> > coll = new List <Dummy <string> >(); var dummy = new ObservableDummy <string>() { Item = "23" }; coll.Add(dummy); var test = coll.WithUpdates().Select(d => d.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldItems[0]); }; Assert.IsTrue(Sys.Contains(test, "23")); Assert.IsFalse(update); dummy.Item = "42"; Assert.IsTrue(update); Assert.IsTrue(Sys.Contains(test, "42")); }
public void SelectMany_ObservableSubSourceItemChanges_Updates() { var update = false; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new List <Dummy <ICollection <Dummy <string> > > >(); var dummy = new ObservableDummy <string>() { Item = "23" }; var dummy2 = new Dummy <ICollection <Dummy <string> > >() { Item = new List <Dummy <string> >() { dummy } }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldItems[0]); Assert.AreEqual("42", e.NewItems[0]); }; Assert.IsTrue(Sys.Contains(test, "23")); Assert.IsFalse(update); dummy.Item = "42"; Assert.IsTrue(update); Assert.IsTrue(Sys.Contains(test, "42")); }
public void Select_ObservableSourceItemRemoved_Update() { var update = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var dummy = new Dummy <string>() { Item = "42" }; coll.Add(dummy); var test = coll.WithUpdates().Select(d => d.Item); test.CollectionChanged += (o, e) => { Assert.IsTrue(e.OldItems.Contains("42")); Assert.AreEqual(1, e.OldItems.Count); update = true; }; Assert.IsTrue(Sys.Contains(test, "42")); Assert.IsFalse(update); coll.Remove(dummy); Assert.IsTrue(update); Assert.IsFalse(Sys.Contains(test, "42")); }
public override Boolean Contains(Expression other) { CollectionExpression ce = other as CollectionExpression; return(ce != null && Enumerable.All(Caster.Cast <object>(_collection), delegate(Object item) { return Enumerable.Contains(Caster.Cast <object>(ce._collection), item); })); }
public void GroupBy_ObservableKeyChangesBetweenGroups_Update() { var updateGroups = false; var updateGroupA = false; var updateGroupB = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var dummy1 = new Dummy <string>("A"); var dummy2 = new Dummy <string>("B"); var dummyChange = new ObservableDummy <string>("A"); coll.Add(dummy1); coll.Add(dummy2); coll.Add(dummyChange); var test = coll.WithUpdates().GroupBy(d => d.Item); test.CollectionChanged += (o, e) => updateGroups = true; var groupA = Sys.Single(test, g => g.Key == "A") as ObservableGroup <string, Dummy <string> >; var groupB = Sys.Single(test, g => g.Key == "B") as ObservableGroup <string, Dummy <string> >; Assert.IsNotNull(groupA); Assert.IsNotNull(groupB); Assert.IsTrue(Sys.Contains(groupA, dummy1)); Assert.IsTrue(Sys.Contains(groupA, dummyChange)); Assert.IsTrue(Sys.Contains(groupB, dummy2)); Assert.IsFalse(updateGroups); var notifierA = groupA as INotifyCollectionChanged; var notifierB = groupB as INotifyCollectionChanged; Assert.IsNotNull(notifierA); Assert.IsNotNull(notifierB); notifierA.CollectionChanged += (o, e) => { Assert.IsTrue(e.OldItems.Contains(dummyChange)); updateGroupA = true; }; notifierB.CollectionChanged += (o, e) => { Assert.IsTrue(e.NewItems.Contains(dummyChange)); updateGroupB = true; }; dummyChange.Item = "B"; Assert.IsFalse(updateGroups); Assert.IsTrue(updateGroupA); Assert.IsTrue(updateGroupB); Assert.IsTrue(Sys.Contains(groupA, dummy1)); Assert.IsTrue(Sys.Contains(groupB, dummy2)); Assert.IsTrue(Sys.Contains(groupB, dummyChange)); }
public void query_sample() { var startWithM = new StartsWithQuery("M"); var endsWithN = LinqSpec.For <string>(n => n.EndsWith("n")); IEnumerable <string> result = new SampleRepository() .Retrieve(startWithM | !endsWithN); result.Satisfy(r => Enumerable.Contains(r, "Jose") && !Enumerable.Contains(r, "Julian") && Enumerable.Contains(r, "Manuel")); }
public void LoadFromExcelXLSX() { var filename = IsotopeTestCommon.Helper.GetTestMethodOutputFilename("Customers.xlsx"); var data = IsotopeTests.Properties.Resources.Customers; var fp = System.IO.File.Create(filename); fp.Write(data, 0, data.Length); fp.Close(); var dt = Isotope.Data.DataTableBuilder.FromExcelWorksheet(filename, "Sheet1", true); var colnames = Enumerable.Select <System.Data.DataColumn, string>(dt.Columns.AsEnumerable(), col => col.ColumnName); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(Enumerable.Contains(colnames, "Telephone")); }
public void SelectMany_ObservableSourceItemSubSourceChanges_NoUpdatesWhenDetached() { var update = false; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new List <Dummy <ICollection <Dummy <string> > > >(); var dummy = new Dummy <string>() { Item = "23" }; var dummy2 = new ObservableDummy <ICollection <Dummy <string> > >() { Item = new List <Dummy <string> >() { dummy } }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsTrue(Sys.Contains(test, "23")); Assert.IsFalse(update); test.Detach(); update = false; dummy2.Item = new List <Dummy <string> >() { new Dummy <string>("42") }; Assert.IsFalse(update); test.Attach(); Assert.IsTrue(update); Assert.IsTrue(test.Contains("42")); update = false; dummy2.Item = new List <Dummy <string> >() { dummy }; Assert.IsTrue(update); }
public void can_cast_expression_as_queryspec() { Expression <Func <string, bool> > startExpr = n => n.StartsWith("M"); Expression <Func <string, bool> > endExpr = n => n.EndsWith("n"); LinqSpec <string> startWithM = startExpr; LinqSpec <string> endsWithN = endExpr; IEnumerable <string> result = new SampleRepository() .Retrieve(startWithM | !endsWithN); result.Satisfy(r => Enumerable.Contains(r, "Jose") && !Enumerable.Contains(r, "Julian") && Enumerable.Contains(r, "Manuel")); }
public override Boolean Contains(Expression other) { CollectionExpression <TValue> ce = other as CollectionExpression <TValue>; if (ce == null) { return(false); } IEnumerable <TValue> collection = ce.Collection; return(Enumerable.All <TValue>(collection, delegate(TValue item) { return Enumerable.Contains <TValue>(collection, item, _comparer); })); }
public void SelectMany_ObservableSourceItemSubSourceChanges_Updates() { var update = false; ICollection <Dummy <ICollection <Dummy <string> > > > coll = new List <Dummy <ICollection <Dummy <string> > > >(); var dummy = new Dummy <string>() { Item = "23" }; var dummy2 = new ObservableDummy <ICollection <Dummy <string> > >() { Item = new List <Dummy <string> >() { dummy } }; coll.Add(dummy2); var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item); test.CollectionChanged += (o, e) => { update = true; switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: Assert.AreEqual(0, e.NewItems.Count); break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: Assert.AreEqual("23", e.OldItems[0]); break; default: Assert.Fail(); break; } }; Assert.IsTrue(Sys.Contains(test, "23")); Assert.IsFalse(update); dummy2.Item = new List <Dummy <string> >(); Assert.IsTrue(update); Assert.IsTrue(!test.Any()); }
public static int LastIndexOf <T>(this ArraySegment <T> src, T b) { if (src.Array == null) { throw new ArgumentNullException(); } if (!Enumerable.Contains(src, b)) { return(-1); } for (var i = src.Count - 1; i >= 0; i--) { if (src.Array[src.Offset + i].Equals(b)) { return(i); } } return(-1); }
/// <summary> /// Get a list of the genes that have not been taken before. This is useful /// if you do not wish the same gene to appear more than once in a /// chromosome. /// </summary> /// <param name="source">The pool of genes to select from.</param> /// <param name="taken">An array of the taken genes.</param> /// <returns>Those genes in source that are not taken.</returns> private static IGene GetNotTaken(Chromosome source, IList <IGene> taken) { int geneLength = source.Genes.Count; for (int i = 0; i < geneLength; i++) { IGene trial = source.Genes[i]; bool found = Enumerable.Contains(taken, trial); if (!found) { taken.Add(trial); return(trial); } } return(null); }
public void WhereTransaction_ObservableItem_Updates() { var oldEngine = ExecutionEngine.Current; try { ExecutionEngine.Current = new SequentialExecutionEngine(); var update = false; var dummy1 = new ObservableDummy <bool>(true); INotifyCollection <Dummy <bool> > coll = new NotifyCollection <Dummy <bool> >() { dummy1 }; var test = coll.Where(d => d.Item); test.CollectionChanged += (o, e) => { update = true; Assert.AreEqual(dummy1, e.OldItems[0]); }; Assert.IsTrue(Sys.Contains(test, dummy1)); Assert.IsFalse(update); ExecutionEngine.Current.BeginTransaction(); dummy1.Item = false; Assert.IsFalse(update); ExecutionEngine.Current.CommitTransaction(); Assert.IsFalse(test.Any()); Assert.IsTrue(update); } finally { ExecutionEngine.Current = oldEngine; } }
public void Where_ObservableSourceSuppressedAdded_NoUpdates() { var update = false; ICollection <Dummy <bool> > coll = new ObservableCollection <Dummy <bool> >(); var dummy = new Dummy <bool>() { Item = false }; var test = coll.WithUpdates().Where(d => d.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsFalse(Sys.Contains(test, dummy)); Assert.IsFalse(update); coll.Add(dummy); Assert.IsFalse(update); Assert.IsFalse(test.Any()); }
public void GroupBy_NoObservableKeyChangesEraseGroup_NoUpdate() { var update = false; ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >(); var dummy1 = new Dummy <string>("A"); var dummy2 = new Dummy <string>("B"); coll.Add(dummy1); coll.Add(dummy2); var test = coll.WithUpdates().GroupBy(d => d.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "A"), dummy1)); Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "B"), dummy2)); Assert.IsFalse(update); dummy2.Item = "A"; Assert.IsFalse(update); }
public void Where_NoObservableItem_NoUpdates() { var update = false; ICollection <Dummy <bool> > coll = new List <Dummy <bool> >(); var dummy = new Dummy <bool>() { Item = true }; coll.Add(dummy); var test = coll.WithUpdates().Where(d => d.Item); test.CollectionChanged += (o, e) => update = true; Assert.IsTrue(Sys.Contains(test, dummy)); Assert.IsFalse(update); dummy.Item = false; Assert.IsTrue(Sys.Contains(test, dummy)); Assert.IsFalse(update); }
public static bool InheritsFrom(this System.Type type, System.Type baseType) { if (baseType.IsAssignableFrom(type)) { return(true); } if (type.IsInterface && !baseType.IsInterface) { return(false); } if (baseType.IsInterface) { return(Enumerable.Contains(type.GetInterfaces(), baseType)); } for (System.Type currentType = type; currentType != null; currentType = currentType.BaseType) { if (currentType == baseType || baseType.IsGenericTypeDefinition && currentType.IsGenericType && currentType.GetGenericTypeDefinition() == baseType) { return(true); } } return(false); }
private static string FormatJsonValue(object v) { if (v == null || v is DBNull) { return("null"); } Type tval = v.GetType(); if (tval != typeof(string) && typeof(IEnumerable).IsAssignableFrom(tval)) { StringBuilder sb = new StringBuilder(); sb.Append("["); IList <string> store = new List <string>(); foreach (object o in (IEnumerable)v) { store.Add(FormatJsonValue(o)); } for (int i = 0; i < store.Count; i++) { sb.Append(store[i]); if (i < store.Count - 2) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } if (tval.IsPrimitive) { if (tval == typeof(bool)) { return(v.ToString().ToLower()); } if (Enumerable.Contains(IntegralTypes, tval)) { return(v.ToString()); } if (Enumerable.Contains(FloatingPointTypes, tval)) { return(string.Format("{0:E}", v)); } } if (tval == typeof(string) || tval == typeof(Char)) { return(string.Format("\"{0}\"", HttpUtility.HtmlEncode((string)v))); } ///todo : more complex classes throw new FormatException(); }
private void SpinSomeBois() { foreach (Thot thot in FindObjectsOfType <Thot>()) { stringcheese[] litBois = new stringcheese[] { "Saber", "Top", "Bottom", "Blade", "Handle", "Ornament0", "Ornament1" }; if (thot.GetComponent <SpinnyBoi>() == null && thot.GetComponent <LumpyBoi>() != null && (Plugin.savePokeyBoisMode ? !FailedAntiSpaghet.Contains(litBois, thot.name) : true)) { thot.AddComponent <SpinnyBoi>(); } } }
public IEnumerable <Speaker> GetSpeakersById(IEnumerable <string> speakerIds) { return(_collection.AsQueryable().Where(speaker => Enumerable.Contains(speakerIds, speaker.Id)).ToList()); }