public async Task DoesCookingVesselsCreateAsyncWorkCorrectly(
            PanForm form, int formCount, double diameter, double sideA, double sideB, double height, string name, double area)
        {
            var list = new List <CookingVessel>();

            var service = this.CreateMockAndConfigureService(list, new List <Recipe>());

            var newCookingVessel = new CookingVesselInputModel
            {
                Form       = form,
                FormsCount = formCount,
                Diameter   = diameter,
                SideA      = sideA,
                SideB      = sideB,
                Height     = height,
                Name       = name,
                Area       = area,
            };

            await service.CreateAsync(newCookingVessel);

            var count         = list.Count();
            var heightToCheck = list.First().Height;

            Assert.Equal(1, count);
            Assert.Equal(7d, heightToCheck);
        }
Example #2
0
        public async Task <IActionResult> Create(CookingVesselInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var cookingVessel = await this.cookingVesselsService.CreateAsync(inputModel);

            return(this.RedirectToAction(nameof(this.All)));
        }
        public async Task DoesCookingVesselsCreateAsyncThrowArgumentExceptionWhenSuchNameExists()
        {
            var list = new List <CookingVessel>();

            var service = this.CreateMockAndConfigureService(list, new List <Recipe>());

            var newCookingVessel = new CookingVesselInputModel
            {
                Form     = PanForm.Circle,
                Diameter = 20,
                Height   = 7,
            };

            await service.CreateAsync(newCookingVessel);

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.CreateAsync(newCookingVessel));
        }
Example #4
0
        public async Task <int> CreateAsync(CookingVesselInputModel inputModel)
        {
            double area = (int)inputModel.Form switch
            {
                1 => Math.PI * (inputModel.Diameter / 2) * (inputModel.Diameter / 2) ?? 0,
                2 => inputModel.SideA * inputModel.SideA ?? 0,
                3 => inputModel.SideA * inputModel.SideB ?? 0,
                4 => inputModel.Area ?? 0,
                5 => Math.PI * (inputModel.Diameter / 2) * (inputModel.Diameter / 2) * inputModel.FormsCount ?? 0,
                _ => 0,
            };

            string name = (int)inputModel.Form switch
            {
                1 => $"{inputModel.Form} {inputModel.Diameter}cm/{inputModel.Height}cm",
                2 => $"{inputModel.Form} {inputModel.SideA}x{inputModel.SideA}cm\xB2/{inputModel.Height}cm",
                3 => $"{inputModel.Form} {inputModel.SideA}x{inputModel.SideB}cm\xB2/{inputModel.Height}cm",
                4 => $"{inputModel.Name} {inputModel.Area}cm\xB2/{inputModel.Height}cm",
                5 => $"{inputModel.FormsCount}x{inputModel.Form} {inputModel.Diameter}cm/{inputModel.Height}cm",
                _ => null,
            };

            if (this.cookingVesselRepository.All().Any(x => x.Name == name))
            {
                throw new ArgumentException(ExceptionMessages.CookingVesselAlreadyExists, name);
            }

            var cookingVessel = new CookingVessel
            {
                Name       = name,
                Form       = inputModel.Form,
                FormsCount = inputModel.FormsCount,
                Diameter   = (int)inputModel.Form switch
                {
                    1 => inputModel.Diameter,
                    _ => null,
                },