private IActionResult TryAddSport(SportModelIn modelIn)
        {
            SportDto      data     = BuildSportDto(modelIn);
            SportDto      added    = sports.AddSport(data);
            SportModelOut modelOut = CreateModelOut(added);
            IActionResult result   = CreatedAtRoute("GetSportById", new { name = added.name }, modelOut);

            return(result);
        }
示例#2
0
        public void AddSportTest()
        {
            GrantAdminPermissions();
            SportDto result = serviceToTest.AddSport(testDto);

            sportsStorage.Verify(r => r.Add(It.IsAny <Sport>()), Times.Once);
            Assert.AreEqual(testSport.Name, result.name);
            Assert.AreEqual(testSport.IsTwoTeams, result.isTwoTeams);
        }
        public string Execute(IList <string> parameters)
        {
            Guard.WhenArgument(parameters.Count, "Count of the parameters.").IsNotEqual(1).Throw();

            string name;

            try
            {
                name = parameters[0];
            }
            catch
            {
                throw new ArgumentException("Failed to parse AddSport command parameters.");
            }

            Guard.WhenArgument(name, "Sport name can not be null!").IsNullOrEmpty().Throw();

            ISportDto sport = this.SportscardFactory.CreateSportDto(name);

            sportService.AddSport(sport);

            return($"Sport {name} was added to database.");
        }