title: UnitTest add item to list and check if exists
body: <p>I want to test if my code works properly so I am writing some unit tests for it.</p>
  
  <p>I want to check when and item in my list with the same values is added again it should return false.</p>
  
  <p>I do not really understand how to set this up. I hope some can help me out.
  Below my code</p>
  
  <p>GuestResponseRepository</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using PartyInvites.Abstract;
  
  namespace PartyInvites.Models
  {
      public class GuestResponseRepository : IRepository
  
      {
          private static List&lt;GuestResponse&gt; responses = new List&lt;GuestResponse&gt;();
  
          IEnumerable&lt;GuestResponse&gt; IRepository.GetAllResponses()
          {
              return responses;
          }
  
          bool IRepository.AddResponse(GuestResponse response)
          {
              if (responses.Any(x =&gt; x.Email == response.Email)) //here
              {
                  if (responses.Any(x =&gt; x.WillAttend == response.WillAttend)) //here
                  {
                      return false;
                  }
  
                  var attend = responses.First(x =&gt; x.Email == response.Email &amp;&amp; x.WillAttend != response.WillAttend);
                  attend.WillAttend = response.WillAttend;
                  return true;
              }
  
              responses.Add(response);
              return true;
          }
      }
  }
  </code></pre>
  
  <p>My interface which communicates with the <code>GuestResponseRepository</code></p>
  
  <pre><code> using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using PartyInvites.Models;
  
  namespace PartyInvites.Abstract
  {
      public interface IRepository
      {
          IEnumerable&lt;GuestResponse&gt; GetAllResponses();
          bool AddResponse(GuestResponse response);
      }
  }
  </code></pre>
  
  <p>A piece of my Homecontroller</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using PartyInvites.Models;
  using PartyInvites.Abstract;
  
  namespace PartyInvites.Controllers {
      public class HomeController : Controller {
          private IRepository repository;
  
          public HomeController(IRepository iRepository)
          {
              this.repository = iRepository;
          }
  
  
          [HttpGet]
          public ViewResult RsvpForm() {
              return View();
          }
  
          [HttpPost]
          public ViewResult RsvpForm(GuestResponse guestResponse) {
              if (ModelState.IsValid) {
  
                  bool result = repository.AddResponse(guestResponse);
                  ViewBag.Response = result;
  
                  repository.AddResponse(guestResponse);                
                  return View("Thanks", guestResponse);
              }
              else
              {
                  // there is a validation error
                  return View();
              }
          }
      }
  }
  </code></pre>
  
  <p>My UnitTest what I got so far</p>
  
  <pre><code>using System;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using PartyInvites.Abstract;
  using PartyInvites.Controllers;
  using PartyInvites.Models;
  using Moq;
  
  namespace Aanmelden
  {
      [TestClass]
      public class UnitTest1
      {
          [TestMethod]
          public void FirstResponse()
          {
              //Arange
              Mock&lt;IRepository&gt; mock = new Mock&lt;IRepository&gt;();
              mock.Setup(m =&gt; m.AddResponse()).Returns(new GuestResponse[] {
              new GuestResponse {Name = "Valheru", Email = "valheru@hotmail.com", Phone = "12345678", WillAttend = true}
              });
  
              HomeController controller = new HomeController(mock.Object);
              //Act
              new GuestResponse
              {
                  Name = "Valheru",
                  Email = "valheru@hotmail.com",
                  Phone = "12345678",
                  WillAttend = true
              };
  
              //Assert
              if viewbag.response = result == false test succeeded
  
          }
      }
  }
  </code></pre>
  
  <p>for some reason <code>mock.Setup(m =&gt; m.**AddResponse**()).Returns(new GuestResponse[] {...</code>
  "AddResponse" aint right says Visual Studio -> </p>
  
  <blockquote>
    <p>there is no argument given that corresponds to the required formal
    parameter 'response' of IRepository.AddResponse(GuestReponse)</p>
  </blockquote>
  
  <p>I am also no sure about my Act piece of code and I lost it totally with the Assert part. I hope someone can help me out!</p>