locked
Help with Nunit tests RRS feed

  • Question

  • Hello everyone!

    Because I'm begginer I realized along with writing code I need to write tests.
    So I started to learn Nunit tests.
    Now I'm trayng to write test for this specific cod.
    Unfortunately I couldn't do it. :(
    I would ask you if you can help me with writing tests for this cod.

    This is not homework, this is my example where I teach Nunit tests.


    I need fo find Bob B with assert in frst test with this certain parameters(skill and skillLevel)
    and in another test I need to find more people, maybe two or three people with this parameters.

    How to check whether these are people who I'm searching for?

     


    using System;
    using System.Collections.Generic;

    class Candidate
    {
    public string Name { get; set; }
    public List<Skill> Skills { get; private set;}

    public Candidate(string name, List<Skill> skills)
    {
    Name = name;
    Skills = skills;
    }
    }

    public class Skill
    {
    public string Name { get;set; }
    public int Level { get;set; }

    public Skill(string name, int level)
    {
    this.Name = name;
    this.Level = level;
    }
    }

    interface ICandidateSearch //interface for search
    {
    List<Candidate> Find(List<String> skills);
    List<Candidate> Find(List<Skill> skills);
    }

    class CandidateSearch : ICandidateSearch
    {
    List<Candidate> candidates;

    public List<Candidate> Find(List<String> skills)
    {
    List<Candidate> results = new List<Candidate>();
    foreach(Candidate c in candidates)
    {
    bool match = true;

    foreach(string name in skills)
    {
    bool found = false;

    foreach(Skill cs in c.Skills)
    {
    if(name == cs.Name)
    {
    found = true;
    break;
    }
    }

    if (!found)
    {
    match = false;
    break;
    }
    }

    if (match) results.Add(c);
    }

    return results;
    }


    public List<Candidate> Find(List<Skill> skills)
    {
    List<Candidate> results = new List<Candidate>();

    foreach(Candidate c in candidates)
    {
    bool match = true;

    foreach(Skill s in skills)
    {
    bool found = false;

    foreach(Skill cs in c.Skills)
    {
    if(s.Name == cs.Name && s.Level<= cs.Level)
    {
    found = true;
    break;
    }
    }

    if (!found)
    {
    match = false;
    break;
    }
    }

    if (match) results.Add(c);
    }

    return results;
    }

    public CandidateSearch(List<Candidate> candidates)
    {
    this.candidates = candidates;
    }
    }

    class Program
    {
    static void Main()
    {
    List<Candidate> candidates = new List<Candidate>();
    List<Skill> list1 = new List<Skill>();
    list1.Add(new Skill("SQL", 4));
    list1.Add(new Skill("MVC", 3));
    list1.Add(new Skill("C#", 5));
    Candidate c1 = new Candidate("Bob B.", list1);
    candidates.Add(c1);

    List<Skill> list2 = new List<Skill>();
    list2.Add(new Skill("SharePoint", 3));
    list2.Add(new Skill("SQL", 5));
    list2.Add(new Skill("C#", 5));
    Candidate c2 = new Candidate("John K.", list2);
    candidates.Add(c2);

    List<Skill> list3 = new List<Skill>();
    list3.Add(new Skill("SQL", 5));
    list3.Add(new Skill("ASP.NET", 4));
    list3.Add(new Skill("XML", 4));
    Candidate c3 = new Candidate("Peter B.", list3);
    candidates.Add(c3);

    CandidateSearch candSearch = new CandidateSearch(candidates);
    List<Skill> list4 = new List<Skill>();
    list4.Add(new Skill("C#", 5));
    List<Candidate> results = candSearch.Find(list4);
    for(int i = 0; i < results.Count; i++)
    {
    Console.Write(results[i].Name);
    if (i < results.Count - 1) Console.Write(",");
    }

    Console.WriteLine();

    List<Skill> list5 = new List<Skill>();
    list5.Add(new Skill("SQL", 5));
    results = candSearch.Find(list5);
    for(int i = 0; i < results.Count; i++)
    {
    Console.Write(results[i].Name);
    if (i < results.Count - 1) Console.Write(",");
    }

    Console.ReadKey();
    }
    }


    Saturday, July 23, 2011 3:37 AM

Answers

  • Here you go,

    Test 1 - Search one candidate and assert the name of the candidates and the skills returned

     

    /// <summary>
      ///A test for SearchIfTheSearchCandidateExistsInTheList
      ///</summary>
      [TestMethod()]
      public void SearchIfTheSearchCandidateExistsInTheListTest()
      {
       // Mock inputs
       var list = CreateListMock();
       var searchCandidate = SearchCandidateMock();
    
       // What is expected?
       var expectedCandidate = new List<Candidate>();
       // Candiate List 1
       var eList1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var eCandidate1 = new Candidate("Bob B.", eList1);
       expectedCandidate.Add(eCandidate1);
       // Candidate List 2
       var eList2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var eCandidate2 = new Candidate("John K.", eList2);
       expectedCandidate.Add(eCandidate2);
    
       // Actual calls
       var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
       // Assert
       Assert.IsNotNull(expectedCandidate);
       for (int i = 0; i < actual.Count; i++ )
       {
        Assert.AreEqual(expectedCandidate[i].Name, actual[i].Name, "Search Result Names do not match");
        Assert.AreEqual(expectedCandidate[i].Skills.Count, actual[i].Skills.Count, "The count of skills for the skill do not match");
    
        for (int j = 0; j < actual[i].Skills.Count; j++)
        {
         Assert.AreEqual(expectedCandidate[i].Skills[j].Name, expectedCandidate[i].Skills[j].Name, "The name of the skills do not match");
         Assert.AreEqual(expectedCandidate[i].Skills[j].Level, expectedCandidate[i].Skills[j].Level, "The level of the skills do not match");
        }
       }
      }
    
      private static List<Candidate> CreateListMock()
      {
       var candidates = new List<Candidate>();
       var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var c1 = new Candidate("Bob B.", list1);
       candidates.Add(c1);
    
       var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var c2 = new Candidate("John K.", list2);
       candidates.Add(c2);
    
       var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
       var c3 = new Candidate("Peter B.", list3);
       candidates.Add(c3);
    
       return candidates;
      }
    
      private static List<Skill> SearchCandidateMock()
      {
       var list = new List<Skill> { new Skill("C#", 5) };
       return list;
      }
    

    Test 2 - Perform a complex multi level search and assert the candidate name, skill and level

     

    [TestMethod()]
      public void MultiSkillSearchValidateIfTheSearchCandidateExistsInTheListTest()
      {
       // Mock inputs
       var list = CreateListMock();
       var searchCandidate = SearchMultipleSkillMock();
    
       // What is expected?
       var expectedCandidate = new List<Candidate>();
       // Candidate List 1
       var eList2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var eCandidate2 = new Candidate("John K.", eList2);
       expectedCandidate.Add(eCandidate2);
    
       // Actual calls
       var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
       // Assert
       Assert.IsNotNull(expectedCandidate);
       for (int i = 0; i < actual.Count; i++ )
       {
        Assert.AreEqual(expectedCandidate[i].Name, actual[i].Name, "Search Result Names do not match");
        Assert.AreEqual(expectedCandidate[i].Skills.Count, actual[i].Skills.Count, "The count of skills for the skill do not match");
    
        for (int j = 0; j < actual[i].Skills.Count; j++)
        {
         Assert.AreEqual(expectedCandidate[i].Skills[j].Name, expectedCandidate[i].Skills[j].Name, "The name of the skills do not match");
         Assert.AreEqual(expectedCandidate[i].Skills[j].Level, expectedCandidate[i].Skills[j].Level, "The level of the skills do not match");
        }
       }
      }
    
      private static List<Candidate> CreateListMock()
      {
       var candidates = new List<Candidate>();
       var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var c1 = new Candidate("Bob B.", list1);
       candidates.Add(c1);
    
       var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var c2 = new Candidate("John K.", list2);
       candidates.Add(c2);
    
       var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
       var c3 = new Candidate("Peter B.", list3);
       candidates.Add(c3);
    
       return candidates;
      }
    
      private static List<Skill> SearchMultipleSkillMock()
      {
       var list = new List<Skill> { new Skill("C#", 5), new Skill("SQL", 5) };
       return list;
      }
    

    All you need to do is, add more skills to the SearchMultiSkillMock and keep modifying the expected result. The rest of the structure should just work fine.

     

    HTH

    Cheers, Tarun


    Please remember to mark the replies as answers if they help.

    Tarun Arora

     

    Blog: http://geekswithblogs.net/TarunArora  Subscribe in a reader


    • Edited by Tarun__AroraMVP Monday, July 25, 2011 9:48 PM formatting
    • Marked as answer by Amii_soft Monday, July 25, 2011 10:11 PM
    Monday, July 25, 2011 9:47 PM

All replies

  • Hi Amii,

    I don't have Nunit installed so i will explain this using the visual studio testing framework.

    I have refactored your code,

    <pre lang="x-c#">using System.Collections.Generic;
    using System.Diagnostics;
    
    namespace WorkItemManager1
    {
      public class Skill
      {
        public string Name { get; set; }
        public int Level { get; set; }
    
        public Skill(string name, int level)
        {
          Name = name;
          Level = level;
        }
      }
    
      public class Candidate
      {
        public string Name { get; set; }
        public List<Skill> Skills { get; set; }
    
        public Candidate(string name, List<Skill> skills)
        {
          Name = name;
          Skills = skills;
        }
      }
    
      interface ICandidateSearch
      {
        List<Candidate> Find(List<string> skills);
        List<Candidate> Find(List<Skill> skills);
      }
    
      class CandidateSearch : ICandidateSearch
      {
        readonly List<Candidate> _candidates;
    
        public List<Candidate> Find(List<string> skills)
        {
          var results = new List<Candidate>();
          foreach (var c in _candidates)
          {
            var match = true;
    
            foreach (var name in skills)
            {
              bool found = false;
    
              foreach (Skill cs in c.Skills)
              {
                if (name == cs.Name)
                {
                  found = true;
                  break;
                }
              }
    
              if (!found)
              {
                match = false;
                break;
              }
            }
    
            if (match) results.Add(c);
          }
    
          return results;
        }
    
    
        public List<Candidate> Find(List<Skill> skills)
        {
          var results = new List<Candidate>();
    
          foreach (var c in _candidates)
          {
            var match = true;
    
            foreach (Skill s in skills)
            {
              var found = false;
    
              foreach (Skill cs in c.Skills)
              {
                if (s.Name == cs.Name && s.Level <= cs.Level)
                {
                  found = true;
                  break;
                }
              }
    
              if (!found)
              {
                match = false;
                break;
              }
            }
    
            if (match) results.Add(c);
          }
    
          return results;
        }
    
        public CandidateSearch(List<Candidate> candidates)
        {
          _candidates = candidates;
        }
      }
    
      public class SearchRepository
      {
        public static List<Candidate> SearchIfTheSearchCandidateExistsInTheList(List<Candidate> list, List<Skill> searchCandidate)
        {
          var candSearch = new CandidateSearch(list);
          var results = candSearch.Find(searchCandidate);
            
          for (var i = 0; i < results.Count; i++)
          {
            Debug.Write(results[i].Name);
            if (i < results.Count - 1) Debug.Write(",");
          }
    
          return results;
        }
      }
    }
    

    Notes

    1. It is important to break your methods down to granular tasks in order to effectively tests them. For example if you look at the main methods i am passinng the collection and search candidate as a variable rather than constructing this in the main method. If you construct this with in the main method, the method would not be reusable, agreed?

    2. Your main methods need to be generic, it is easy to create private methods that do the dirty work and can always be mocked during the test very easily.

    Now, if you right click the class and select, create test, this should create a test project if not already there and will add the class as a unit test for you while creating a basic structure for the test.

    Now you can simply search the Main method to provoke the tets for your find,

    using WorkItemManager1;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System.Collections.Generic;
    
    namespace TestProject1
    {
      /// <summary>
      ///This is a test class for SearchRepositoryTest and is intended
      ///to contain all SearchRepositoryTest Unit Tests
      ///</summary>
      [TestClass()]
      public class SearchRepositoryTest
      {
    
    
        private TestContext testContextInstance;
    
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
          get
          {
            return testContextInstance;
          }
          set
          {
            testContextInstance = value;
          }
        }   
    
        /// <summary>
        ///A test for SearchIfTheSearchCandidateExistsInTheList
        ///</summary>
        [TestMethod()]
        public void SearchIfTheSearchCandidateExistsInTheListTest()
        {
          // Mock inputs
          var list = CreateListMock();
          var searchCandidate = SearchCandidateMock();
    
          // What is expected?
          var expectedCandidate = new List<Candidate>();
          var eCandidate = new Candidate("Bob B.", new List<Skill>());
          expectedCandidate.Add(eCandidate);
    
          // Actual calls
          var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
          // Assert
          Assert.AreEqual(expectedCandidate[0].Name, actual[0].Name, "Search Results do not match");
        }
    
        private static List<Candidate> CreateListMock()
        {
          var candidates = new List<Candidate>();
          var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
          var c1 = new Candidate("Bob B.", list1);
          candidates.Add(c1);
    
          var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
          var c2 = new Candidate("John K.", list2);
          candidates.Add(c2);
    
          var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
          var c3 = new Candidate("Peter B.", list3);
          candidates.Add(c3);
    
          return candidates;
        }
    
        private static List<Skill> SearchCandidateMock()
        {
          var list = new List<Skill> { new Skill("C#", 5) };
          return list;
        }
    
      }
    }
    
    

    The key in the test code above is,

    /// <summary>
            ///A test for SearchIfTheSearchCandidateExistsInTheList
            ///</summary>
            [TestMethod()]
            public void SearchIfTheSearchCandidateExistsInTheListTest()
            {
                // Mock inputs
                var list = CreateListMock();
                var searchCandidate = SearchCandidateMock();

                // What is expected?
                var expectedCandidate = new List<Candidate>();
                var eCandidate = new Candidate("Bob B.", new List<Skill>());
                expectedCandidate.Add(eCandidate);

                // Actual calls
                var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);

                // Assert
                Assert.AreEqual(expectedCandidate[0].Name, actual[0].Name, "Search Results do not match");
            }

    If you see the test is split up in to 4 steps,

    1. Mock the inputs

    2. What do you expect as a result of the test

    3. Execute the method you need to test

    4. Assert the test results.

    Now that the structure and mock are there, you could set up test methods for

    1. No results returned by the search method

    2. Boundary level tests

    3. Two or more results returned

    4. 10 or more results returned.

    HTH
    Cheers, Tarun


    Please remember to mark the replies as answers if they help.

    Tarun Arora

    Blog: http://geekswithblogs.net/TarunArora  Subscribe in a reader

    • Marked as answer by Amii_soft Saturday, July 23, 2011 9:40 PM
    • Unmarked as answer by Amii_soft Monday, July 25, 2011 1:36 PM
    Saturday, July 23, 2011 1:34 PM
  • Hi Tarun_Arora,

    Thank you for your response.

    Your answer helped me a lot.Your explanation I applied in NUnite.

    Everything is great!

    I was looking for candidates for Skill "C#" and SkillLevel 5.
    I got Bob B. and John K.

    I have a new question for you!

    Can you help me to write test for more candidates with
    more Skill and more SkillLevel?

    Example:

    For Skill SQL, SkillLevel 5 and Skill ASP.NET,SkillLevel 4 and Skill MVC,SkillLevel 3
    I need to get these candidates:

    John K.(he has a SQL 5),Piter B.(He has a SQL 5 and ASP.NET 4) and Bob B.(He has a MVC 3)

    Thank you for your help and a separate time!
    Monday, July 25, 2011 1:36 PM
  • Hi Tarun_Arora,

    Thank you for your response.

    Your answer helped me a lot.Your explanation I applied in NUnite.

    Everything is great!

    I was looking for candidates for Skill "C#" and SkillLevel 5.
    I got Bob B. and John K.

    I have a new question for you!

    Can you help me to write test for more candidates with
    more Skill and more SkillLevel?

    Example:

    For Skill SQL, SkillLevel 5 and Skill ASP.NET,SkillLevel 4 and Skill MVC,SkillLevel 3
    I need to get these candidates:

    John K.(he has a SQL 5),Piter B.(He has a SQL 5 and ASP.NET 4) and Bob B.(He has a MVC 3)

    Thank you for your help and a separate time!
    private static List<Candidate> CreateListMock()
        {
          var candidates = new List<Candidate>();
          var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
          var c1 = new Candidate("Bob B.", list1);
          candidates.Add(c1);
    
          var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
          var c2 = new Candidate("John K.", list2);
          candidates.Add(c2);
    
          var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
          var c3 = new Candidate("Peter B.", list3);
          candidates.Add(c3);
    
          return candidates;
        }
    


    The List mock will remain the same. You need to change the expected results, consider the code below.

    [TestMethod()]
        public void SearchIfTheSearchCandidateExistsInTheListTest()
        {
          // Mock inputs
          var list = CreateListMock();
          var searchCandidate = SearchCandidateMock();
    
          // What is expected?
          var expectedCandidate = new List<Candidate>();
          var eList = new new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
          var eCandidate = new Candidate("Bob B.", eList);
          expectedCandidate.Add(eCandidate);
    
          // Actual calls
          var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
          // Assert
          Assert.AreEqual(expectedCandidate[0].Name, actual[0].Name, "Search Results do not match");
          Asset.AreEqual(
            // Look for skills in expectedCandidate[0] and match skills in actual[0], 
            )
          Assert.AreEqual(
            // Look for skills in expectedCandidate[0] and match skills in actual[0], validate the count as well
            )
        }
    


    Please vote up in case this or the previous reply helped.

    Cheers, Tarun

     


    Please remember to mark the replies as answers if they help.

    Tarun Arora

    Blog: http://geekswithblogs.net/TarunArora  Subscribe in a reader

    Monday, July 25, 2011 1:55 PM
  • Hi Tarun_Arora,

    I have a problem with SearchCandidate() // Cannot resolve simbol SearchCandidate()

    Where is the

    private static List <Skill> SearchCandidate()
    {
    var list = new List <Skill> {New Skill ("C #", 5)}
    return list;
    }

    This does not in your previous code.


    I think this is a problem.

    What should I write for more candidates with more Skill
    and more SkillLevels?


    Also

    Asset.AreEqual(
            // Look for skills in expectedCandidate[0] and match skills in actual[0],
            )
          Assert.AreEqual(
            // Look for skills in expectedCandidate[0] and match skills in actual[0], validate the count as well
            )

    I did not understand!


    Sorry if my questions are trivial,only a few days ago I started to teach Unit tests!

    Still many things we are not clear,Sorry!

    Monday, July 25, 2011 7:13 PM
  • Here you go,

    Test 1 - Search one candidate and assert the name of the candidates and the skills returned

     

    /// <summary>
      ///A test for SearchIfTheSearchCandidateExistsInTheList
      ///</summary>
      [TestMethod()]
      public void SearchIfTheSearchCandidateExistsInTheListTest()
      {
       // Mock inputs
       var list = CreateListMock();
       var searchCandidate = SearchCandidateMock();
    
       // What is expected?
       var expectedCandidate = new List<Candidate>();
       // Candiate List 1
       var eList1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var eCandidate1 = new Candidate("Bob B.", eList1);
       expectedCandidate.Add(eCandidate1);
       // Candidate List 2
       var eList2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var eCandidate2 = new Candidate("John K.", eList2);
       expectedCandidate.Add(eCandidate2);
    
       // Actual calls
       var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
       // Assert
       Assert.IsNotNull(expectedCandidate);
       for (int i = 0; i < actual.Count; i++ )
       {
        Assert.AreEqual(expectedCandidate[i].Name, actual[i].Name, "Search Result Names do not match");
        Assert.AreEqual(expectedCandidate[i].Skills.Count, actual[i].Skills.Count, "The count of skills for the skill do not match");
    
        for (int j = 0; j < actual[i].Skills.Count; j++)
        {
         Assert.AreEqual(expectedCandidate[i].Skills[j].Name, expectedCandidate[i].Skills[j].Name, "The name of the skills do not match");
         Assert.AreEqual(expectedCandidate[i].Skills[j].Level, expectedCandidate[i].Skills[j].Level, "The level of the skills do not match");
        }
       }
      }
    
      private static List<Candidate> CreateListMock()
      {
       var candidates = new List<Candidate>();
       var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var c1 = new Candidate("Bob B.", list1);
       candidates.Add(c1);
    
       var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var c2 = new Candidate("John K.", list2);
       candidates.Add(c2);
    
       var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
       var c3 = new Candidate("Peter B.", list3);
       candidates.Add(c3);
    
       return candidates;
      }
    
      private static List<Skill> SearchCandidateMock()
      {
       var list = new List<Skill> { new Skill("C#", 5) };
       return list;
      }
    

    Test 2 - Perform a complex multi level search and assert the candidate name, skill and level

     

    [TestMethod()]
      public void MultiSkillSearchValidateIfTheSearchCandidateExistsInTheListTest()
      {
       // Mock inputs
       var list = CreateListMock();
       var searchCandidate = SearchMultipleSkillMock();
    
       // What is expected?
       var expectedCandidate = new List<Candidate>();
       // Candidate List 1
       var eList2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var eCandidate2 = new Candidate("John K.", eList2);
       expectedCandidate.Add(eCandidate2);
    
       // Actual calls
       var actual = SearchRepository.SearchIfTheSearchCandidateExistsInTheList(list, searchCandidate);
    
       // Assert
       Assert.IsNotNull(expectedCandidate);
       for (int i = 0; i < actual.Count; i++ )
       {
        Assert.AreEqual(expectedCandidate[i].Name, actual[i].Name, "Search Result Names do not match");
        Assert.AreEqual(expectedCandidate[i].Skills.Count, actual[i].Skills.Count, "The count of skills for the skill do not match");
    
        for (int j = 0; j < actual[i].Skills.Count; j++)
        {
         Assert.AreEqual(expectedCandidate[i].Skills[j].Name, expectedCandidate[i].Skills[j].Name, "The name of the skills do not match");
         Assert.AreEqual(expectedCandidate[i].Skills[j].Level, expectedCandidate[i].Skills[j].Level, "The level of the skills do not match");
        }
       }
      }
    
      private static List<Candidate> CreateListMock()
      {
       var candidates = new List<Candidate>();
       var list1 = new List<Skill> { new Skill("SQL", 4), new Skill("MVC", 3), new Skill("C#", 5) };
       var c1 = new Candidate("Bob B.", list1);
       candidates.Add(c1);
    
       var list2 = new List<Skill> { new Skill("SharePoint", 3), new Skill("SQL", 5), new Skill("C#", 5) };
       var c2 = new Candidate("John K.", list2);
       candidates.Add(c2);
    
       var list3 = new List<Skill> { new Skill("SQL", 5), new Skill("ASP.NET", 4), new Skill("XML", 4) };
       var c3 = new Candidate("Peter B.", list3);
       candidates.Add(c3);
    
       return candidates;
      }
    
      private static List<Skill> SearchMultipleSkillMock()
      {
       var list = new List<Skill> { new Skill("C#", 5), new Skill("SQL", 5) };
       return list;
      }
    

    All you need to do is, add more skills to the SearchMultiSkillMock and keep modifying the expected result. The rest of the structure should just work fine.

     

    HTH

    Cheers, Tarun


    Please remember to mark the replies as answers if they help.

    Tarun Arora

     

    Blog: http://geekswithblogs.net/TarunArora  Subscribe in a reader


    • Edited by Tarun__AroraMVP Monday, July 25, 2011 9:48 PM formatting
    • Marked as answer by Amii_soft Monday, July 25, 2011 10:11 PM
    Monday, July 25, 2011 9:47 PM
  • Thank you very much Tarun_Arora !!!

     

     

    This is by far the best answer I got at all !

    A lot of you have bothered to answer me, so thank you much.

     

    With this code I have a complete example where they can learn a lot.

     

    We will try to overcome as soon as the material from this example.

     

    Once again, thank you very much and good luck!

    Monday, July 25, 2011 10:11 PM