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 3788358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:59:10+00:00 2026-05-19T11:59:10+00:00

I spend over 2 hours on this… i can’t figure out why this test

  • 0

I spend over 2 hours on this… i can’t figure out why this test is PASSING. I mean.. it shouldnt return the view “Completed” but in the test it does! It say Expected “string.Empty” but returned “Completed” however for the creditcard to pass.. the securitycode need to be “test” which is isnt at all in the test. So it should return the default view (which is like view();).

What i am doing wrong ? it is my test that is wrong ? or the controller logic ?

Thanks a lots.


[Test]
public void Cannot_Check_Out_If_Credit_Card_Failed_To_Process()
{
 var mockOrderSubmitter = new Mock<IOrderSubmitter>();
 var mockCreditCardProcessor = new Mock<ICreditCardProcessor>();

// Arrange: Given a user has a non-empty cart
var cart = new Cart();
cart.AddItem(new Product(), 1);

// Arrange: ... but the credit card failed to process
var cartController = new CartController(null, mockOrderSubmitter.Object, mockCreditCardProcessor.Object);
var result = cartController.CheckOut(cart, new ShippingDetails(), new CreditCard() { SecurityCode = "123" });

// Assert
result.ShouldBeDefaultView();
}

[HttpPost]
public ActionResult CheckOut(Cart cart, ShippingDetails shippingDetails, CreditCard creditCard)
{
// Empty carts can't be checked out
if (cart.Lines.Count == 0)
    ModelState.AddModelError("Cart", "Sorry, your cart is empty!");

// Everything is valid
if (ModelState.IsValid)
{
    // Effectue le paiement.
    TransactionResult result = creditcardProcessor.TakePayment(creditCard, cart.ComputeTotalValue());
    if (result == TransactionResult.Success)
    {
        // Envoi la commande
        orderSubmitter.SubmitOrder(cart, shippingDetails);
        cart.Clear();
        return View("Completed");
    }
    else
    {
        ModelState.AddModelError("CreditCard", "Sorry, we couldn't process your credit card, please verify your credit card details and retry.");
        return View(new CheckOutViewModel());
    }

}
else // Something was invalid
    return View(new CheckOutViewModel());
}

public class MainCreditCardProcessor : ICreditCardProcessor
{
    public TransactionResult TakePayment(CreditCard card, decimal amount)
    {
        if (card.SecurityCode == "test")
            return TransactionResult.Success;
        else
            return TransactionResult.TransactionDeclined;
    }
}

  • 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-05-19T11:59:11+00:00Added an answer on May 19, 2026 at 11:59 am

    Found solution to this. The mocks object doesnt have any implementation. (Which i should have know before that)

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

Sidebar

Related Questions

I've spent the last several hours searching the web, and I can't figure this
I've already spent countless hours puzzling over this, utilizing Google searches and other Stack
I've spent over 6 hours on this issue by now and really need help.
After banging my head against the wall over this for the past few hours
Before I go off and spend several hours building this, I wanted to see
I've spent over three hours on this trying to work with the code I've
After several hours of working on porting this program over, it appears to finally
Hey guys, I've been bashing my head around for hours now, over this login
I have a text file that I want to send over the network, this
I have read numerous posts, spent hours going over the documents at cakephp.org and

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.