コード例 #1
0
ファイル: DBService.cs プロジェクト: rplonski/SampleApp
        public static void InsertInvoiceItem(InvoiceItem invoiceItem)
        {
            if (invoiceItem.Amount <= 0 ||
                invoiceItem.AmountNet <= 0 ||
                invoiceItem.AmountGross <= 0 ||
                string.IsNullOrEmpty(invoiceItem.Unit) ||
                string.IsNullOrEmpty(invoiceItem.Name) ||
                string.IsNullOrEmpty(invoiceItem.InvoiceId))
            {
                throw new ArgumentException();
            }

            string connectionString = @"Data Source = (LocalDb)\MSSQLLocalDB; Initial Catalog = SampleAppDB; Integrated Security = True; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand insertCommand =
                    new SqlCommand("INSERT INTO InvoiceItem (Id, InvoiceId, Name, VatRate, AmountNet, AmountGross, Amount, Unit) "
                                   + "VALUES (@Id, @InvoiceId, @Name, @VatRate, @AmountNet, @AmountGross, @Amount, @Unit)", connection);
                insertCommand.Parameters.Add(new SqlParameter("Id", invoiceItem.Id));
                insertCommand.Parameters.Add(new SqlParameter("InvoiceId", invoiceItem.InvoiceId));
                insertCommand.Parameters.Add(new SqlParameter("Name", invoiceItem.Name));
                insertCommand.Parameters.Add(new SqlParameter("VatRate", invoiceItem.GetVatRate()));
                insertCommand.Parameters.Add(new SqlParameter("AmountNet", invoiceItem.AmountNet));
                insertCommand.Parameters.Add(new SqlParameter("AmountGross", invoiceItem.AmountGross));
                insertCommand.Parameters.Add(new SqlParameter("Amount", invoiceItem.Amount));
                insertCommand.Parameters.Add(new SqlParameter("Unit", invoiceItem.Unit));

                insertCommand.ExecuteNonQuery();
            }
        }
コード例 #2
0
        public void SetVatRate_CorrectVatParameter_CorrectVatValue()
        {
            //Arrange
            var invoiceItem = new InvoiceItem();
            int vatParamter = 23;

            //Act
            invoiceItem.SetVatRate(vatParamter);

            //Assert
            Assert.AreEqual(invoiceItem.GetVatRate(), vatParamter);
        }
コード例 #3
0
        public void CalculateGrossAmount_IncorrectVat_IncorrectGrossAmount()
        {
            //Arrange
            var       invoiceItem       = new InvoiceItem();
            int       vatParamter       = 120;
            Exception expectedException = null;

            //Act
            try
            {
                invoiceItem.SetVatRate(vatParamter);
            }
            catch (Exception ex)
            {
                expectedException = ex;
            }

            //Assert
            Assert.AreNotEqual(vatParamter, invoiceItem.GetVatRate());
        }