Example #1
0
        public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Email")] Coach coach)
        {
            if (id != coach.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _coachService.UpdateAndSave(coach);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_coachService.CoachExists(coach.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(coach));
        }
        public void ExistsTest()
        {
            var fakeRepositoryMock = new Mock <ICoachRepository>();

            fakeRepositoryMock.Setup(x => x.CoachExists(It.IsAny <long>())).Returns(true);

            var coachService = new CoachService(fakeRepositoryMock.Object);

            bool result = coachService.CoachExists(1);

            Assert.True(result);
        }