Deal with result in callback functions of multiple AJAX-Call

Sometimes, it requires to appear the result after all of the deferred tasks have completed in AJAX-Call. The code can be implemented as follows with jQuery:

var deferreds = [], resultArry = [];

$.each(inputArry, function(index, input){ 

deferreds.push(ajaxFunction(input, functionSuccess(result){

console.log("Each Ajax-Call done!");

resultArry.push(result); //Each result saved in the array.


$.when.apply(null, deferreds).done(function(){

console.log("All Ajax-Call Done:" + resultArry.length);



Importance is to use Function.apply.


C#: Add Object List as Test Data for the same Test Case in NUnit

Sometimes, it is required to define a couple of test data for one test case. In NUnit, “TestCaseSource” is the way to collect the test data for the same test case.

  1. Add annotation “TestCaseSource” before test case.
    [Test, TestCaseSource(typeof(TestDataFactory), "TestDataCollection")]
    public void TestMethod(TestData data) {}
  2. Define a “TestDataFactory” class, which includes static IEnumerable variable “TestDataCollection”.
    public class TestDataFactory
    public static IEnumerable TestDataCollection
    yield return new TestData {var1 =123,var2="test1"};
    yield return new TestData{var1 =456,var2 = "test2"};
  3. Define some test data as a class.

    public class TestData
    public int var1 { get; set; }
    public string var2 { get; set; }

C#: Call by reference or by type?

  • For the object with the basic type, e.g. int, string, etc. It is different with calling by value or by reference.
    int year = 10;
    t.SetYear(year); //year = 10;
    t.SetYearRef(ref year); // year changed in SetYearRef();
  • There is no concept of “call by reference” or “call by value” for List . It works like “call by reference”.
    List l = new List { "a", "b" };

    The values of l are changed in method.
  • The object is called also like “reference”.MySubClass has two variables, t1.year and t1.myList, the values will be changed in the method SetObject() like a reference.
    MySubClass t1 = new MySubClass (2015,new List{"a"});