public void Init() { _repoUser = new RepoModel.User { FirstName = "Firstname", LastName = "Lastname", UserId = Guid.NewGuid(), UserLogin = new RepoModel.UserLogin { Username = "******", Password = "******", Token = "1234564asd4987das65d4as65d4sa6d5132s1gfd5g1" } }; _apiUser = new UserRepoToApi().MapToDestination(_repoUser); _apiUser.UserLogin.Password = "******"; var logFactory = LoggerFactory.Create(builder => builder.AddConsole()); _log = logFactory.CreateLogger <UserController>(); //Mock _mockActService = new Mock <IActionService>(); _mockActService.Setup(s => s.ProcessAction <RegistrationAction>(It.IsAny <ApiModel.User>())) .Returns((ApiModel.User user) => { if (user == null) { return(Task.FromResult <object>(null)); } //Simulates an exception if (user.UserLogin == null) { throw new NullReferenceException("Test Throw Null Exception from RegistrationAction. Parameter cannot be null."); } //Simulates an invalid user if (user.UserLogin.Username == "UserExists") { return(Task.FromResult <object>(new Result { ErrorCode = ErrorCode.UserAlreadyExists, StatusCode = StatusCode.Failed, StatusDetail = "Test Invalid Username" })); } return(Task.FromResult <object>(_repoUser)); }); }
public void Init() { _userApi = new ApiModel.User { FirstName = "Firstname", LastName = "Lastname", UserId = Guid.NewGuid(), UserLogin = new ApiModel.UserLogin { Username = "******", Password = "******", Token = "1234564asd4987das65d4as65d4sa6d5132s1gfd5g1" } }; _userRepo = new UserApiToRepo().MapToDestination(_userApi); _mockValManager = new Mock <IValidatorManager <object, RepoModel.User> >(); }
public void Init() { _userApi = new ApiModel.User { FirstName = "Firstname", LastName = "Lastname", UserId = Guid.NewGuid(), UserLogin = new ApiModel.UserLogin { Username = "******", Password = "******", Token = "1234564asd4987das65d4as65d4sa6d5132s1gfd5g1" } }; _userRepo = new UserApiToRepo().MapToDestination(_userApi); var logFactory = LoggerFactory.Create(builder => builder.AddConsole()); _log = logFactory.CreateLogger <LoginAction>(); //Mock _mockRepositoryTrue = new Mock <IUserRepository>(); _mockRepositoryTrue.Setup(x => x.GetItemAsync(It.IsAny <Expression <Func <RepoModel.User, bool> > >())).Returns(Task.FromResult(_userRepo)); _mockRepositoryTrue.Setup(x => x.UpdateItemAsync(It.IsAny <RepoModel.User>(), It.IsAny <Expression <Func <RepoModel.User, string> > >(), It.IsAny <string>())).Returns(Task.FromResult(true)); _mockRepositoryFalse = new Mock <IUserRepository>(); _mockRepositoryFalse.Setup(x => x.GetItemAsync(It.IsAny <Expression <Func <RepoModel.User, bool> > >())).Returns(Task.FromResult(_userRepo)); _mockRepositoryFalse.Setup(x => x.UpdateItemAsync(It.IsAny <RepoModel.User>(), It.IsAny <Expression <Func <RepoModel.User, string> > >(), It.IsAny <string>())).Returns(Task.FromResult(false)); _mockUsService = new Mock <IUserService>(); _mockUsService.Setup(s => s.Authenticate(It.IsAny <RepoModel.User>(), true)) .Returns((RepoModel.User user, bool isRegistered) => user.UserLogin.Username != "InvalidToken" ? _userRepo.UserLogin.Token : TokenResultTest); _mockValManager = new Mock <IValidatorManager <LoginValidator, RepoModel.User> >(); _mockValManager.Setup(m => m.GetValidatorsResult(It.IsAny <RepoModel.User>())) .Returns(Task.FromResult(It.IsAny <IEnumerable <Func <Result> > >())); _mockValService = new Mock <IValidationService>(); _mockValService.Setup(v => v.ProcessValidation(_mockValManager.Object, It.IsAny <RepoModel.User>())) .Returns(Task.FromResult((object)_userRepo)); }
public void Init() { _apiUser = new ApiModel.User { FirstName = "Firstname", LastName = "Lastname", UserId = Guid.NewGuid(), UserLogin = new ApiModel.UserLogin { Username = "******", Password = "******" } }; new UserApiToRepo().MapToDestination(_apiUser); _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() }; _repoPayment = new PaymentApiToRepo().MapToDestination(_apiPayment); var logFactory = LoggerFactory.Create(builder => builder.AddConsole()); _log = logFactory.CreateLogger <ProcessPaymentAction>(); //Mock _mockRepoTrue = new Mock <IPaymentRepository>(); _mockRepoTrue.Setup(r => r.AddItemAsync(It.IsAny <RepoModel.Payment>())).Returns(Task.FromResult(true)); _mockRepoFalse = new Mock <IPaymentRepository>(); _mockRepoFalse.Setup(r => r.AddItemAsync(It.IsAny <RepoModel.Payment>())).Returns(Task.FromResult(false)); _mockValManager = new Mock <IValidatorManager <PaymentValidator, RepoModel.Payment> >(); _mockValManager.Setup(m => m.GetValidatorsResult(It.IsAny <RepoModel.Payment>())) .Returns(Task.FromResult(It.IsAny <IEnumerable <Func <Result> > >())); _mockValService = new Mock <IValidationService>(); _mockValService.Setup(v => v.ProcessValidation(_mockValManager.Object, It.IsAny <RepoModel.Payment>())) .Returns(Task.FromResult((object)_repoPayment)); _mockBankProcessorObj = new Mock <IBankProcessor>(); _mockBankProcessorObj.Setup(b => b.Process(It.IsAny <RepoModel.Payment>())) .Returns(Task.FromResult((object)_repoPayment)); _mockBankProcessorEx = new Mock <IBankProcessor>(); _mockBankProcessorEx.Setup(b => b.Process(It.IsAny <RepoModel.Payment>())) .Returns(Task.FromResult((object)new Exception("Test return exception."))); }