public async Task <IActionResult> Create(HeroCreateInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.Redirect("/Hero/Create")); } await this.heroService.CreateHero(inputModel); return(this.Redirect("/Hero")); }
public async Task CreateHeroShouldCreateHeroInDatabase() { // Arrange HeroCreateInputModel inputModel = new HeroCreateInputModel() { Fraction = Fraction.Sheep, Gender = Gender.Male }; HeroService heroService = this.GetHeroServiceInitialValues(); // Act await heroService.CreateHero(inputModel); // Assert Assert.True(this.context.Heroes.Any()); }
public async Task CreateHeroShouldUseGenderAndFractionFromInputModel() { // Arrange Fraction fraction = Fraction.Pig; Gender gender = Gender.Female; HeroCreateInputModel inputModel = new HeroCreateInputModel() { Fraction = fraction, Gender = gender }; HeroService heroService = this.GetHeroServiceInitialValues(); // Act await heroService.CreateHero(inputModel); // Assert Assert.True(this.context.Heroes.Any(x => x.Fraction == fraction && x.Gender == gender)); }
public async Task CreateHeroShouldIgnoreNameInInputModel() { // Arrange HeroCreateInputModel inputModel = new HeroCreateInputModel() { Fraction = Fraction.Sheep, Gender = Gender.Male, Name = "Name" }; HeroService heroService = this.GetHeroServiceInitialValues(); // Act await heroService.CreateHero(inputModel); Hero hero = this.context.Heroes.First(); // Assert Assert.Equal(UserName, hero.Name); }
public async Task CreateHero(HeroCreateInputModel inputModel) { Hero hero = this.mapper.Map <Hero>(inputModel); hero.ApplicationUser = await this.userService.GetApplicationUser(); hero.Name = hero.ApplicationUser.UserName; hero.AvatarUrl = string.Format( AvatarUrlFormat, hero.Fraction.ToString().ToLower(), hero.Gender.ToString().ToLower()); await this.context.Heroes.AddAsync(hero); await this.context.SaveChangesAsync(); }