public async Task <Result <bool> > Handle(CreateAccountCommand request, CancellationToken cancellationToken) { try { var accountType = await _accountTypeRepository.GetAccountTypeByName(request.AccountType); var newAccount = new Account { Name = request.Name, Zip = request.Zip, Country = request.Country, City = request.City, Street = request.Street, StreetNo = request.StreetNo, ContactEmail = request.ContactEmail, CreatedAt = DateTime.UtcNow, CreatedBy = request.CreatedBy, AccountTypeId = accountType == null ? 1 : accountType.Id }; await _accountRepository.Create(newAccount); return(Result <bool> .Ok(true)); } catch (Exception e) { return(Result <bool> .Failure(e.Message)); } }
public void Add() { var itemsCnt = _customerRepository.GetAll().Count(); var dozer = new Customer { CustomerName = "Apoc", AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value) }; _customerRepository.Add(dozer); var item = _customerRepository.GetCustomerByName("Apoc"); Assert.Equal("Apoc", item.CustomerName); }
public void JuniorTest() { var customer = new Customer { //Id = 99, AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Junior1" }; _customerRepository.Add(customer); var survey = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2); var custSurv = new CustomerSurvey { CustomerId = customer.Id, SurveyId = survey.Id, Date = DateTime.Now }; _customerSurveyRepository.Add(custSurv); var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value); //Age? var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_0_17.Value); //"0-17" var answerAge = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id }; _answerRepository.Add(answerAge); var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);; //Is Student? var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no" var answerStud = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id }; _answerRepository.Add(answerStud); var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value); //Income? var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_0.Value); //"0" var answerIncome = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id }; _answerRepository.Add(answerIncome); var bundleRecomemndation = new BundleRecomendationService(_context); Bundle recomendeBundle = bundleRecomemndation.Recommend(customer, survey); _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} Value: {recomendeBundle?.Value}"); Assert.Equal(Bundle.JuniorSaver.Value, recomendeBundle?.BundleName); _output.WriteLine($"\tIncluded Product: {recomendeBundle?.ProductIncluded?.FirstOrDefault().Product.ProductName}"); Assert.Equal(Product.JuniorSaverAccount.Value, recomendeBundle?.ProductIncluded?.FirstOrDefault().Product.ProductName); }
public void Junior_CanAdd_JuniorAccount_Test() { var customer = new Customer { AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Junior2" }; _customerRepository.Add(customer); var survey = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2); var custSurv = new CustomerSurvey { CustomerId = customer.Id, SurveyId = survey.Id, Date = DateTime.Now }; _customerSurveyRepository.Add(custSurv); var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value); //Age? var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_0_17.Value); //"0-17" var answerAge = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id }; _answerRepository.Add(answerAge); var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);; //Is Student? var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no" var answerStud = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id }; _answerRepository.Add(answerStud); var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value); //Income? var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_0.Value); //"0" var answerIncome = new Answer { CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id }; _answerRepository.Add(answerIncome); var bundleRecomemndation = new BundleRecomendationService(_context); Bundle recomendeBundle = bundleRecomemndation.Recommend(customer, survey); var product = _productRepository.GetByName(Product.JuniorSaverAccount.Value); var prodSelection = new ProducSelectionService(_context); string msg; var res = prodSelection.IsCanAddProduct(product, customer, survey, out msg); _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} \tValue: {recomendeBundle?.Value}"); foreach (var productBundle in recomendeBundle?.ProductIncluded) { _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}"); } _output.WriteLine($"\tres: [{res}], Msg: [{msg}]"); Assert.True(res); //Assert.Equal("Stud not hits", msg); }