public Dictionary <String, String> BuyCdInStock(string cdTitle, string cdArtist, int chartPosition, int stock, double price, string cardNumber, string expiry, string securityCode, bool paymentAccepted) { var mockPayments = new Mock <IPayments>(); double chargedPrice = 1.0; string chargedCardNumber = null; mockPayments.Setup(payments => payments.Charge(It.IsAny <double>(), It.IsAny <string>(), expiry, securityCode)).Returns(paymentAccepted) .Callback <double, string, string, string>((actualChargedPrice, actualCardNumber, actualExpiry, actualSecurityCode) => { chargedPrice = actualChargedPrice; chargedCardNumber = actualCardNumber; }); var mockCharts = new Mock <ICharts>(); string chartNotification = null; mockCharts.Setup(charts => charts.Notify(It.IsAny <string>())).Callback <string>(message => chartNotification = message); var sut = new CD(cdTitle, cdArtist, chartPosition, price, stock, mockPayments.Object, mockCharts.Object); sut.Buy(cardNumber, expiry, securityCode); return(new Dictionary <String, String> { { "endStock", sut.Stock.ToString(CultureInfo.InvariantCulture) }, { "chargedPrice", chargedPrice.ToString(CultureInfo.InvariantCulture) }, { "chargedCardNumber", chargedCardNumber }, { "chartNotification", chartNotification } }); }
public void the_customer_buys_that_CD(double price) { string cdTitle = "So"; string cdArtist = "Peter Gabriel"; sut = new CD(cdTitle, cdArtist, chartPosition, price, stock, mockPayments.Object, mockCharts.Object); string cardNumber = "1234234534564567"; string expiry = "10/21"; string securityCode = "817"; mockPayments.Setup(payments => payments.Charge(It.IsAny <double>(), It.IsAny <string>(), expiry, securityCode)).Returns(paymentAccepted) .Callback <double, string, string, string>((actualChargedPrice, actualCardNumber, actualExpiry, actualSecurityCode) => { chargedPrice = actualChargedPrice; }); sut.Buy(cardNumber, expiry, securityCode); }