Exemple #1
0
        public void TestCalculateMixInVolume()
        {
            //Testing if one of the volume properties are set after running
            //the method
            TextBox nicBaseConc = new TextBox();

            nicBaseConc.Text = "72";
            TextBox desiredNicConc = new TextBox();

            desiredNicConc.Text = "24";
            TextBox volumeRequired = new TextBox();

            volumeRequired.Text = "30";
            TextBox vgBox = new TextBox();

            vgBox.Text = "45";
            TextBox pgBox = new TextBox();

            pgBox.Text = "55";

            TextBox[] flavouringPercentages = { new TextBox() };
            flavouringPercentages[0].Text = "4.3";

            Mix tempMix = new Mix();

            //sets the volume properties
            tempMix.CalculateMixInVolume(desiredNicConc, volumeRequired, nicBaseConc, vgBox, pgBox, flavouringPercentages);

            Assert.IsNotNull(tempMix.FlavouringsVolumeInMix);
        }
        private void CalculateButton_Click(object sender, RoutedEventArgs e)
        {
            //Most of the inards of this method should be delegated to other methods if we want to return a Mix object.
            Mix tempMix = new Mix();

            //make sure the mix has at least one flavouring percentage and the neccasary information to calculate it
            if (String.IsNullOrWhiteSpace(flavouring1PercentageInput.Text) || String.IsNullOrWhiteSpace(nicotineBaseConcInput.Text) || String.IsNullOrWhiteSpace(desiredNicotineConcInput.Text) ||
                String.IsNullOrWhiteSpace(volumeRequiredInput.Text) || String.IsNullOrWhiteSpace(desiredPGPercentageInput.Text) || String.IsNullOrWhiteSpace(desiredVGPercentageInput.Text))
            {
                userErrorInfo.Text = "You are missing key information to calculate this mix.";
            }
            else
            {
                //make sure the mix makes mathematical sense
                try
                {
                    //make sure pg vg ratio adds up to 100 put this in if statement
                    Mix.PGVGValidator(desiredPGPercentageInput, desiredVGPercentageInput);

                    TextBox[] flavouringNamesInput = GetFlavouringNameInputTextBoxes();


                    TextBlock[] flavouringNamesOutput = GetFlavouringNamesOutput();
                    int         i = 0;
                    foreach (TextBox flavouringName in flavouringNamesInput)
                    {
                        if (String.IsNullOrWhiteSpace(flavouringName.Text))
                        {
                            i += 1;
                            continue;
                        }
                        else
                        {
                            flavouringNamesOutput[i].Text = Convert.ToString(flavouringName.Text);
                            i += 1;
                        }
                    }


                    tempMix.NicotineWeightCalculator(nicotineBaseConcInput);

                    TextBox[] flavouringPercentagesInput = GetFlavouringPercentageInputTextBoxes();

                    tempMix.CalculateMixInVolume(desiredNicotineConcInput, volumeRequiredInput, nicotineBaseConcInput, desiredVGPercentageInput, desiredPGPercentageInput, flavouringPercentagesInput);

                    TextBlock[] flavouringVolumeOutput = GetFlavouringVolumeOutput();
                    tempMix.DisplayMixResultsVolume(nicotineBaseVolumeOutput, pgBaseVolumeOutput, vgVolumeOutput, flavouringVolumeOutput);

                    TextBlock[] flavouringWeightOutput = GetFlavouringWeightOutput();
                    tempMix.DisplayMixResultsWeight(nicotineBaseGramsOutput, pgGramsOutput, vgGramsOutput, flavouringWeightOutput);

                    TextBlock[] flavouringPercentageOutput = GetFlavouringPercentageOutput();

                    tempMix.DisplayMixResultsPercentage(nicotineBasePercentageOutput, vgPercentageOutput, pgPercentageOutput, flavouringPercentagesInput, flavouringPercentageOutput);


                    //Displaying totals.          Could do this with a generic?
                    List <TextBlock> percentageOutputList = new List <TextBlock>();
                    percentageOutputList.AddRange(flavouringPercentageOutput);
                    percentageOutputList.Add(nicotineBasePercentageOutput);
                    percentageOutputList.Add(pgPercentageOutput);
                    percentageOutputList.Add(vgPercentageOutput);

                    List <TextBlock> volumeOutputList = new List <TextBlock>();
                    volumeOutputList.AddRange(flavouringVolumeOutput);
                    volumeOutputList.Add(nicotineBaseVolumeOutput);
                    volumeOutputList.Add(vgVolumeOutput);
                    volumeOutputList.Add(pgBaseVolumeOutput);

                    List <TextBlock> weightOutputList = new List <TextBlock>();
                    weightOutputList.AddRange(flavouringWeightOutput);
                    weightOutputList.Add(nicotineBaseGramsOutput);
                    weightOutputList.Add(vgGramsOutput);
                    weightOutputList.Add(pgGramsOutput);

                    tempMix.DisplayTotals(volumeOutputList, weightOutputList, percentageOutputList, flavouringPercentagesInput, totalVolumeOutput, totalGramsOutput, totalPercentageOutput, totalFlavourPercentageOutput);


                    mixMadeSuccesfully = true;
                }
                catch (Exception ex)
                {
                    userErrorInfo.Text = Convert.ToString(ex.Message);
                }
            }
        }