コード例 #1
0
        public async Task AddAndSaveTest()
        {
            var coach1 = new Coach()
            {
                Id = 1, Name = "test coach 1", Email = "*****@*****.**"
            };
            var coach2 = new Coach()
            {
                Id = 2, Name = "test coach 2", Email = "*****@*****.**"
            };
            var coaches = new List <Coach> {
                coach1, coach2
            };

            var coach3 = new Coach()
            {
                Id = 3, Name = "test coach 3", Email = "*****@*****.**"
            };

            var fakeRepositoryMock = new Mock <ICoachRepository>();

            fakeRepositoryMock.Setup(x => x.Add(It.IsAny <Coach>())).Callback <Coach>(arg => coaches.Add(arg));

            var coachService = new CoachService(fakeRepositoryMock.Object);

            await coachService.AddAndSave(coach3);


            Assert.Equal(3, coaches.Count);
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email")] Coach coach)
        {
            if (ModelState.IsValid)
            {
                await _coachService.AddAndSave(coach);

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