using Moq - question RRS feed

  • Question

  • User888441741 posted

    i have just started using Moq ver (3.1) and i have read blogs and what not.... anyway... i guess until you makes your hand dirty you will not learn :)

    okay here is what i'm testing...

          var newProduct = new Mock<IPartialPerson>();
                newProduct.SetupGet(p => p.FirstName).Returns("FirstName");
                newProduct.SetupGet(p => p.MiddleName).Returns("MiddleName");
                newProduct.SetupGet(p => p.LastName).Returns("LastName");
                newProduct.SetupGet(p => p.EmailAddress).Returns("EmailAddress@hotmail.com");
                newProduct.SetupGet(p => p.UserID).Returns("UserID");
                //mock Escort repository
                var mockEscortRepository = new Mock<IEscortRepository>();  
                mockEscortRepository.Setup(p => p.LoadAllEscorts())
                    .Returns(newProduct.Object); //error


    Error 1 The best overloaded method match for 'Moq.Language.IReturns<App.Repositories.Interface.IEscortRepository,System.Collections.Generic.List<App.Model.PartialPerson>>.Returns(System.Collections.Generic.List<App.Model.PartialPerson>)' has some invalid arguments

     Error 2 Argument '1': cannot convert from 'App.Model.Interface.IPartialPerson' to 'System.Collections.Generic.List<App.Model.PartialPerson>'

    public interface IPartialPerson
            string FirstName { get; }
            string MiddleName { get; }
            string LastName { get; }
            string EmailAddress { get; }
            string FullName { get; }
            string UserID { get; }


     public interface IEscortRepository
            List<PartialPerson> LoadAllEscorts();
            List<PartialPerson> SelectedEscorts(List<PartialPerson> selectedEscorts);  

    i have two methods that i want to test "LoadAllaEscorts" and "SelectedEscorts"

    how would i do a test for both methods?


    Friday, February 26, 2010 3:35 PM