Exemplo n.º 1
0
        public void PaymentValidator_AggregateException()
        {
            //Mock
            var mock = new Mock <IUserRepository>();

            mock.Setup(x => x.GetItemAsync(null)).Returns(Task.FromResult <User>(null));
            //Arrange
            var manager = new PaymentValidator(mock.Object, _log);

            //Act and Assert
            Assert.ThrowsException <AggregateException>(() => manager.GetValidatorsResult(new Payment()).Result, "CardDetails property is null. Invalid value.");
        }
Exemplo n.º 2
0
        public void PaymentValidator_InvalidCardNumber_Success()
        {
            //Mock
            var mock = new Mock <IUserRepository>();

            mock.Setup(x => x.GetItemAsync(It.IsAny <Expression <Func <User, bool> > >())).Returns(Task.FromResult(_user));
            //Arrange
            var manager = new PaymentValidator(mock.Object, _log);
            //Act
            var list = manager.GetValidatorsResult(_payment).Result.ToList();

            //Assert
            Assert.IsTrue(manager.ReturnObject != null);
            Assert.IsTrue(list.Any());
            foreach (var result in list.Select(item => item.Invoke()).Where(x => x.StatusCode == StatusCode.Failed))
            {
                Assert.IsTrue(result.StatusCode == StatusCode.Failed);
                Assert.AreEqual(result.ErrorCode, ErrorCode.InvalidCardNumber);
            }
        }
Exemplo n.º 3
0
        public void PaymentValidator_Success()
        {
            //Mock
            var mock = new Mock <IUserRepository>();

            mock.Setup(x => x.GetItemAsync(It.IsAny <Expression <Func <User, bool> > >())).Returns(Task.FromResult(_user));
            //Arrange
            var manager = new PaymentValidator(mock.Object, _log);

            _payment.CardDetails.CardNumber = ValidCardNumber;
            //Act
            var list = manager.GetValidatorsResult(_payment).Result.ToList();

            //Assert
            Assert.IsTrue(manager.ReturnObject != null);
            Assert.IsTrue(list.Any());
            foreach (var item in list)
            {
                Assert.IsTrue(item.Invoke().StatusCode == StatusCode.Success);
            }
        }