Esempio n. 1
0
        public async ValueTask Setup()
        {
            _mapper            = Resolve <IMapper>();
            _leadRepository    = Resolve <ILeadRepository>();
            _accountRepository = Resolve <IAccountRepository>();
            _systemUnderTest   = new LeadController(_leadRepository, _accountRepository, _mapper, _urlOptions);
            await DropOrRestoreTestDbs("Dbs_Restore");

            _leadForTest      = (LeadInputModel)LeadInputModelMock.leadInputModel.Clone();
            _accountIMForTest = (AccountInputModel)AccountInputModelMock.accountInputModel.Clone();

            foreach (var item in LeadInputModelMock.leadsToInsertForSearchTest)
            {
                _leadsToInsertForSearch.Add((LeadInputModel)item.Clone());
            }

            foreach (var leadModel in _leadsToInsertForSearch)
            {
                ActionResult <LeadOutputModel> leadsInsertActionResult
                    = await _systemUnderTest.AddLead(leadModel);

                LeadOutputModel outputLead = AssertAndConvert(leadsInsertActionResult);
                leadModel.Id = outputLead.Id;
                _leadsForCompare.Add(outputLead);
                _accountIMForTest.LeadId = (long)outputLead.Id;
                ActionResult <AccountOutputModel> accountForSearchActionResult = await _systemUnderTest.AddAccount(_accountIMForTest);

                var accountForSearch = AssertAndConvert(accountForSearchActionResult);
                _accountsOMForTest.Add(accountForSearch);
            }
        }
Esempio n. 2
0
        protected void DeepEqualForLeadModels(LeadInputModel inputModel, LeadOutputModel outputModel)
        {
            Assert.NotNull(outputModel.CityName);
            Assert.NotNull(outputModel.RegistrationDate);
            Assert.NotNull(outputModel.Accounts);
            var model  = mapper.Map <Lead>(inputModel);
            var model1 = mapper.Map <LeadOutputModel>(model);

            Assert.IsTrue(model1.EqualsForLeadTest(outputModel));
        }
Esempio n. 3
0
        public async Task <JsonResult> Form3([FromBody] LeadInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(model));
            }

            var reponse = await _leadService.SubmitAsync(model);

            return(Json(reponse.ReferenceNumber));
        }
Esempio n. 4
0
        public async Task <IActionResult> Form2(LeadInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var reponse = await _leadService.SubmitAsync(model);

            return(RedirectToAction(nameof(Success), new { reference = reponse.ReferenceNumber }));
        }
Esempio n. 5
0
        public async ValueTask <ActionResult <LeadOutputModel> > AddLead(LeadInputModel leadInputModel)
        {
            var result = await _leadRepository.AddOrUpdateLead(_mapper.Map <Lead>(leadInputModel));

            if (result.IsOkay)
            {
                if (result.RequestData == null)
                {
                    return(Problem($"Added lead not found", statusCode: 520));
                }
                return(Ok(_mapper.Map <LeadOutputModel>(result.RequestData)));
            }
            return(Problem($"Transaction failed {result.ExMessage}", statusCode: 520));
        }
        public static LeadModel ToLead(this LeadInputModel model)
        {
            var lead = new LeadModel
            {
                PhoneNumber = model.ContactNumber,
                Person      =
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                }
            };

            return(lead);
        }
Esempio n. 7
0
        public async ValueTask <string> UpdateLeadRW(LeadInputModel leadModel)
        {
            if (!leadModel.Id.HasValue)
            {
                return("ID is empty");
            }
            var validationResult = await _validator.ValidateLeadInputModel(leadModel);

            if (!string.IsNullOrWhiteSpace(validationResult))
            {
                return(validationResult);
            }
            return("");
        }
Esempio n. 8
0
        public async Task <ResultModel> SubmitAsync(LeadInputModel model)
        {
            var lead = model.ToLead();

            var response = await _httpClient.PostAsJsonAsync(_settings.PostUri, lead).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                var error = await _ParseModel <ErrorModel>(response.Content).ConfigureAwait(false);

                _logger.LogError(error.Title, error);
            }

            var result = await _ParseModel <ResultModel>(response.Content).ConfigureAwait(false);

            return(result);
        }
Esempio n. 9
0
        public async ValueTask <ActionResult <LeadOutputModel> > UpdateLead(LeadInputModel leadModel)
        {
            var message = await _wrapper.UpdateLeadRW(leadModel);

            if (string.IsNullOrWhiteSpace(message))
            {
                leadModel.Password = new PasswordEncryptor().EncryptPassword(leadModel.Password);
                DataWrapper <LeadDto> newDataWrapper = await _repo.AddOrUpdateLead(_mapper.Map <LeadDto>(leadModel));

                _logger.Info($"Update lead info with Id: {newDataWrapper.Data.Id}");
                return(MakeResponse(newDataWrapper, _mapper.Map <LeadOutputModel>));
            }
            else
            {
                return(BadRequest(message));
            }
        }
Esempio n. 10
0
        public async ValueTask <string> CreateLeadRW(LeadInputModel leadModel)
        {
            var validationResult = new string[] {
                await _validator.ValidateLeadInputModel(leadModel),
                await _validator.ValidateLoginInfo(leadModel)
            };

            if (!string.IsNullOrWhiteSpace(validationResult[0]))
            {
                return(validationResult[0]);
            }
            if (!string.IsNullOrWhiteSpace(validationResult[1]))
            {
                return(validationResult[1]);
            }
            return("");
        }
Esempio n. 11
0
        public async ValueTask <string> ValidateLeadInputModel(LeadInputModel leadModel)
        {
            if (leadModel.Id.HasValue)
            {
                var leadId = await _repo.GetById(leadModel.Id.Value);

                if (leadId == null)
                {
                    return("Lead was not found");
                }
            }
            if (string.IsNullOrWhiteSpace(leadModel.FirstName))
            {
                return("Enter the name");
            }
            if (string.IsNullOrWhiteSpace(leadModel.LastName))
            {
                return("Enter the last name");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Password))
            {
                return("Enter a password");
            }
            if (!Regex.IsMatch(leadModel.Password, passwordPattern))
            {
                return("Password have to be between 8 and 20 characters long and contain lowercase, uppercase and number, possible characters: @#$%^&+=*.-_");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Phone))
            {
                return("Enter the phone number");
            }
            if (string.IsNullOrWhiteSpace(leadModel.Address))
            {
                return("Enter the address");
            }
            if (string.IsNullOrWhiteSpace(leadModel.BirthDate))
            {
                return("Enter the date of birth");
            }
            return("");
        }
Esempio n. 12
0
        public async ValueTask <string> ValidateLoginInfo(LeadInputModel leadModel)
        {
            DataWrapper <int> dataWrapper;

            if (string.IsNullOrWhiteSpace(leadModel.Login))
            {
                leadModel.Login = await CreateLogin();
            }
            if (!string.IsNullOrWhiteSpace(leadModel.Login))
            {
                dataWrapper = await _repo.FindLeadByLogin(leadModel.Login);

                if (dataWrapper.Data != 0)
                {
                    return("User with this login already exists");
                }
                if (!Regex.IsMatch(leadModel.Login, Validator.loginPattern))
                {
                    return("The Login is incorrect");
                }
            }
            if (string.IsNullOrWhiteSpace(leadModel.Email))
            {
                return("Enter the email");
            }
            if (!string.IsNullOrWhiteSpace(leadModel.Email))
            {
                dataWrapper = await _repo.CheckEmail(leadModel.Email);

                if (dataWrapper.Data != 0)
                {
                    return("User with this email already exists");
                }
                if ((!Regex.IsMatch(leadModel.Email, Validator.emailPattern)))
                {
                    return("The Email is incorrect");
                }
            }
            return("");
        }
Esempio n. 13
0
 protected void ChangeLead(LeadInputModel model)
 {
     model.Email = $"[email protected]{LeadInputModelMock.RandomNumber(1, 1000000000)}";
     model.Phone = $"+79995196034{LeadInputModelMock.RandomNumber(1, 1000000000)}";
     model.Login = $"regina{LeadInputModelMock.RandomNumber(1, 1000000000)}";
 }