예제 #1
0
        public async Task ValidCustomerRegistrationCallsUnitOfWorkAndReturnsCorrectCustomerId()
        {
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var request        = new CustomerRegistrationRequest
            {
                FirstName    = "Bob",
                Surname      = "Smith",
                DateOfBirth  = new DateTime(2000, 1, 1),
                EmailAddress = "*****@*****.**",
                PolicyNumber = "AB-123456"
            };

            unitOfWorkMock.Setup(a => a.CustomerCustomerRegistrations.Add(It.Is <CustomerRegistration>(
                                                                              registration => registration.FirstName == request.FirstName && registration.Surname == request.Surname &&
                                                                              registration.DateOfBirth == request.DateOfBirth && registration.EmailAddress == request.EmailAddress &&
                                                                              registration.PolicyNumber == request.PolicyNumber)))
            .Callback <CustomerRegistration>(r => r.Id = 101);

            var service = new CustomerRegistrationService(unitOfWorkMock.Object, new CustomerRegistrationRequestValidator());

            var result = await service.Register(request);

            result.IsSuccessful.Should().BeTrue();
            result.CustomerId.Should().Be(101);
            result.ValidationMessages.Length.Should().Be(0);
        }
        public void RegisterCustomer_happycase_returns_successfull_response()
        {
            var sut = new CustomerRegistrationService(_repo, _gateway);

            Dtos.CreateCustomerRequest request = new Dtos.CreateCustomerRequest {
                Name = "Foo"
            };

            var response = sut.RegisterCustomer(request);

            response.IsSuccess.Should().BeTrue("because we are in the happy case");
        }
 public CustomerController(CustomerRegistrationService CustomerRegistrationService, IEmailService emailService, IMobileService MobileService, UsersService UsersService, IConfiguration configuration, OTPAuthenticationService OTPAuthenticationService, MerchantService MerchantService, NaqelUsersService NaqelUsersService, LookupTypeValuesService LookupTypeValuesService)
 {
     _CustomerRegistrationService = CustomerRegistrationService;
     _emailService             = emailService;
     _UsersService             = UsersService;
     _configuration            = configuration;
     _OTPAuthenticationService = OTPAuthenticationService;
     _MerchantService          = MerchantService;
     _NaqelUsersService        = NaqelUsersService;
     _MobileService            = MobileService;
     _LookupTypeValuesService  = LookupTypeValuesService;
 }
예제 #4
0
 public CommandHandler(
     CustomerService customerService,
     CarService carService,
     CustomerRegistrationService customerRegistrationService,
     RentalService rentalService
     )
 {
     CustomerService             = customerService;
     CarService                  = carService;
     CustomerRegistrationService = customerRegistrationService;
     RentalService               = rentalService;
 }
        public void RegisterCustomer_with_failing_repository_returns_failure_response()
        {
            var sut = new CustomerRegistrationService(_repo, _gateway);

            Dtos.CreateCustomerRequest request = new Dtos.CreateCustomerRequest {
                Name = "Foo"
            };

            _repo.RegisterCustomerTwo(Arg.Any <string>()).Returns(Result.Fail <Customer>("new Customer()"));
            var response = sut.RegisterCustomer(request);

            response.IsSuccess.Should().BeFalse("because we are NOT in the happy case");
        }
예제 #6
0
        static void Main(string[] args)
        {
            IServiceCollection serviceCollection = new ServiceCollection();

            CompositionRoot.ComposeApplication(serviceCollection);

            IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            CustomerRegistrationService service = serviceProvider.GetService <CustomerRegistrationService>();

            service.Register(new CustomerDTO());

            Console.ReadLine();
        }
 public AdminController(CustomerRegistrationService customerRegistrationService,
                        UsersService usersService, IConfiguration configuration,
                        NaqelUsersService naqelUsersService, MerchantService merchantService, IEmailService emailService, LookupTypeValuesService lookupTypeValuesService, AdminPromotionalService AdminPromotionalService, AdminPromotionalCountriesService AdminPromotionalCountriesService)
 {
     _customerRegistrationService = customerRegistrationService;
     _usersService                     = usersService;
     _naqelUsersService                = naqelUsersService;
     _merchantService                  = merchantService;
     _emailService                     = emailService;
     _configuration                    = configuration;
     _lookupTypeValuesService          = lookupTypeValuesService;
     _AdminPromotionalService          = AdminPromotionalService;
     _AdminPromotionalCountriesService = AdminPromotionalCountriesService;
 }
 public PaymentController(ICheckoutApi checkoutApi, ISerializer serializer,
                          WalletHistoryService walletHistoryService, UsersService usersService, IOptions <AppSettings> appSettings,
                          PaymentCardsService paymentCardsService,
                          PaymentResponseService paymentResponseService, CustomerRegistrationService customerService)
 {
     _checkoutApi            = checkoutApi ?? throw new ArgumentNullException(nameof(checkoutApi));
     _serializer             = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _walletHistoryService   = walletHistoryService;
     _usersService           = usersService;
     _appSettings            = appSettings.Value;
     _paymentCardsService    = paymentCardsService;
     _paymentResponseService = paymentResponseService;
     _customerService        = customerService;
 }
예제 #9
0
        public void TestMethod1()
        {
            Mock <ICustomerRepository> customerRepo = new Mock <ICustomerRepository>();
            bool isInsertCalled = false;

            customerRepo.Setup(x => x.Insert(It.IsAny <Customer>(), It.IsAny <CancellationToken>()))
            .Callback(() => {
                isInsertCalled = true;
                Console.WriteLine("Dummy mock");
            });
            CustomerRegistrationService service = new CustomerRegistrationService(customerRepo.Object);

            service.Register(new CustomerDTO());

            Assert.IsTrue(isInsertCalled, "isInsertCalled false");
        }
예제 #10
0
        public async Task InvalidCustomerRegistrationRequestReturnsErrors()
        {
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var service        = new CustomerRegistrationService(unitOfWorkMock.Object, new CustomerRegistrationRequestValidator());
            var request        = new CustomerRegistrationRequest();
            var result         = await service.Register(request);

            result.IsSuccessful.Should().BeFalse();
            result.CustomerId.Should().BeNull();
            result.ValidationMessages.Length.Should().Be(4);

            result.ValidationMessages[0].Property.Should().Be("FirstName");
            result.ValidationMessages[0].Message.Should().Be("'First Name' must not be empty.");

            result.ValidationMessages[1].Property.Should().Be("Surname");
            result.ValidationMessages[1].Message.Should().Be("'Surname' must not be empty.");

            result.ValidationMessages[2].Property.Should().Be("PolicyNumber");
            result.ValidationMessages[2].Message.Should().Be("'Policy Number' must not be empty.");

            result.ValidationMessages[3].Property.Should().Be("");
            result.ValidationMessages[3].Message.Should().Be("'Date Of Birth' or 'Email Address' must not be empty.");
        }
 public NaqelController(NaqelServices NaqelServices, OrdersService OrdersService, MerchantContractService MerchantContractService, MerchantRequestService MerchantRequestService, MerchantService MerchantService, MerchantRedirectionService MerchantRedirectionService, LookupTypeService LookupTypeService, NaqelUsersService naqelUsersService,
                        IConfiguration configuration, IEmailService emailService, WalletHistoryService WalletHistoryService, PaymentResponseService PaymentResponseService,
                        MerchantCatalogService MerchantCatalogService, CategoryService CategoryService, MerchantRequestDetailsService MerchantRequestDetailsService,
                        CustomerRegistrationService CustomerRegistrationService, MerchantAccountDetailsService MerchantAccountDetailsService)
 {
     _NaqelServices              = NaqelServices;
     _OrdersService              = OrdersService;
     _MerchantContractService    = MerchantContractService;
     _MerchantRequestService     = MerchantRequestService;
     _MerchantService            = MerchantService;
     _MerchantRedirectionService = MerchantRedirectionService;
     _LookupTypeService          = LookupTypeService;
     _naqelUsersService          = naqelUsersService;
     _configuration              = configuration;
     _emailService                  = emailService;
     _WalletHistoryService          = WalletHistoryService;
     _PaymentResponseService        = PaymentResponseService;
     _MerchantCatalogService        = MerchantCatalogService;
     _CategoryService               = CategoryService;
     _MerchantRequestDetailsService = MerchantRequestDetailsService;
     _CustomerRegistrationService   = CustomerRegistrationService;
     _MerchantAccountDetailsService = MerchantAccountDetailsService;
 }
예제 #12
0
        public void SetUp()
        {
            _restfullClientMock = new Mock <IRestfulClient>();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <SaveCustomerVehicleRequest, Customer>()
                .ForMember(dest => dest.CustomerNo, opt => opt.ResolveUsing(src => src.CustomerNo));
                cfg.CreateMap <SaveCustomerVehicleRequest, CustomerVehicle>();
                cfg.CreateMap <Customer, RegisterCustomerRequest>()
                .ForMember(dest => dest.RoofTopId, opt => opt.ResolveUsing(src => src.RooftopId))
                .ForMember(dest => dest.EmailAddress, opt => opt.ResolveUsing(src => src.CustomerEmail));
                cfg.CreateMap <CustomerVehicle, RegisterCustomerRequest>()
                .ForMember(dest => dest.RegistrationNumber, opt => opt.ResolveUsing(src => src.RegistrationNo))
                .ForMember(dest => dest.VehicleId, opt => opt.ResolveUsing(src => src.VehicleNo));
                cfg.CreateMap <Customer, VerifyCustomerRequest>()
                .ForMember(dest => dest.RoofTopId, opt => opt.ResolveUsing(src => src.RooftopId));
            });

            _mapper = config.CreateMapper();

            _underTest =
                new CustomerRegistrationService(_mapper, _restfullClientMock.Object, null);
        }
예제 #13
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin");

            if (allowedOrigin == null)
            {
                allowedOrigin = "*";
            }

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });


            CustomerRegistrationService = CustomerRegistrationService ?? AutofacLifetimeScope.Resolve <ICustomerRegistrationService>(context.OwinContext);
            CustomerService             = CustomerService ?? AutofacLifetimeScope.Resolve <ICustomerService>(context.OwinContext);

            Customer customer         = CustomerService.GetCustomerByEmail(context.UserName);
            var      validationResult = CustomerRegistrationService.ValidateCustomer(context.UserName, context.Password);

            if (validationResult != CustomerLoginResults.Successful)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }
            //var unitofWork = AutofacLifetimeScope.Resolve<Data.Infrastructure.IUnitOfWork>(context.OwinContext);
            BaseService             = BaseService ?? AutofacLifetimeScope.Resolve <IBaseService>(context.OwinContext);
            ShoppingCartService     = ShoppingCartService ?? AutofacLifetimeScope.Resolve <IShoppingCartService>(context.OwinContext);
            CustomerActivityService = CustomerActivityService ?? AutofacLifetimeScope.Resolve <ICustomerActivityService>(context.OwinContext);

            //migrate shopping cart
            ShoppingCartService.MigrateShoppingCart(BaseService.WorkContext.CurrentCustomer, customer, true);

            //activity log
            CustomerActivityService.InsertActivity(customer, "PublicStore.Login", "Login");

            BaseService.Commit();
            //unitofWork.Commit();

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Role, string.Join(",", customer.CustomerRoles.Select(r => r.Name))));
            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
            identity.AddClaim(new Claim("sub", context.UserName));

            //context.Validated(identity);

            //new code
            var props = new AuthenticationProperties(new Dictionary <string, string>
            {
                {
                    "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId
                },
                {
                    "userName", context.UserName
                }
            });

            var ticket = new AuthenticationTicket(identity, props);


            context.Validated(ticket);

            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); // To allow CORS on the token middleware provider
        }
        public new void SetUp()
        {
            _customerSettings = new CustomerSettings
            {
                UnduplicatedPasswordsNumber = 1,
                HashedPasswordFormat        = "SHA512"
            };
            _securitySettings = new SecuritySettings
            {
                EncryptionKey = "273ece6f97dd844d"
            };
            _rewardPointsSettings = new RewardPointsSettings
            {
                Enabled = false
            };

            _encryptionService = new EncryptionService(_securitySettings);
            _customerRepo      = new Mock <IRepository <Customer> >();

            var customer1 = new Customer
            {
                Id       = 1,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            AddCustomerToRegisteredRole(customer1);

            var customer2 = new Customer
            {
                Id       = 2,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            AddCustomerToRegisteredRole(customer2);

            var customer3 = new Customer
            {
                Id       = 3,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            AddCustomerToRegisteredRole(customer3);

            var customer4 = new Customer
            {
                Id       = 4,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            AddCustomerToRegisteredRole(customer4);

            var customer5 = new Customer
            {
                Id       = 5,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            _customerRepo.Setup(x => x.Table).Returns(new List <Customer> {
                customer1, customer2, customer3, customer4, customer5
            }.AsQueryable());

            _customerPasswordRepo = new Mock <IRepository <CustomerPassword> >();
            var saltKey   = _encryptionService.CreateSaltKey(5);
            var password  = _encryptionService.CreatePasswordHash("password", saltKey, "SHA512");
            var password1 = new CustomerPassword
            {
                CustomerId     = customer1.Id,
                PasswordFormat = PasswordFormat.Hashed,
                PasswordSalt   = saltKey,
                Password       = password,
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password2 = new CustomerPassword
            {
                CustomerId     = customer2.Id,
                PasswordFormat = PasswordFormat.Clear,
                Password       = "******",
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password3 = new CustomerPassword
            {
                CustomerId     = customer3.Id,
                PasswordFormat = PasswordFormat.Encrypted,
                Password       = _encryptionService.EncryptText("password"),
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password4 = new CustomerPassword
            {
                CustomerId     = customer4.Id,
                PasswordFormat = PasswordFormat.Clear,
                Password       = "******",
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password5 = new CustomerPassword
            {
                CustomerId     = customer5.Id,
                PasswordFormat = PasswordFormat.Clear,
                Password       = "******",
                CreatedOnUtc   = DateTime.UtcNow
            };

            _customerPasswordRepo.Setup(x => x.Table).Returns(new[] { password1, password2, password3, password4, password5 }.AsQueryable());

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _storeService                  = new Mock <IStoreService>();
            _customerRoleRepo              = new Mock <IRepository <CustomerRole> >();
            _genericAttributeRepo          = new Mock <IRepository <GenericAttribute> >();
            _shoppingCartRepo              = new Mock <IRepository <ShoppingCartItem> >();
            _genericAttributeService       = new Mock <IGenericAttributeService>();
            _newsLetterSubscriptionService = new Mock <INewsLetterSubscriptionService>();
            _rewardPointService            = new Mock <IRewardPointService>();

            _localizationService             = new Mock <ILocalizationService>();
            _workContext                     = new Mock <IWorkContext>();
            _workflowMessageService          = new Mock <IWorkflowMessageService>();
            _customerCustomerRoleMappingRepo = new Mock <IRepository <CustomerCustomerRoleMapping> >();

            _customerService = new CustomerService(new CustomerSettings(),
                                                   new TestCacheManager(),
                                                   null,
                                                   null,
                                                   _eventPublisher.Object,
                                                   _genericAttributeService.Object,
                                                   _customerRepo.Object,
                                                   _customerCustomerRoleMappingRepo.Object,
                                                   _customerPasswordRepo.Object,
                                                   _customerRoleRepo.Object,
                                                   _genericAttributeRepo.Object,
                                                   _shoppingCartRepo.Object,
                                                   new TestCacheManager(),
                                                   null);

            _customerRegistrationService = new CustomerRegistrationService(_customerSettings,
                                                                           _customerService,
                                                                           _encryptionService,
                                                                           _eventPublisher.Object,
                                                                           _genericAttributeService.Object,
                                                                           _localizationService.Object,
                                                                           _newsLetterSubscriptionService.Object,
                                                                           _rewardPointService.Object,
                                                                           _storeService.Object,
                                                                           _workContext.Object,
                                                                           _workflowMessageService.Object,
                                                                           _rewardPointsSettings);
        }
예제 #15
0
        public void ReadCallback(IAsyncResult ar)
        {
            String content = String.Empty;
            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            // Read data from the client socket.
            int bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                // There might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(
                                    state.buffer, 0, bytesRead));

                // Check for end-of-file tag. If it is not there, read
                // more data.
                content = state.sb.ToString();
                //var nc = new CultureInfo(state.sb.ToString(), true);
                if (content.IndexOf("#") > -1)
                {
                    // All the data has been read from the
                    // client. Display it on the console.
                    Trace.Write("Read " + content.Length + " bytes from socket. \n Data : " + content, "Information");
                    // Echo the data back to the client.

                    string output = null;

                    if (content.Contains('?') == false)
                    {
                    }
                    else
                    {
                        RunTerminalTransactions terminalTransaction  = new RunTerminalTransactions();
                        RunCustomerRegistration customerRegistration = new RunCustomerRegistration();

                        var input        = content.Split('?');
                        var inputRequest = Convert.ToInt64(input[0]);

                        switch (inputRequest)
                        {
                        case 5001:
                        case 5002:
                        case 5003:
                        case 5004:
                            output = terminalTransaction.RunTransaction(content);
                            break;

                        case 5100:
                            output = customerRegistration.NFCCustomerRegistration(content);
                            break;

                        case 5101:
                            output = customerRegistration.NFCCustomerRegistration(content);
                            break;

                        default:
                            break;
                        }
                    }
                    CustomerRegistrationService cr = new CustomerRegistrationService();
                    //writer.WriteLine("Role ID: " + RoleEnvironment.CurrentRoleInstance.Id + " Connection ID: " + clientId.ToString() + "Status " + status.ToString());
                    Send(handler, output.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                         new AsyncCallback(ReadCallback), state);
                }
            }
        }
        public CustomerRegistrationServiceTests()
        {
            #region customers
            var customer1 = new Customer
            {
                Id       = 1,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };
            var customer2 = new Customer
            {
                Id       = 2,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };
            var customer3 = new Customer
            {
                Id       = 3,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };
            var customer4 = new Customer
            {
                Id       = 4,
                Username = "******",
                Email    = "*****@*****.**",
                Active   = true
            };

            #endregion

            #region passwords
            _securitySettings = new SecuritySettings
            {
                EncryptionKey = "273ece6f97dd844d"
            };

            _encryptionService = new EncryptionService(_securitySettings);

            var saltKey   = _encryptionService.CreateSaltKey(5);
            var password  = _encryptionService.CreatePasswordHash("password", saltKey, "SHA512");
            var password1 = new CustomerPassword
            {
                CustomerId     = customer1.Id,
                PasswordFormat = PasswordFormat.Hashed,
                PasswordSalt   = saltKey,
                Password       = password,
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password2 = new CustomerPassword
            {
                CustomerId     = customer2.Id,
                PasswordFormat = PasswordFormat.Clear,
                Password       = "******",
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password3 = new CustomerPassword
            {
                CustomerId     = customer3.Id,
                PasswordFormat = PasswordFormat.Encrypted,
                Password       = _encryptionService.EncryptText("password"),
                CreatedOnUtc   = DateTime.UtcNow
            };
            var password4 = new CustomerPassword
            {
                CustomerId     = customer4.Id,
                PasswordFormat = PasswordFormat.Clear,
                Password       = "******",
                CreatedOnUtc   = DateTime.UtcNow
            };
            #endregion

            _customerRoleRepo = _fakeDataStore.RegRepository(new[]
            {
                new CustomerRole
                {
                    Id           = 1,
                    Active       = true,
                    IsSystemRole = true,
                    SystemName   = NopCustomerDefaults.RegisteredRoleName
                }
            });
            _customerRepo         = _fakeDataStore.RegRepository(new[] { customer1, customer2, customer3, customer4 });
            _customerPasswordRepo = _fakeDataStore.RegRepository(new[] { password1, password2, password3, password4 });
            _customerCustomerRoleMappingRepository = _fakeDataStore.RegRepository <CustomerCustomerRoleMapping>();

            _customerService = new FakeCustomerService(
                customerCustomerRoleMappingRepository: _customerCustomerRoleMappingRepository,
                customerRepository: _customerRepo,
                customerPasswordRepository: _customerPasswordRepo,
                customerRoleRepository: _customerRoleRepo);

            //AddCustomerToRegisteredRole(customer1);
            //AddCustomerToRegisteredRole(customer2);
            //AddCustomerToRegisteredRole(customer3);
            //AddCustomerToRegisteredRole(customer4);

            _rewardPointsSettings = new RewardPointsSettings
            {
                Enabled = false
            };

            _customerSettings = new CustomerSettings
            {
                UnduplicatedPasswordsNumber = 1,
                HashedPasswordFormat        = "SHA512"
            };

            _storeService = new Mock <IStoreService>();

            _genericAttributeService       = new Mock <IGenericAttributeService>();
            _newsLetterSubscriptionService = new Mock <INewsLetterSubscriptionService>();
            _rewardPointService            = new Mock <IRewardPointService>();

            _localizationService    = new Mock <ILocalizationService>();
            _workContext            = new Mock <IWorkContext>();
            _workflowMessageService = new Mock <IWorkflowMessageService>();

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            _customerRegistrationService = new CustomerRegistrationService(_customerSettings,
                                                                           _customerService,
                                                                           _encryptionService,
                                                                           _eventPublisher.Object,
                                                                           _genericAttributeService.Object,
                                                                           _localizationService.Object,
                                                                           _newsLetterSubscriptionService.Object,
                                                                           _rewardPointService.Object,
                                                                           _storeService.Object,
                                                                           _workContext.Object,
                                                                           _workflowMessageService.Object,
                                                                           _rewardPointsSettings);
        }