Exemple #1
0
        public async void TestPartRepoForAdd()
        {
            // arrange
            int indexCpu = 5;
            var repo     = new PartRepository <Cpu>(_context, _mapper);
            var expected = MockData.Cpus.Where(c => c.Id == indexCpu).FirstOrDefault();

            // act
            var result = await repo.Add(expected);

            // assert
            Assert.Equal(expected.Description, result.Description);
        }
        private static Part InitPart(PartType partType, string manufacturer, string model, string description, decimal price = 0)
        {
            var repository = new PartRepository();
            var part       = new Part
            {
                PartType     = partType,
                Description  = description,
                Model        = model,
                Manufacturer = manufacturer,
                Price        = price
            };

            repository.Add(part);
            return(part);
        }
Exemple #3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            double result;

            numberPictureBox.Visible = false;
            namePictureBox.Visible   = false;
            pricePictureBox.Visible  = false;
            bool error = false;

            if (nameTextBox.Text.Length == 0)
            {
                namePictureBox.Visible = true;
                error = true;
            }
            if (numberTextBox.Text.Length == 0)
            {
                numberPictureBox.Visible = true;
                error = true;
            }
            if (priceTextBox.Text.Length == 0 || !Double.TryParse(priceTextBox.Text, out result))
            {
                pricePictureBox.Visible = true;
                error = true;
            }

            if (error)
            {
                return;
            }

            SpareParts p = new SpareParts(this.id, nameTextBox.Text, numberTextBox.Text, Double.Parse(priceTextBox.Text, CultureInfo.InvariantCulture));

            if (p.Id == 0)
            {
                PartRepository.Add(p);
            }
            else
            {
                PartRepository.Update(p);
            }

            this.Close();
        }