Last active
August 29, 2015 14:22
-
-
Save christopherbauer/915c6043f8d19d9d631f to your computer and use it in GitHub Desktop.
Mocking IHttpRequestContext for Unit Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class when_removing_a_coupon | |
{ | |
[Test] | |
public void then_should_remove_the_coupon_from_the_session() | |
{ | |
// Arrange | |
var httpSessionStateBase = new Mock<HttpSessionStateBase>(); | |
var coupons = new Dictionary<int, Coupon>(); | |
httpSessionStateBase.SetupGet(session => session["PendingBuyerCoupons"]) | |
.Returns(buyerCoupons); | |
var httpRequestContext = new Mock<IHttpRequestContext>(); | |
httpRequestContext.SetupGet(context => context.Session).Returns(httpSessionStateBase.Object); | |
var service = new SessionDataService(httpRequestContext.Object); | |
var coupon = new Coupon {DigitalCouponId = 1}; | |
service.AddCoupon(coupon); | |
// Act | |
service.RemoveCoupon(coupon); | |
// Assert | |
Assert.That(coupons.Count, Is.EqualTo(0)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment