Exemplo n.º 1
0
        [ValidateModelStateFilter(nameof(Create))] //TODO:Refacotr ValidaModelStateFilter
        public async Task <IActionResult> Create(CreateProteinProductInputModel model)
        {
            await this.productsService.CreateProductAsync <Protein, CreateProteinProductInputModel>(model, model.Image);

            return(this.Redirect(WebConstants.HomePagePath));
        }
        public async Task CreateProducts_ShouldCreate()
        {
            this.Initialize();

            var protModel = new CreateProteinProductInputModel()
            {
                Name                = Proteinname,
                Price               = Price2,
                Description         = ProteinDesciption,
                Directions          = ProteinDirections,
                Image               = image,
                Type                = ProteinType.Whey,
                IsSuatableForVegans = false,
                EnergyPerServing    = Energy,
                ProteinPerServing   = Protein,
                Fibre               = Fibre,
                Salt                = Salt,
                Carbohydrate        = Carbo,
                Fat = Fat
            };

            var creaModel = new CreateCreatineProductInputModel()
            {
                Name                = CreatineName,
                Price               = Price1,
                Description         = CreatineDescription,
                Directions          = CreatineDirections,
                Image               = image,
                Type                = CreatineType.Capsules,
                IsSuatableForVegans = false
            };

            var aminoModel = new CreateAminoAcidProducInputModel()
            {
                Name                = AminoName,
                Price               = Price3,
                Description         = AminoDescription,
                Directions          = AminoDirections,
                Image               = image,
                Type                = AminoAcidType.BCAA,
                IsSuatableForVegans = false,
                EnergyPerServing    = Energy,
                ProteinPerServing   = Protein,
                Carbohydrate        = Carbo,
                Salt                = Salt,
                Fat = Fat
            };

            var vitaModel = new CreateVitaminProductInputModel()
            {
                Name                = VitaminName,
                Price               = Price4,
                Description         = VitaminDescription,
                Directions          = VitaminDirections,
                Image               = image,
                Type                = VitaminType.Multi,
                IsSuatableForVegans = false
            };

            var expectedResult = 1;
            var actual         = await this.service.CreateProductAsync <Vitamin, CreateVitaminProductInputModel>(vitaModel, image);

            Assert.Equal(expectedResult, actual);

            actual = await this.service.CreateProductAsync <AminoAcid, CreateAminoAcidProducInputModel>(aminoModel, image);

            Assert.Equal(expectedResult, actual);

            actual = await this.service.CreateProductAsync <Creatine, CreateCreatineProductInputModel>(creaModel, image);

            Assert.Equal(expectedResult, actual);

            actual = await this.service.CreateProductAsync <Protein, CreateProteinProductInputModel>(protModel, image);

            Assert.Equal(expectedResult, actual);

            var expectedTotalCount = 4;

            Assert.Equal(expectedTotalCount, this.context.Products.Count());
            Assert.Equal(expectedResult, this.context.Proteins.Count());
            Assert.Equal(expectedResult, this.context.Aminos.Count());
            Assert.Equal(expectedResult, this.context.Vitamins.Count());
            Assert.Equal(expectedResult, this.context.Creatines.Count());
        }