public async Task <IActionResult> Edit(TestBaseDto testBaseDto)
        {
            if (ModelState.IsValid)
            {
                await _testBaseService.UpdateTestBaseAsync(testBaseDto);

                return(RedirectToAction(nameof(Index)));
            }

            var topics = await _topicService.GetAllTopicsAsync();

            ViewData["TopicId"] = new SelectList(topics, "Id", "Name", testBaseDto.TopicId);
            return(View(testBaseDto));
        }
Esempio n. 2
0
        public async Task UpdateTestBaseAsync_UpdateWithId1_ModelIsUpdated()
        {
            var cartBeforeUpdate = await _context.TestBases.AsNoTracking().FirstOrDefaultAsync(c => c.Id == 1);

            await _service.UpdateTestBaseAsync(new TestBaseDto()
            {
                Id = 1,
                AmountOfSeconds = 100,
                Name            = "ChangedTestName",
                NumOfQuestions  = 5,
                NumOfTries      = 3,
                TopicId         = 1,
                TopicName       = "TestTopicName"
            });

            var cartAfterUpdate = await _context.TestBases.AsNoTracking().FirstOrDefaultAsync(c => c.Id == 1);

            cartAfterUpdate.Id.Should().Be(cartBeforeUpdate.Id);
            cartAfterUpdate.Name.Should().NotBe(cartBeforeUpdate.Name);
        }