Пример #1
0
        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"));
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
        }
Пример #5
0
        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();
        }