Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:09:22+00:00 2026-06-08T16:09:22+00:00

I am writing an app that I have been deploying to appharbor. I am

  • 0

I am writing an app that I have been deploying to appharbor. I am having trouble getting my project to build now because I have expanded my tests. I believe the issue is that I am using a db initializer to populate the database with test seed data. These tests pass on my local box but once I deploy the tests fail on appharbor. I suspect I need to mock data but I am not sure how to do this. As an example, here is a controller test that I have for one of my action methods.

Controller

    // GET: /Lead/Url
    // TODO: Add optional url parameters
    public ActionResult Url(string pfirstname, string plastname, string phone, int leadsource)
    {

        var lead = new Lead();
        //store 
        lead.parent_FirstName = pfirstname;
        lead.parent_LastName = plastname;
        lead.parent_Phone = phone;
        lead.LeadSourceID = leadsource;
        lead.AgentID = 1;

        if (ModelState.IsValid)
        {
            leadRepository.InsertLead(lead);
            leadRepository.Save();
            ViewBag.Message = "Success";
        }

        return View(lead);
    }

    //
    // POST: /Lead/URL       
    [HttpPost, ActionName("Url")]
    public ActionResult Url(Lead lead)
    {
        return View();
    }

Unit Test

[TestMethod]
    public void LeadUrl()
    {
        //ARRANGE
        ILeadRepository leadrepository = new LeadRepository(new LeadManagerContext());
        Database.SetInitializer<LeadManagerContext>(new LeadManagerInitializer());
        LeadController controller = new LeadController(leadrepository);

        //ACT
        ViewResult result = controller.Url("Brad", "woods","465-456-4965",1) as ViewResult;
        var lead = (Lead)result.ViewData.Model;

        //ASSERT
       Assert.AreEqual("Success" ,result.ViewBag.Message);
        /*check for valid data */
       Assert.AreEqual("Brad", lead.parent_FirstName);

    }

Could someone please explain what I need to do next in order to improve code like this and get it to run again on app harbor successfully?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:09:24+00:00Added an answer on June 8, 2026 at 4:09 pm

    Actually you haven’t verified interactions between controller and it’s dependencies (repository). And this is the most important part – controller should pass your Lead object to repository. And then call Save (consider also to Unit Of Work pattern).

    Also you should test controller in isolation, only this way you could be sure, that failing controller’s test is an issue of controller, not of LeadRepository or LeadManagerInitializer.

    // Arrange
    Lead expected = CreateBrad();    
    var repository = new Mock<ILeadRepository>();
    LeadController controller = new LeadController(repository.Object);    
    // Act
    ViewResult result = (ViewResult)controller.Url("Brad", "woods", "465-456", 1);
    // Assert      
    Lead actual = (Lead)result.ViewData.Model;
    // All fields should be equal, not only name
    Assert.That(actual, Is.EqualTo(expected));
    Assert.AreEqual("Success", result.ViewBag.Message);
    // You need to be sure, that expected lead object passed to repository
    repository.Verify(r => r.InsertLead(expected));
    repository.Verify(r => r.Save());
    

    BTW I’d moved expected Lead creation to separate method:

    private Lead CreateBrad()
    {
        Lead lead = new Lead();
        lead.parent_FirstName = "Brad";
        lead.parent_LastName = "woods";
        lead.parent_Phone = "465-456";
        lead.LeadSourceID = 1;
        lead.AgentID = 1;
        return lead;
    }
    

    Also you should override Equals method for Lead instances comparison:

    public class Lead
    {
       // your current code here
    
       public override bool Equals(object obj)
       {
           Lead other = obj as Lead;
           if (other == null)
               return false;
    
           return other.parent_FirstName == parent_FirstName &&
                  other.parent_LastName == parent_LastName &&
                  // compare other properties here
                  other.AgentID == AgentID;
       }
    
       // also override GetHashCode method
    }
    

    BTW Why you don’t pass Lead object to your action method (via POST message)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing some a django project / app that initiates some test
I'm writing an iPhone App that relies on getting the device location. Management have
I'm writing an app that stores the location of the places you have been
I have been writing a web app for some time now for Google App
I have been writing a C# app that works fine on Windows. It controls
I'm writing an app that monitors the user's location. I have a CLLocationManager object
I have an iPhone app that I am writing and it has 2 targets
I have the following section of code in an app that I am writing:
I'm writing a simple web app in PHP that needs to have write access
I have a 32bit iMac that I am writing an iPhone app in Xcode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.