示例#1
0
        /// <summary>
        /// Handles the CustomerSignupCommand.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(CustomerSignupCommand command)
        {
            InfoAccumulator info = ValidateSignupCommand(command);

            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            //TODO: code below contains race condition. We should find a way to validate to do it properly

            if (!BrokerQueries.IsExistsBroker(command.EmailAddress))
            {
                Log.ErrorFormat("Attempt to sign in customer with email of broker: {0}", command.EmailAddress);
                info.AddError("Sign-up error");
                SendReply(info, command);
                return;
            }

            SecurityUser user;

            try {
                user = CustomerQueries.CreateSecurityUser(command.EmailAddress, command.Password, command.SequrityQuestionId ?? 0, command.SecurityQuestionAnswer, command.CommandOriginatorIP);
            } catch (SqlException ex) {
                Log.ErrorFormat("Attempt to sign in existing customer: {0}", command.EmailAddress);
                info.AddError("Sign-up error");
                SendReply(info, command);
                return;
            }



            Customer customer = ConvertToCustomer(command, user);
            int      id       = (int)CustomerQueries.UpsertCustomer(customer);

            if (id < 1)
            {
                Log.ErrorFormat("could not create customer of user: "******"could not create customer");
            }

            string encryptedCustomerId = CustomerIdEncryptor.EncryptCustomerId(customer.Id, command.CommandOriginator);

            SendReply(info, command, response => response.CustomerId = encryptedCustomerId);
        }
示例#2
0
        public void TestFullSignUp()
        {
            IContainer container = InitContainer(typeof(CustomerProcessor));

            var customerSignUp = container.GetInstance <CustomerProcessor>();


            string passwordString = GetRandomPassword();
            string emailAddress   = GetRandomEmailAddress();

            var loginInfo = new LoginInfo()
            {
                Password           = new Password(passwordString, passwordString),
                Email              = emailAddress,
                PasswordAnswer     = "bbbb",
                RemoteIp           = "111.111.111.111",
                PasswordQuestionId = 1
            };

            Customer customer = new Customer {
                Name             = emailAddress,
                Id               = GetRundomInteger(2000, int.MaxValue),
                Status           = CustomerStatus.Registered.ToString(),
                RefNumber        = GetRandomPassword(),
                WizardStep       = (int)WizardStepType.SignUp,
                CollectionStatus = (int)CollectionStatusNames.Enabled,
                IsTest           = true,
                IsOffline        = null,
                PromoCode        = "lalala",
                PersonalInfo     =
                {
                    MobilePhone         = "123456789",
                    MobilePhoneVerified = false,
                    FirstName           = GenerateName(),
                    Surname             = GenerateName(),
                    MaritalStatus       = EzBobModels.Enums.MaritalStatus.Married,
                    Gender      = Gender.M,
                    DateOfBirth = DateTime.Today
                },
                TrustPilotStatusID   = (int)TrustPilotStauses.Neither,
                GreetingMailSentDate = DateTime.UtcNow,
                Vip             = false,
                WhiteLabelId    = null,
                BrokerID        = null,
                GoogleCookie    = "kind of google cookie",
                ReferenceSource = "lalalalala",
                AlibabaId       = null,
                IsAlibaba       = false,
                OriginID        = 1
            };

            CampaignSourceRef campaignSourceRef = new CampaignSourceRef()
            {
                RSource = "Direct",
                RDate   = DateTime.UtcNow
            };

            decimal requestedLoan = 10000;
            //TODO: update test for customer address and customer phone (two last nulls)
            var infoAccumulator = customerSignUp.UpdateCustomer(customer, requestedLoan, customer.ReferenceSource, GenerateVisitTimesString(), campaignSourceRef, null, null);

            Assert.False(infoAccumulator.HasErrors, "expected no errors");


            CustomerQueries realCustomerQueries = new CustomerQueries("Server=localhost;Database=ezbob;User Id=ezbobuser;Password=ezbobuser;MultipleActiveResultSets=true");

            var customerQueriesMock = new Mock <ICustomerQueries>();
//            customerQueriesMock.SetupAllProperties();

            Func <string, string, int, string, string, SecurityUser> createUser = (s1, s2, i, s3, s4) => realCustomerQueries.CreateSecurityUser(s1, s2, i, s3, s4);

            customerQueriesMock.Setup(o => o.CreateSecurityUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(),
                                                                It.IsAny <string>(), It.IsAny <string>()))
            .Returns(createUser);

            customerQueriesMock.Setup(o => o.UpsertCustomer(It.IsAny <Customer>()))
            .Returns(() => null);

            container.Configure(r => r.ForSingletonOf <ICustomerQueries>()
                                .Use(() => customerQueriesMock.Object));

            container.EjectAllInstancesOf <CustomerProcessor>();

            customerSignUp = container.GetInstance <CustomerProcessor>();

            //TODO: update test for customer address and customer phone (two last nulls)
            infoAccumulator = customerSignUp.UpdateCustomer(customer, requestedLoan, customer.ReferenceSource, GenerateVisitTimesString(), campaignSourceRef, null, null);
            Assert.True(infoAccumulator.HasErrors, "expected to have errors");
        }