public void Init() { _apiPayment = new ApiModel.Payment { CardDetails = new ApiModel.CardDetails { CardFirstname = "Firstname", CardLastname = "Lastname", CardNumber = "1234567894567896", Cvv = "123", ExpiryDateMonth = 10, ExpiryDateYear = 2025, Type = "mastercard" }, Created = DateTime.Now, Details = "Payment Test", PaymentId = Guid.NewGuid(), Price = new ApiModel.Price { Amount = 100, Currency = "EUR" }, ProductId = "123ABC_TEST1", ProductName = "Product Test", UserId = Guid.NewGuid() }; _filter = new ApiModel.PaymentsFilter { UserId = _apiPayment.UserId.ToString(), StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1) }; _repoPayment = new PaymentApiToRepo().MapToDestination(_apiPayment); var payments = new List <RepoModel.Payment> { _repoPayment }; var logFactory = LoggerFactory.Create(builder => builder.AddConsole()); _log = logFactory.CreateLogger <AllPaymentsActionProvider>(); //Mock _mockRepo = new Mock <IPaymentRepository>(); _mockRepo.Setup(r => r.GetMongoQueryable()).Returns(payments.AsQueryable()); _mockValManager = new Mock <IValidatorManager <AllPaymentsValidator, CoreModel.PaymentsFilter> >(); _mockValManager.Setup(m => m.GetValidatorsResult(It.IsAny <CoreModel.PaymentsFilter>())) .Returns(Task.FromResult(It.IsAny <IEnumerable <Func <Result> > >())); _mockVaService = new Mock <IValidationService>(); _mockVaService.Setup(v => v.ProcessValidation(_mockValManager.Object, It.IsAny <CoreModel.PaymentsFilter>())) .Returns(Task.FromResult((object)payments)); }
public void Init() { _filter = new ApiModel.PaymentsFilter { UserId = "97190759-1638-42fa-abb7-1ac97111978d" }; _userId = new Guid("3fa85f64-5717-4562-b3fc-2c963f66afa6"); _repoPayment = new RepoModel.Payment { CardDetails = new RepoModel.CardDetails { CardFirstname = "Firstname", CardLastname = "Lastname", CardNumber = "1234567894567896", Cvv = "123", ExpiryDateMonth = 10, ExpiryDateYear = 2025, Type = "mastercard" }, Created = DateTime.Now, Details = "Payment Test", PaymentId = Guid.NewGuid(), Price = new RepoModel.Price { Amount = 100, Currency = "EUR" }, ProductId = "123ABC_TEST1", ProductName = "Product Test", UserId = _userId }; _apiPayment = new PaymentRepoToApi().MapToDestination(_repoPayment); _repoPayments = new List <RepoModel.Payment> { _repoPayment }; _apiPayments = new PaymentsRepoToApi().MapToDestination(_repoPayments).ToList(); var logFactory = LoggerFactory.Create(builder => builder.AddConsole()); _log = logFactory.CreateLogger <PaymentController>(); //Mock _mockActService = new Mock <IActionService>(); _mockActService.Setup(s => s.ProcessAction <AllPaymentsActionProvider>(It.IsAny <ApiModel.PaymentsFilter>())) .Returns((ApiModel.PaymentsFilter filter) => { if (filter == null) { return(Task.FromResult <object>(null)); } //Simulates an exception if (filter.ProductName == "Exception") { throw new NullReferenceException("Test Throw Null Exception from AllPaymentsActionProvider. Parameter cannot be null."); } //Simulates an invalid user if (filter.UserId.Length < 36 || filter.UserId.Length > 36) { return(Task.FromResult <object>(new Result { ErrorCode = ErrorCode.NoAuthorized, StatusCode = StatusCode.Failed, StatusDetail = "Test Invalid User ID" })); } return(Task.FromResult <object>(_repoPayments)); }); }