﻿/// <reference name="JS/JSLINQ.js" />
//-----------------------------------------------------------------------
// Part of the LINQ to JavaScript (JSLINQ) v1.02 Project - http://jslinq.com
// Copyright (C) 2008 Chris Pietschmann (http://pietschsoft.com). All rights reserved.
// This project is licensed under the Microsoft Reciprocal License (Ms-RL)
// This license can be found here: http://www.codeplex.com/JSLINQ/license
//-----------------------------------------------------------------------
var Samples = {};

/* *** Arrays that Sample Code Uses *** */
Samples.People = [
    {ID:1,FirstName:"Chris",LastName:"Pearson",BookIDs:[1001,1002,1003]},
    {ID:2,FirstName:"Kate",LastName:"Johnson",BookIDs:[2001,2002,2003]},
    {ID:3,FirstName:"Josh",LastName:"Sutherland",BookIDs:[3001,3002,3003]},
    {ID:4,FirstName:"John",LastName:"Ronald",BookIDs:[4001,4002,4003]},
    {ID:5,FirstName:"Steve",LastName:"Pinkerton",BookIDs:[1001,1002,1003]},
    {ID:6,FirstName:"Katie",LastName:"Zimmerman",BookIDs:[2001,2002,2003]},
    {ID:7,FirstName:"Dirk",LastName:"Anderson",BookIDs:[3001,3002,3003]},
    {ID:8,FirstName:"Chris",LastName:"Stevenson",BookIDs:[4001,4002,4003]},
    {ID:9,FirstName:"Bernard",LastName:"Sutherland",BookIDs:[1001,2002,3003]},
    {ID:10,FirstName:"Bernard",LastName:"Pinkerton",BookIDs:[4001,3002,2003]}
];

/* *** Array of Samples Contained in this page *** */
Samples.SampleList = [
    {Group:"From Operator", Samples:["Samples.From01"]},
    {Group:"Where Operator", Samples:["Samples.Where01","Samples.Where02","Samples.Where03","Samples.Where04"]},
    {Group:"Select Operator", Samples:["Samples.Select01","Samples.Select02"]},
    {Group:"SelectMany Operator", Samples:["Samples.SelectMany01","Samples.SelectMany02"]},
    {Group:"OrderBy Operator", Samples:["Samples.OrderBy01","Samples.OrderBy02"]},
    {Group:"OrderByDescending Operator", Samples:["Samples.OrderByDescending01","Samples.OrderByDescending02"]},
    {Group:"Count Operator", Samples:["Samples.Count01","Samples.Count02","Samples.Count03","Samples.Count04","Samples.Count05"]},
    {Group:"Distinct Operator", Samples:["Samples.Distinct01","Samples.Distinct02","Samples.Distinct03"]},
    {Group:"Any Operator", Samples:["Samples.Any01","Samples.Any02","Samples.Any03","Samples.Any04"]},
    {Group:"All Operator", Samples:["Samples.All01","Samples.All02","Samples.All03","Samples.All04"]},
    {Group:"Reverse Operator", Samples:["Samples.Reverse01"]},
    {Group:"First Operator", Samples:["Samples.First01","Samples.First02","Samples.First03","Samples.First04"]},
    {Group:"Last Operator", Samples:["Samples.Last01","Samples.Last02","Samples.Last03","Samples.Last04"]},
    {Group:"ElementAt Operator", Samples:["Samples.ElementAt01"]}
];

/* *** Code used for executing and showing the samples in the page *** */
Samples.ShowSampleList = function(){
    var sampleList = document.getElementById("SampleList");
    for(var g = 0; g < Samples.SampleList.length; g++)
    {
        var group = document.createElement("li");
        group.innerHTML = Samples.SampleList[g].Group;
        sampleList.appendChild(group);
        group = document.createElement("ul");
        
        for(var s = 0; s < Samples.SampleList[g].Samples.length; s++)
        {
            var sample = eval("new " + Samples.SampleList[g].Samples[s] + "()");
            
            var sampleElement = document.createElement("li");
            sampleElement.innerHTML = "<a href='javascript:Samples.Show(" + Samples.SampleList[g].Samples[s] + ");'>" + sample.Name + "</a>";
            group.appendChild(sampleElement);
        }
        
        sampleList.appendChild(group);
    }
};
Samples.ShowSourceData = function(){
    document.getElementById("SourceData").innerHTML = Samples.Views.People(Samples.People);
};
Samples.Show = function(sample){
    var s = new sample();
    // Display Sample Name, Description and Code on the page
    document.getElementById("lblSampleTitle").innerHTML = s.Title;
    document.getElementById("lblSampleDescription").innerHTML = s.Description;
    document.getElementById("txtSampleCode").value = s.Code;
    // Execute the Sample to prove it works
    document.getElementById("ResultData").innerHTML = s.View(s.Code());
};
Samples.RunTests = function(){
    var failureCount = 0;
    var successCount = 0;
    var strFailedTest = "";
    
    var start = (new Date()).getTime();
    
    for(var g = 0; g < Samples.SampleList.length; g++)
    {
        for(var i = 0; i < Samples.SampleList[g].Samples.length; i++)
        {
            var s = eval("new " + Samples.SampleList[g].Samples[i] + "()");
            if (s.Test())
                successCount++;
            else
            {
                failureCount++;
                strFailedTest += Samples.SampleList[g].Samples[i] + "<br/>";
            }
        }
    }
    
    var end = (new Date()).getTime();
    
    var elem = document.getElementById("TestResults");
    elem.innerHTML = "Successes: " + successCount + " - Failures: " + failureCount + " - Timing: " + (end - start);
    if (failureCount > 0) {
        elem.innerHTML += "<br/><strong>Failed Tests:</strong><br/>" + strFailedTest;
    }
};

Samples.Views = {};
Samples.Views.People = function(people) {
    var str = "<table class='peopleList'><tr><th>ID</th><th>First Name</th><th>Last Name</th><th>Books</th></tr>";
    if (people.length == undefined)
    {
        /// If the length of the people array is undefined, then it's not an array but a Person object instead.
        str += "<tr><td>" + people.ID + "</td><td>" + people.FirstName + "</td><td>" + people.LastName + "</td><td>" + Samples.Views.StringArray(people.BookIDs) + "</td></tr>";
    }
    else
    {
        for(var i = 0; i < people.length; i++){
            str += "<tr><td>" + people[i].ID + "</td><td>" + people[i].FirstName + "</td><td>" + people[i].LastName + "</td><td>" + Samples.Views.StringArray(people[i].BookIDs) + "</td></tr>";
        }
    }
    str += "</table>";
    return str;
};
Samples.Views.StringArray = function(strArray) {
    var str = "<table>";
    for(var i = 0; i < strArray.length; i++){
        str += "<tr><td>" + strArray[i] + "</td></tr>";
    }
    str += "</table>";
    return str;
};
Samples.Views.Count = function(b) {
    return "Count: " +  b.toString();
};
Samples.Views.Boolean = function(b) {
    return b.toString();
};




/* *** From Operator Samples *** */
Samples.From01 = function(){
    this.Name = "Basic Usage";
    this.Title = "From Operator: " + this.Name;
    this.Description = "This is the most basic example of using the From Operator.";
    this.View = Samples.Views.People;
};
Samples.From01.prototype = {
    Code:function(){
        var sample = From(Samples.People);
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10);
        }
        catch (ex)
        {
            return false;
        }
    }
};


/* *** Where Operator Samples *** */
Samples.Where01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Where Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Where Operator by passing in a string value for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.Where01.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Where("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 2);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Where02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Where Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Where Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.Where02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Where(function(item){return item.FirstName == 'Chris';});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 2);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Where03 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "Where Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Where Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.Where03.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Where("item.FirstName == 'Chris' && index == 0");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Where04 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "Where Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Where Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.Where04.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Where(function(item, index){return item.FirstName == 'Chris' && index == 0;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};


/* *** Select Operator *** */
Samples.Select01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Select Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.Select01.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Select("item.FirstName");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && typeof(r[0]) == 'string');
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Select02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Select Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.Select02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Select(function(item){return item.FirstName;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && typeof(r[0]) == 'string');
        }
        catch(ex)
        {
            return false;
        }
    }
};

/* *** SelectMany Operator * ***/
Samples.SelectMany01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "SelectMany Operator: " + this.Name;
    this.Description = "This is the most basic example of using the SelectMany Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.SelectMany01.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            SelectMany("item.BookIDs");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 30 && typeof(r[0]) == 'number');
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.SelectMany02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "SelectMany Operator: " + this.Name;
    this.Description = "This is the most basic example of using the SelectMany Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.SelectMany02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            SelectMany(function(item){return item.BookIDs;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 30 && typeof(r[0]) == 'number');
        }
        catch(ex)
        {
            return false;
        }
    }
};

/* *** OrderBy Operator *** */
Samples.OrderBy01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the OrderBy Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.OrderBy01.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            OrderBy("item.FirstName");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Steve");
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.OrderBy02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the OrderBy Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.OrderBy02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            OrderBy(function(item){return item.FirstName;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Steve");
        }
        catch(ex)
        {
            return false;
        }
    }
};


/* *** OrderByDescending Operator *** */
Samples.OrderByDescending01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the OrderByDescending Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.OrderByDescending01.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            OrderByDescending("item.FirstName");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && r[0].FirstName == "Steve" && r[r.length - 1].FirstName == "Bernard");
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.OrderByDescending02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Select Operator: " + this.Name;
    this.Description = "This is the most basic example of using the OrderByDescending Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.OrderByDescending02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            OrderByDescending(function(item){return item.FirstName;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && r[0].FirstName == "Steve" && r[r.length - 1].FirstName == "Bernard");
        }
        catch(ex)
        {
            return false;
        }
    }
};


/* *** Count Operator *** */
Samples.Count01 = function(){
    this.Name = "Basic Usage";
    this.Title = "Count Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Count Operator.";
    this.View = Samples.Views.Count;
};
Samples.Count01.prototype = {
    Code:function(){
        var sample = From(Samples.People).Count();
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r == 10);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Count02 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Count Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Count Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.Count;
};
Samples.Count02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Count("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r == 2);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Count03 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Count Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Count Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.Count;
};
Samples.Count03.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Count(function(item){return item.FirstName == 'Chris';});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r == 2);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Count04 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "Count Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Count Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Count;
};
Samples.Count04.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Count("item.FirstName == 'Chris' && index == 0");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Count05 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "Count Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Count Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Count;
};
Samples.Count05.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Count(function(item, index){return item.FirstName == 'Chris' && index == 4;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r == 0);
        }
        catch(ex)
        {
            return false;
        }
    }
};


/* *** Distinct Operator *** */
Samples.Distinct01 = function(){
    this.Name = "Basic Usage";
    this.Title = "Distinct Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Distinct Operator.<br/><strong>Currently, Using the Distinct Operator without specifying a clause does not work with an Array of Objects. However, it does work correctly with an Array of Numbers or Strings.</strong>";
    this.View = Samples.Views.StringArray;
};
Samples.Distinct01.prototype = {
    Code:function(){
        /// This sample actually doesn't work because there is a bug in the way Objects are compared.
        var sample = From(Samples.People).Select("item.FirstName").Distinct();
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 8);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Distinct02 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Distinct Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Distinct Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.Distinct02.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Distinct("item.FirstName");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 8);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Distinct03 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Distinct Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Distinct Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.StringArray;
};
Samples.Distinct03.prototype = {
    Code:function(){
        var sample = From(Samples.People).
            Distinct(function(item){return item.FirstName;});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 8);
        }
        catch(ex)
        {
            return false;
        }
    }
};

        
        
/* *** Any Operator *** */
Samples.Any01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Any Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Any Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.Boolean;
};
Samples.Any01.prototype = {
    Code:function(){
        var sample = From(Samples.People).Any("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == true);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Any02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Any Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Any Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.Boolean;
};
Samples.Any02.prototype = {
    Code:function(){
        var sample = From(Samples.People).Any(function(item){return item.FirstName == 'Chris'});
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == true);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Any03 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "Any Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Any Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Boolean;
};
Samples.Any03.prototype = {
    Code:function(){
        var sample = From(Samples.People).Any("item.FirstName == 'Chris' && index == 4");
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Any04 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "Any Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Any Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Boolean;
};
Samples.Any04.prototype = {
    Code:function(){
        var sample = From(Samples.People).Any(function(item, index){return item.FirstName == 'Chris' && index == 4});
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};
    
        
        
/* *** All Operator *** */
Samples.All01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "All Operator: " + this.Name;
    this.Description = "This is the most basic example of using the All Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.Boolean;
};
Samples.All01.prototype = {
    Code:function(){
        var sample = From(Samples.People).All("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.All02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "All Operator: " + this.Name;
    this.Description = "This is the most basic example of using the All Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.Boolean;
};
Samples.All02.prototype = {
    Code:function(){
        var sample = From(Samples.People).All(function(item){return item.FirstName == 'Chris'});
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.All03 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "All Operator: " + this.Name;
    this.Description = "This is the most basic example of using the All Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Boolean;
};
Samples.All03.prototype = {
    Code:function(){
        var sample = From(Samples.People).All("item.FirstName == 'Chris' && index == 0");
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.All04 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "All Operator: " + this.Name;
    this.Description = "This is the most basic example of using the All Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.Boolean;
};
Samples.All04.prototype = {
    Code:function(){
        var sample = From(Samples.People).All(function(item, index){return item.FirstName == 'Chris' && index == 0});
        return sample;
    },
    Test:function(){
        try
        {
            return (this.Code() == false);
        }
        catch(ex)
        {
            return false;
        }
    }
};
        
        
        
/* *** Reverse Operator * ***/
Samples.Reverse01 = function(){
    this.Name = "Basic Usage";
    this.Title = "Reverse Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Reverse Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.Reverse01.prototype = {
    Code:function(){
        var sample = From(Samples.People).Reverse();
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Chris");
        }
        catch(ex)
        {
            return false;
        }
    }
};

        
        
/* *** First Operator * ***/
Samples.First01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "First Operator: " + this.Name;
    this.Description = "This is the most basic example of using the First Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.First01.prototype = {
    Code:function(){
        var sample = From(Samples.People).First("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.First02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "First Operator: " + this.Name;
    this.Description = "This is the most basic example of using the First Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.First02.prototype = {
    Code:function(){
        var sample = From(Samples.People).First(function(item){return item.FirstName == 'Chris'});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.First03 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "First Operator: " + this.Name;
    this.Description = "This is the most basic example of using the First Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.First03.prototype = {
    Code:function(){
        var sample = From(Samples.People).First("item.FirstName == 'Chris' && index == 0");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.First04 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "First Operator: " + this.Name;
    this.Description = "This is the most basic example of using the First Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.First04.prototype = {
    Code:function(){
        var sample = From(Samples.People).First(function(item, index){return item.FirstName == 'Chris' && index == 0});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

        
        
/* *** Last Operator * ***/
Samples.Last01 = function(){
    this.Name = "Basic String Clause";
    this.Title = "Last Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Last Operator by passing in a string for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.Last01.prototype = {
    Code:function(){
        var sample = From(Samples.People).Last("item.FirstName == 'Chris'");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 8);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Last02 = function(){
    this.Name = "Basic Function Clause";
    this.Title = "Last Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Last Operator by passing in a function for the operator clause.";
    this.View = Samples.Views.People;
};
Samples.Last02.prototype = {
    Code:function(){
        var sample = From(Samples.People).Last(function(item){return item.FirstName == 'Chris'});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 8);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Last03 = function(){
    this.Name = "String Clause - Reference Item Index";
    this.Title = "Last Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Last Operator by passing in a string for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.Last03.prototype = {
    Code:function(){
        var sample = From(Samples.People).Last("item.FirstName == 'Chris' && index == 0");
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

Samples.Last04 = function(){
    this.Name = "Function Clause - Reference Item Index";
    this.Title = "Last Operator: " + this.Name;
    this.Description = "This is the most basic example of using the Last Operator by passing in a function for the operator clause, and referencing the Array items index within the clause.";
    this.View = Samples.Views.People;
};
Samples.Last04.prototype = {
    Code:function(){
        var sample = From(Samples.People).Last(function(item, index){return item.FirstName == 'Chris' && index == 0});
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Chris" && r.ID == 1);
        }
        catch(ex)
        {
            return false;
        }
    }
};

        
        
/* *** ElementAt Operator * ***/
Samples.ElementAt01 = function(){
    this.Name = "Basic Usage";
    this.Title = "ElementAt Operator: " + this.Name;
    this.Description = "This is the most basic example of using the ElementAt Operator.";
    this.View = Samples.Views.People;
};
Samples.ElementAt01.prototype = {
    Code:function(){
        var sample = From(Samples.People).ElementAt(1);
        return sample;
    },
    Test:function(){
        try
        {
            var r = this.Code();
            return (r.FirstName == "Kate" && r.ID == 2);
        }
        catch(ex)
        {
            return false;
        }
    }
};