Created
December 2, 2015 22:32
-
-
Save samueleresca/ad7bc2a95e967260ceae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//REPO | |
var objArray = [ | |
{id: 1, description: "Cuba libre", price: 6.00}, | |
{id: 2,description: "Beer",price: 3.50}, | |
{id: 3, description: "Vodka Lemon", price: 5.00}, | |
{id: 4, description: "Long island", price: 5.50}, | |
{id: 5, description: "Caipiroska", price: 7.50} | |
] | |
//SIMPLE QUERY | |
var testResult1= Enumerable.From(objArray) | |
.Where(function (x) { return x.price >= 5.00 }) | |
.Select(function (x) { return x.description }).ToArray(); | |
//TEST | |
QUnit.test("Test Where() and Select()", function (assert) { | |
assert.ok(testResult1[0] == "Cuba libre", "Passed!: value " + testResult1[0]); | |
}); | |
//LAMBDA EXP | |
var testResult2 = Enumerable.From(objArray) | |
.Where("$.price >= 5.00") | |
.Select("$.description").ToArray(); | |
//TEST | |
QUnit.test("Test Where() and Select() using LAMBDA selector", function (assert) { | |
assert.ok(testResult2[0] == "Cuba libre", "Passed! value " + testResult2[0]); | |
}); | |
//LAMBDA EXP ORDER BY | |
var testResult3 = Enumerable.From(objArray) | |
.Where("$.price >= 5.00") | |
.OrderBy("$.price") | |
.Select(function (x) { | |
return { description: x.description, price: x.price } | |
}).ToArray(); | |
//TEST | |
QUnit.test("Test ORDERBY() using LAMBDA selector", function (assert) { | |
assert.ok(testResult3[0].description == "Vodka Lemon", "Passed! value " + testResult3[0].description); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment