コード例 #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,DateTime,G1P1Score,G1P2Score,G2P1Score,G2P2Score,G3P1Score,G3P2Score,PlayerId1,PlayerId2")] MatchViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                MatchDTO matchDTO = new MatchDTO
                {
                    Id        = viewmodel.Id,
                    DateTime  = viewmodel.DateTime,
                    G1P1Score = viewmodel.G1P1Score,
                    G1P2Score = viewmodel.G1P2Score,
                    G2P1Score = viewmodel.G2P1Score,
                    G2P2Score = viewmodel.G2P2Score,
                    G3P1Score = viewmodel.G3P1Score,
                    G3P2Score = viewmodel.G3P2Score,
                    PlayerId1 = viewmodel.PlayerId1,
                    PlayerId2 = viewmodel.PlayerId2
                };

                await service.AddMatch(matchDTO);

                return(RedirectToAction("Index"));
            }

            var players = await playerService.GetPlayersAsync();

            viewmodel.LoadPlayersIntoSelectList(players);

            return(View(viewmodel));
        }
コード例 #2
0
ファイル: AddMatchTests.cs プロジェクト: afgonzal/futbol
        public async Task Ok_Success()
        {
            var service = new MatchesService(_repository.Object, null, _mapper);
            await service.AddMatch(MockedMatch());

            _repository.Verify(x => x.AddAsync(It.IsAny <DataRepository.DataEntities.Match>()), Times.Once);
        }
コード例 #3
0
ファイル: AddMatchTests.cs プロジェクト: afgonzal/futbol
        public void RepositoryError_ThrowException()
        {
            _repository.Setup(x => x.AddAsync(It.IsAny <DataRepository.DataEntities.Match>())).ThrowsAsync(new DataException());

            var service = new MatchesService(_repository.Object, null, _mapper);

            Assert.ThrowsAsync <DataException>(async() => await service.AddMatch(MockedMatch()));

            _repository.Verify(x => x.AddAsync(It.IsAny <DataRepository.DataEntities.Match>()), Times.Once);
        }