public async Task <ActionResult> Login(LoginViewModel model) { if (string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(string.Empty, ProjectResources.ResourceErrors.LoginError); return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } var response = await _userManager.CreateIdentity(model); if (response.IsSuccess) { _authManager.SignOut(); _authManager.SignIn((ClaimsIdentity)response.Object, out var culture); CultureSetter.Set(culture, this); return(Json(new { success = true })); } return(Json(new { success = false, errors = new string[] { ProjectResources.ResourceErrors.LoginError } })); }
public void CalculateTotalPriceCorrectly(string input, double expectedTotalPrice, string cultureInput, string testName) { //Arrange var consoleStringInput = ConsoleInputBuilder.Build(input); CultureSetter.SetCulture(cultureInput); var sut = new OrderPlacer(repository, resource); //sut = System under test. //Act #pragma warning disable S1481 // Unused local variables should be removed using var consoleInput = new ConsoleInput(consoleStringInput); //Exceptions: Unused locally created resources in a using statement are not reported. #pragma warning restore S1481 // Unused local variables should be removed using var consoleOutput = new ConsoleOutput(); sut.PlaceOrder(OrderItemType.Food); sut.PlaceOrder(OrderItemType.Drink); sut.GetOrderedList(); var totalPrice = sut.CalculateTotalPrice(); //Assert totalPrice.Should().BeApproximately(expectedTotalPrice, 0.004); //Fluent assertions: https://app.pluralsight.com/library/courses/fluent-assertions-improving-unit-tests/table-of-contents using (ApprovalResults.ForScenario(testName)) { Approvals.Verify(consoleOutput.GetOuput()); //Approval Tests: https://app.pluralsight.com/course-player?clipId=23302914-f8f9-4e93-94af-c9420fa8e031 } }
public async Task <ActionResult> UserProfile(UserProfileViewModel model) { var user = UserParser.UserProfileViewModelToUser(model); if (!string.IsNullOrEmpty(model.Password)) { if ((string.IsNullOrEmpty(model.NewPassword) | string.IsNullOrEmpty(model.ConfirmNewPassword)) || !ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } user.Password = model.Password; user.NewPassword = model.NewPassword; } else { if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } } var response = await _userManager.Update(user, (ClaimsIdentity)this.User.Identity); if (response.IsSuccess) { CultureSetter.Set(model.Culture, this); return(Json(new { success = true })); } if (response.Message.Equals("Wrong current password", StringComparison.OrdinalIgnoreCase)) { return(Json(new { success = false, errors = new string[] { ProjectResources.ResourceErrors.ChangePasswordError } })); } return(Json(new { success = false, errors = new string[] { response.Message } })); }
public void WriteOrderableItems(List <OrderItem> orderableItems, string cultureInput, string testName) { //Arrange CultureSetter.SetCulture(cultureInput); using var consoleOutput = new ConsoleOutput(); //Act OrderPlacerHelper.WriteOrderableItems(orderableItems, resource); //Assert using (ApprovalResults.ForScenario(testName)) { Approvals.Verify(consoleOutput.GetOuput()); } }
public async Task <ActionResult> Registration(RegistrationViewModel model) { if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } var user = UserParser.RegistrationViewModelToUser(model); var response = await _userManager.CreateIdentity(user); if (response.IsSuccess) { _authManager.SignIn((ClaimsIdentity)response.Object); CultureSetter.Set(model.Culture, this); return(Json(new { success = true })); } string error = string.Empty; if (response.Message.Equals("Username is already taken", StringComparison.OrdinalIgnoreCase)) { error = ProjectResources.ResourceErrors.UserNameIsTaken; } if (response.Message.Equals("Email is already taken", StringComparison.OrdinalIgnoreCase)) { error = ProjectResources.ResourceErrors.EmailIsTaken; } return(Json(new { success = false, errors = new string[] { error } })); }
private void btnSubmit_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show(Resources.Resources.settingsMsgBoxBody, Resources.Resources.settingsMsgBoxTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (confirmResult != DialogResult.OK) { return; } try { var tournamentType = gbTournamentType.Controls.OfType <RadioButton>() .FirstOrDefault(r => r.Checked)?.Tag.ToString(); var language = gbLanguage.Controls.OfType <RadioButton>() .FirstOrDefault(r => r.Checked)?.Tag.ToString(); _repository.SaveSettings(tournamentType, language); CultureSetter.SetFormCulture(language, GetType(), Controls); } catch (Exception ex) when(ex is ArgumentNullException || ex is IOException || ex is CultureNotFoundException) { MessageBox.Show(Resources.Resources.unexpectedErrorOccured); } if (OpenForms.Count > 1) { Close(); return; } Hide(); new WorldCup().ShowDialog(); Close(); }
private void InitializeCulture() { var language = _repository.GetSelectedLanguage(); CultureSetter.SetFormCulture(language, GetType(), Controls); }
public ActionResult SetCulture(string culture) { CultureSetter.Set(culture, this); return(Redirect(Request.UrlReferrer.ToString())); }