Exemple #1
0
        public JsonResult OhmsCalculator(string bandAColor, string bandBColor, string bandCColor, string bandDColor, string selectedbtnId)
        {
            string oldbtnId = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(selectedbtnId))
                {
                    return(null);
                }

                string[] selbtnId = selectedbtnId.Split('.');

                if (selbtnId.Length > 0)
                {
                    switch (selbtnId[1])
                    {
                    case "1":
                        if (_ohmsCalculatorService.IsValidBandABColor(selbtnId[0]))
                        {
                            oldbtnId   = bandAColor + "." + selbtnId[1];
                            bandAColor = selbtnId[0];
                        }
                        break;

                    case "2":
                        if (_ohmsCalculatorService.IsValidBandABColor(selbtnId[0]))
                        {
                            oldbtnId   = bandBColor + "." + selbtnId[1];
                            bandBColor = selbtnId[0];
                        }
                        break;

                    case "3":
                        if (_ohmsCalculatorService.IsValidBandCColor(selbtnId[0]))
                        {
                            oldbtnId   = bandCColor + "." + selbtnId[1];
                            bandCColor = selbtnId[0];
                        }
                        break;

                    case "4":
                        if (_ohmsCalculatorService.IsValidBandDColor(selbtnId[0]))
                        {
                            oldbtnId   = bandDColor + "." + selbtnId[1];
                            bandDColor = selbtnId[0];
                        }
                        break;
                    }
                }

                double ohms = _ohmsCalculatorService.CalculateOhmValue(bandAColor, bandBColor, bandCColor, bandDColor);
                return(Json(new { ohms = ohms.ToString() + " Ω ", bandAColor = bandAColor, bandBColor = bandBColor, bandCColor = bandCColor, bandDColor = bandDColor, oldId = oldbtnId, selectedId = selectedbtnId }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void RejectInvalidInput(string bandAcolor, string bandBcolor, string bandCcolor, string bandDcolor)
        {
            var mockPieRepository = new ResistorBandRepository();

            ////arrange
            var OhmsCalculatorService = new OhmsCalculatorService(mockPieRepository);
            var ohms = OhmsCalculatorService.CalculateOhmValue(bandAcolor, bandBcolor, bandCcolor, bandDcolor);

            //assert
            Assert.Equal(-1, ohms);
        }
Exemple #3
0
        public void OhmsCalculator2()
        {
            var mockPieRepository = new ResistorBandRepository();

            ////arrange
            var OhmsCalculatorService = new OhmsCalculatorService(mockPieRepository);
            var ohms = OhmsCalculatorService.CalculateOhmValue("Red", "Yellow", "DeepPink", "Red");

            //assert
            Assert.Equal(.024, ohms);
        }
        public void AcceptOhmsValueWYDB(string bandAcolor, string bandBcolor, string bandCcolor, string bandDcolor)
        {
            var mockPieRepository = new ResistorBandRepository();

            ////arrange
            var OhmsCalculatorService = new OhmsCalculatorService(mockPieRepository);
            var ohms = OhmsCalculatorService.CalculateOhmValue(bandAcolor, bandBcolor, bandCcolor, bandDcolor);

            //assert
            Assert.Equal(.094, ohms);
        }