public async Task CanRedeemCoupon_NullEvaluator_ArgumentNullException() { var couponManager = new CouponManager(_logger, _couponProvider); var ex = await Assert.ThrowsAsync <ArgumentNullException>(() => couponManager.CanRedeemCoupon(new Guid(), new Guid(), null)); Assert.Equal(new ArgumentNullException("Evaluators can not be null").Message, ex.Message); }
public async Task CanRedeemCoupon_EmptyEvaluator_ReturnTrue() { _mock.Mock <ICouponProvider>().Setup(m => m.Retrieve(new Guid())).ReturnsAsync(new Coupon()); var couponManager = new CouponManager(_logger, _couponProvider); var result = await couponManager.CanRedeemCoupon(new Guid(), new Guid(), _emptyEvaluators); Assert.True(result); }
public async Task CanRedeemCoupon_NullCoupon_ArgumentNullException() { _mock.Mock <ICouponProvider>().Setup(m => m.Retrieve(new Guid())).ReturnsAsync(null as Coupon); var couponManager = new CouponManager(_logger, _couponProvider); var ex = await Assert.ThrowsAsync <KeyNotFoundException>(() => couponManager.CanRedeemCoupon(new Guid(), new Guid(), new List <Func <Coupon, Guid, bool> >())); Assert.NotStrictEqual(new KeyNotFoundException(), ex); }
public async Task EvaluatorsAreNull() { //Arrange var couponManager = new CouponManager(_fakeLogger, _fakeCouponProvider); //Act and Assert var ex = await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => couponManager.CanRedeemCoupon(Guid.NewGuid(), Guid.NewGuid(), null)); Assert.AreEqual(ex.ParamName, "evaluators"); }
public async Task NoCouponFound() { //Arrange A.CallTo(() => _fakeCouponProvider.Retrieve(Guid.NewGuid())).WithAnyArguments().Returns <Coupon>(null); var func = A.Fake <IEnumerable <Func <Coupon, Guid, bool> > >(); var couponManager = new CouponManager(_fakeLogger, _fakeCouponProvider); //Act and Assert await Assert.ThrowsExceptionAsync <KeyNotFoundException>(() => couponManager.CanRedeemCoupon(Guid.NewGuid(), Guid.NewGuid(), func)); }
public async Task WithCouponButNoEvaluator() { //Arrange var func = A.Fake <IEnumerable <Func <Coupon, Guid, bool> > >(); //Assuming a coupon is found A.CallTo(() => _fakeCouponProvider.Retrieve(Guid.NewGuid())).WithAnyArguments().Returns <Coupon>(new Coupon()); //Act var couponManager = new CouponManager(_fakeLogger, _fakeCouponProvider); var result = await couponManager.CanRedeemCoupon(Guid.NewGuid(), Guid.NewGuid(), func); //Assert Assert.IsTrue(result); }
public async Task WithCouponButFailingEvaluation() { //Arrange var fakeFuncs = A.CollectionOfFake <Func <Coupon, Guid, bool> >(10); //Assuming a coupon is found A.CallTo(() => _fakeCouponProvider.Retrieve(Guid.NewGuid())).WithAnyArguments().Returns <Coupon>(new Coupon()); foreach (var fakeFunc in fakeFuncs) { //Assuming all the evaluators resulted to false A.CallTo(() => fakeFunc.Invoke(new Coupon(), Guid.NewGuid())).Returns(false); } //Act var couponManager = new CouponManager(_fakeLogger, _fakeCouponProvider); var result = await couponManager.CanRedeemCoupon(Guid.NewGuid(), Guid.NewGuid(), fakeFuncs.AsEnumerable()); //Assert Assert.IsFalse(result); }