public async Task <FaqDetailsViewModel> CreateAsync(FaqCreateInputModel faqCreateInputModel) { var faq = new FaqEntry { Question = faqCreateInputModel.Question, Answer = faqCreateInputModel.Answer, }; bool doesFaqExist = await this.faqEntriesRepository .All() .AnyAsync(x => x.Question == faqCreateInputModel.Question && x.Answer == faqCreateInputModel.Answer); if (doesFaqExist) { throw new ArgumentException( string.Format(ExceptionMessages.FaqAlreadyExists, faqCreateInputModel.Question, faqCreateInputModel.Answer)); } await this.faqEntriesRepository.AddAsync(faq); await this.faqEntriesRepository.SaveChangesAsync(); var viewModel = await this.GetViewModelByIdAsync <FaqDetailsViewModel>(faq.Id); return(viewModel); }
public async Task <IActionResult> Create(FaqCreateInputModel faqCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(faqCreateInputModel)); } await this.aboutService.CreateAsync(faqCreateInputModel); return(this.RedirectToAction("GetAll", "About", new { area = "Administration" })); }
public async Task TestAddingFaqEntry() { var model = new FaqCreateInputModel { Question = "Ask me something?", Answer = "Please reply to that question.", }; await this.aboutService.CreateAsync(model); var count = await this.faqEntriesRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task TestAddingFaqEntry() { var model = new FaqCreateInputModel { Question = "How can I register?", Answer = "Use the register form.", }; await this.faqService.CreateAsync(model); var count = await this.faqEntriesRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckIfAddingFaqEntryThrowsArgumentException() { this.SeedDatabase(); var faqEntry = new FaqCreateInputModel { Question = "Test Question?", Answer = "Test Answer.", }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.aboutService.CreateAsync(faqEntry)); Assert.Equal(string.Format(ExceptionMessages.FaqAlreadyExists, faqEntry.Question, faqEntry.Answer), exception.Message); }
public async Task CheckSettingOfFaqEntryProperties() { var model = new FaqCreateInputModel { Question = "How are you?", Answer = "Nice.", }; await this.aboutService.CreateAsync(model); var faqEntry = await this.faqEntriesRepository.All().FirstOrDefaultAsync(); Assert.Equal("How are you?", faqEntry.Question); Assert.Equal("Nice.", faqEntry.Answer); }
public async Task CheckSettingOfFaqEntryProperties() { var model = new FaqCreateInputModel { Question = "What do you think about the website?", Answer = "I think it is a nice place to visit.", }; await this.faqService.CreateAsync(model); var faqEntry = await this.faqEntriesRepository.All().FirstOrDefaultAsync(); Assert.Equal(model.Question, faqEntry.Question); Assert.Equal(model.Answer, faqEntry.Answer); }
public async Task CheckIfAddingFaqEntryReturnsViewModel() { var faqEntry = new FaqCreateInputModel { Question = "What are going to do with these tests?", Answer = "I am so bored right now.", }; var viewModel = await this.aboutService.CreateAsync(faqEntry); var dbEntry = await this.faqEntriesRepository.All().FirstOrDefaultAsync(); Assert.Equal(dbEntry.Id, viewModel.Id); Assert.Equal(dbEntry.Question, viewModel.Question); Assert.Equal(dbEntry.Answer, viewModel.Answer); }
public async Task CheckIfAddingFaqEntryReturnsViewModel() { var faqEntry = new FaqCreateInputModel { Question = "What do you think about our reviews?", Answer = "There are so beautiful.", }; var viewModel = await this.faqService.CreateAsync(faqEntry); var dbEntry = await this.faqEntriesRepository.All().FirstOrDefaultAsync(); Assert.Equal(dbEntry.Id, viewModel.Id); Assert.Equal(dbEntry.Question, viewModel.Question); Assert.Equal(dbEntry.Answer, viewModel.Answer); }