public void Where_IfElse() { var list = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); var condition = true; Assert.Equal(4, list.Where(condition, x => x % 2 == 0, x => x % 3 == 0).Count()); Assert.Equal(2, list.Where(!condition, x => x % 2 == 0, x => x % 3 == 0).Count()); }
public void Where_IfElse_Queryable() { var query = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8).AsQueryable(); var condition = true; Assert.Equal(4, query.Where(condition, x => x % 2 == 0, x => x % 3 == 0).Count()); Assert.Equal(2, query.Where(!condition, x => x % 2 == 0, x => x % 3 == 0).Count()); }
public void Split_Empty_ClearEmpty() { var empty = Coll.Array <int>(); var r = empty.Split(x => x == 1, clearEmpty: true); Assert.NotNull(r); Assert.Empty(r); }
public void Split_Empty() { var empty = Coll.Array <int>(); var r = empty.Split(x => x == 1); Assert.NotNull(r); Assert.Equal(1, r.Count()); Assert.Empty(r.ElementAt(0)); }
public void Where_If() { //Setup var list = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); var condition = true; //Exercise & Verify Assert.Equal(4, list.Where(condition, x => x % 2 == 0).Count()); Assert.Equal(list.Count(), list.Where(!condition, x => x % 2 == 0).Count()); }
public void Array() { var r = Coll.Array(1, 2, 3, 3, 5); Assert.Equal(5, r.Length); Assert.Equal(1, r[0]); Assert.Equal(2, r[1]); Assert.Equal(3, r[2]); Assert.Equal(3, r[3]); Assert.Equal(5, r[4]); }
public static IDictionary <TKey, TValue> Merge <TKey, TValue>( this IDictionary <TKey, TValue> source, IDictionary <TKey, TValue> arg) { if (arg == null) { throw new ArgumentNullException("arg"); } return(source.Merge(Coll.Array(arg))); }
public void ContainsAny_ArrayItems_ShouldContainAnyItems() { // Setup var sut = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); // Exercise var actual = sut.ContainsAny(new int[] { 1, 3, 5 }); // Verify Assert.True(actual); }
public void ContainsAll_ArrayItems_ShouldContainAllItems() { // Setup var sut = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); var expectedContainedArray = new int[] { 1, 2, 3, 4 }; // Exercise var actual = sut.ContainsAll(expectedContainedArray); // Verify Assert.True(actual); }
public void ForEach_MultipleParameters() { var list = Coll.Array(1, 2, 3, 4); var acc = 0; list.ForEach((i, o) => { acc += (i * o); }); Assert.Equal(20, acc); }
public void ForEach_SingleParameter() { var list = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); var acc = 0; list.ForEach((i) => { acc += i; }); Assert.Equal(list.Sum(), acc); }
public void WhereBetween() { var query = Coll.Array( DateTime.Today.AddMonths(-2), DateTime.Today, DateTime.Today.AddMonths(2) ).AsQueryable(); var queryFiltered = query.WhereBetween(x => x, DateTime.Today.AddMonths(-1), DateTime.Today.AddMonths(1)); Assert.Equal(1, queryFiltered.Count()); Assert.True(queryFiltered.Contains(query.ElementAt(1))); Assert.False(queryFiltered.ContainsAny(query.ElementAt(0), query.ElementAt(2))); }
public static string ToHumanFileSize(this long bytes) { var sizes = Coll.Array("B", "KB", "MB", "GB"); var len = bytes; var order = 0; while (len >= 1024 && order + 1 < sizes.Length) { order = order + 1; len = len / 1024; } return(string.Format("{0:0.##} {1}", len, sizes[order])); }
public void Where_In_TProp_TPropNullableItems_ReturnsDTO1() { var dto1 = new WhereInDTO(1, "zzz", 1); var dto2 = new WhereInDTO(2, "aaa", null); var dto3 = new WhereInDTO(3, "hhh", 3); var items = Enumerable.Range(1, 1).Cast <int?>(); var query = Coll.Array(dto1, dto2, dto3); var res = query.Where(x => x.Property1, items); Assert.Equal(dto1, res.ElementAt(0)); Assert.Equal(1, res.Count()); }
public void Where_In_TProp_TPropNullableItems_NullItems_ReturnsAll() { var dto1 = new WhereInDTO(1, "zzz", 1); var dto2 = new WhereInDTO(2, "aaa", null); var dto3 = new WhereInDTO(3, "hhh", 3); IEnumerable <int?> items = null; var query = Coll.Array(dto1, dto2, dto3); var res = query.Where(x => x.Property1, items); Assert.Equal(dto1, res.ElementAt(0)); Assert.Equal(dto2, res.ElementAt(1)); Assert.Equal(dto3, res.ElementAt(2)); }
public void Search() { var dto1 = new SearchDTO("Isis", "Castañeda", "Finantial"); var dto2 = new SearchDTO("Helenia", "Caro", "Online"); var dto3 = new SearchDTO("Humberto", "Carmona", "Finantial"); var query = Coll.Array(dto1, dto2, dto3).AsQueryable(); var result = query.Search("isis", x => x.Property1).ToList(); Assert.Equal(1, result.Count()); Assert.Equal(dto1.Property1, result.First().Property1); result = query.Search("isis casta", x => x.Property1 + " " + x.Property2).ToList(); Assert.Equal(1, result.Count()); Assert.Equal(dto1.Property1, result.First().Property1); }
public void ForEach_TwoParameter() { // Setup var list = Coll.Array(1, 2, 3, 4, 5, 6, 7, 8); var acc = 0; var index = 0; // Exercise list.ForEach((e, i) => { acc += e; index = i; }); // Verify Assert.Equal(list.Sum(), acc); Assert.Equal(list.Count() - 1, index); }
public void CheckBoxListFor() { var model = new Model1() { PropIntList = Coll.Array(2, 3) }; var helper = new HtmlTagHelper <Model1>(model); var propExpression = Expr((Model1 m) => m.PropIntList); var tag = helper.CheckBoxListFor( propExpression, OptionsList.CreateForEnum <Enum1>()); Assert.Equal(3, tag.Children.Count()); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(0).First(), name: "PropIntList", display: "Option1", value: 1, isChecked: false); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(1).First(), name: "PropIntList", display: "Option2", value: 2, isChecked: true); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(2).First(), name: "PropIntList", display: "Option3", value: 3, isChecked: true); }
public void CheckBoxList_NotNull_DefaultValue() { var model = new Model1() { PropIntList = Coll.Array(2, 3) }; var helper = new HtmlTagHelper(model); var name = "PropIntList"; var tag = helper.CheckBoxList( name, OptionsList.CreateForEnum <Enum1>(), defaultValues: Coll.Array(1, 2, 4)); Assert.Equal(3, tag.Children.Count()); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(0).First(), name: name, display: "Option1", value: 1, isChecked: false); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(1).First(), name: name, display: "Option2", value: 2, isChecked: true); CheckBoxListTagTest.AssertValidOption(tag.Options.Skip(2).First(), name: name, display: "Option3", value: 3, isChecked: true); }
public void Split_ClearEmpty() { var list = Coll.Array(1, 2, 2, 3, 4, 5, 6, 7, 8); var r = list.Split(x => x == 2 || x == 4 || x == 8, clearEmpty: true); Assert.NotNull(r); Assert.Equal(3, r.Count()); Assert.Equal(1, r.ElementAt(0).Count()); Assert.Equal(1, r.ElementAt(0).ElementAt(0)); Assert.Equal(1, r.ElementAt(1).Count()); Assert.Equal(3, r.ElementAt(1).ElementAt(0)); Assert.Equal(3, r.ElementAt(2).Count()); Assert.Equal(5, r.ElementAt(2).ElementAt(0)); Assert.Equal(6, r.ElementAt(2).ElementAt(1)); Assert.Equal(7, r.ElementAt(2).ElementAt(2)); }
public void AddOptions_Enum_SelectedValues() { var tag = new CheckBoxListTag(DEFAULT_NAME) .AddOptions( OptionsList.CreateForEnum <Enum1>() .SelectedValues(Coll.Array(2)) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Options.Count()); var firstChild = tag.Options.First(); var secondChild = tag.Options.Skip(1).First(); AssertValidOption(firstChild, name: DEFAULT_NAME, display: "Option1", value: 1, isChecked: false); AssertValidOption(secondChild, name: DEFAULT_NAME, display: "Option2", value: 2, isChecked: true); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal(2, secondChild.Data("customdata")); }
public void AddOptions_Enum_SelectedValues() { var tag = new SelectTag() .AddOptions( OptionsList.CreateForEnum<Enum1>() .SelectedValues(Coll.Array(2)) .Configure((x, op) => op.Data("customdata", x.Value))); Assert.Equal(2, tag.Children.Count()); var firstChild = tag.Children.First(); var secondChild = tag.Children.Skip(1).First(); Assert.Equal("Option1", firstChild.Text()); Assert.True(firstChild.ValueIsEqual(1)); Assert.False(firstChild.HasAttr("selected")); Assert.Equal(1, firstChild.Data("customdata")); Assert.Equal("Option2", secondChild.Text()); Assert.True(secondChild.ValueIsEqual(2)); Assert.True(secondChild.HasAttr("selected")); Assert.Equal(2, secondChild.Data("customdata")); }
public void OrderByProperty_desc() { var dto1 = new OrderByPropertyDTO(1, "zzz", DateTime.Today); var dto2 = new OrderByPropertyDTO(2, "aaa", DateTime.Today.AddMonths(1)); var dto3 = new OrderByPropertyDTO(3, "hhh", DateTime.Today.AddMonths(-1)); var query = Coll.Array(dto1, dto2, dto3).AsQueryable(); query = query.OrderByProperty("Property1", false); Assert.Equal(dto1.Property1, query.ElementAt(2).Property1); Assert.Equal(dto2.Property1, query.ElementAt(1).Property1); Assert.Equal(dto3.Property1, query.ElementAt(0).Property1); query = query.OrderByProperty("Property2", false); Assert.Equal(dto2.Property2, query.ElementAt(2).Property2); Assert.Equal(dto3.Property2, query.ElementAt(1).Property2); Assert.Equal(dto1.Property2, query.ElementAt(0).Property2); query = query.OrderByProperty("Property3", false); Assert.Equal(dto3.Property3, query.ElementAt(2).Property3); Assert.Equal(dto1.Property3, query.ElementAt(1).Property3); Assert.Equal(dto2.Property3, query.ElementAt(0).Property3); }
public void Array_Empty() { var r = Coll.Array <int>(); Assert.Equal(0, r.Length); }
public static Uri Absolute(string relative) { return(new Uri(UriHelper.GetBaseUri(), relative.Trim(Coll.Array('/')))); }