Пример #1
0
        public async Task CreateGuardian_MakesCorrectCalls()
        {
            // Arrange
            var guardianEfficiency = new GuardianEfficiency();
            var guardianElo        = new GuardianElo();
            await _efficiencyRepository.UpdateGuardianEfficiency(Arg.Do <GuardianEfficiency>(eff => guardianEfficiency = eff));

            await _eloRepository.UpdateGuardianElo(Arg.Do <GuardianElo>(elo => guardianElo = elo));

            // Act
            await _guardianService.CreateGuardian(_testGuardian);

            // Assert
            await _guardianRepository.Received(1).CreateGuardian(_testGuardian);

            guardianEfficiency.GuardianId.Should().Be(_testGuardian.Id);
            guardianEfficiency.Id.Should().NotBeNullOrEmpty();
            guardianEfficiency.NewEfficiency.Should().Be(0.0);
            guardianEfficiency.PreviousEfficiency.Should().Be(0.0);

            guardianElo.GuardianId.Should().Be(_testGuardian.Id);
            guardianElo.Id.Should().NotBeNullOrEmpty();
            guardianElo.NewElo.Should().Be(1200);
            guardianElo.PreviousElo.Should().Be(0);
        }
        public IActionResult AddGuardian([FromForm] CreateGuardianRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AddGuardianView"));
            }

            var guardian = request.ToGuardian();

            _guardianService.CreateGuardian(guardian);
            return(Redirect("/guardians"));
        }