public async Task <IActionResult> SearchFormulas(int?barSize, int?degree, int?mandrelID)
        {
            var fList = SortFormulas(await repo.Formulas);
            var m     = await repo.GetMandrelByIdAsync(mandrelID);

            var resultList = new List <Formula>();

            foreach (Formula f in fList)
            {
                if ((barSize == null || f.BarSize == barSize) &&
                    (degree == null || f.Degree == degree) &&
                    (mandrelID == null || f.Mandrel == m))
                {
                    resultList.Add(f);
                }
            }
            var barSizes = new List <int>();
            var degrees  = new List <int>();
            var mandrels = new List <Mandrel>();

            FillFormulaSearchDropdowns(fList, in barSizes, in degrees, in mandrels);
            var fS = new FormulaSearch
            {
                SearchResults = resultList,
                BarSizes      = barSizes,
                Degrees       = degrees,
                Mandrels      = mandrels,
                BarSize       = barSize,
                BendDegree    = degree,
                MandrelID     = mandrelID
            };

            return(View("Index", fS));
        }
Esempio n. 2
0
        public async Task SearchInvalidFormulaTest()
        {
            //// Arrange
            // Done in the constructor

            // Act
            ViewResult view = (ViewResult)await controller.SearchFormulas(4, null, 3);

            FormulaSearch fS = (FormulaSearch)view.Model;

            // Assert
            Assert.Empty(fS.SearchResults);
        }
        public async Task RetrieveByMandrelIDTest()
        {
            //Arrange
            //Nothing to Arrange
            //Act
            ViewResult view = (ViewResult)await controller.SearchFormulas(null, null, 2);

            FormulaSearch fs = (FormulaSearch)view.Model;

            //Assert
            Assert.Single(fs.SearchResults);
            Assert.Equal(90, fs.SearchResults[0].Degree);
            Assert.Equal(smallMandrel, fs.SearchResults[0].Mandrel);
            Assert.Equal("16.5", fs.SearchResults[0].PinNumber);
            Assert.Equal(1.5m, fs.SearchResults[0].InGained);
        }
        public async Task RetrieveByDegreesTest()
        {
            //Arrange
            //Nothing to Arrange
            //Act
            ViewResult view = (ViewResult)await controller.SearchFormulas(null, 90, null);

            FormulaSearch fs = (FormulaSearch)view.Model;

            //Assert
            Assert.Equal(2, fs.SearchResults.Count);
            Assert.Equal(90, fs.SearchResults[1].Degree);
            Assert.Equal(mediumMandrel, fs.SearchResults[1].Mandrel);
            Assert.Equal("15", fs.SearchResults[1].PinNumber);
            Assert.Equal(2m, fs.SearchResults[1].InGained);
        }
        // GET: Formulas
        public async Task <IActionResult> Index()
        {
            var fList    = SortFormulas(await repo.Formulas);
            var barSizes = new List <int>();
            var degrees  = new List <int>();
            var mandrels = new List <Mandrel>();

            FillFormulaSearchDropdowns(fList, in barSizes, in degrees, in mandrels);
            var fS = new FormulaSearch
            {
                SearchResults = fList,
                BarSizes      = barSizes,
                Degrees       = degrees,
                Mandrels      = mandrels
            };

            return(View(fS));
        }
Esempio n. 6
0
        public async Task SearchFormulasTest()
        {
            //// Arrange
            // Done in the constructor

            // Act
            ViewResult view = (ViewResult)await controller.SearchFormulas(4, null, null);

            FormulaSearch fS = (FormulaSearch)view.Model;

            // Assert
            Assert.Single(fS.SearchResults);
            Assert.Equal(4, fS.SearchResults[0].BarSize);
            Assert.Equal(90, fS.SearchResults[0].Degree);
            Assert.Equal(smallMandrel, fS.SearchResults[0].Mandrel);
            Assert.Equal("16.5", fS.SearchResults[0].PinNumber);
            Assert.Equal(1.5m, fS.SearchResults[0].InGained);
        }
Esempio n. 7
0
        public async Task IndexTest()
        {
            //// Arrange
            // Done in the constructor

            // Act
            ViewResult view = (ViewResult)await controller.Index();

            FormulaSearch fS = (FormulaSearch)view.Model;

            // Assert
            Assert.Equal(2, fS.SearchResults.Count);
            Assert.Equal(2, fS.BarSizes.Count);
            Assert.Single(fS.Degrees);
            Assert.Equal(2, fS.Mandrels.Count);
            Assert.Null(fS.BarSize);
            Assert.Null(fS.BendDegree);
            Assert.Null(fS.MandrelID);
        }