コード例 #1
0
        public void DeleteVoucher(string voucherNumber)
        {
            string voucherType;
            int    voucherSerialNo;

            if (VoucherNoUtils.TryParse(voucherNumber, out voucherType, out voucherSerialNo))
            {
                IList <Record> deletableItems =
                    _recordRepository.Get(r => r.VoucherType == voucherType && r.VoucherSerialNo == voucherSerialNo).
                    ToList();
                int count = 0;
                foreach (Record deletableItem in deletableItems)
                {
                    _recordRepository.Delete(deletableItem);
                    count++;
                }

                if (count > 0 && _recordRepository.Save() > 0)
                {
                    InvokeManagerEvent("Voucher " + voucherNumber + " deleted successfully.");
                }
            }
            else
            {
                InvokeManagerEvent("Invalid Voucher Number : " + voucherNumber);
            }
        }
コード例 #2
0
        public void TestTryParseWithSeveralData()
        {
            string[] voucherNumbers = new[]
            {
                "DV-1",                           //1
                "DV1",                            //2
                "Contra-9900",                    //3
                "990099",                         //4
                "J--9",                           //5
                "-9",                             //6
                "CV-",                            //7
                "",                               //8
                "CV-9-",                          //9
                "DV-10190986",                    //10
                "CV-0",                           //11
                "C-99999999"                      //12
            };
            bool[] expectedCanParsed = new[]
            {
                true,                               //1
                false,                              //2
                true,                               //3
                false,                              //4
                false,                              //5
                false,                              //6
                false,                              //7
                false,                              //8
                false,                              //9
                true,                               //10
                true,                               //11
                true                                //12
            };
            string[] expectedVoucherTypes = new[]
            {
                "DV",                                   //1
                "",                                     //2
                "Contra",                               //3
                "",                                     //4
                "",                                     //5
                "",                                     //6
                "",                                     //7
                "",                                     //8
                "",                                     //9
                "DV",                                   //10
                "CV",                                   //11
                "C"                                     //12
            };
            int[] expectedVoucherSerialNo = new[]
            {
                1,                                     //1
                0,                                     //2
                9900,                                  //3
                0,                                     //4
                0,                                     //5
                0,                                     //6
                0,                                     //7
                0,                                     //8
                0,                                     //9
                10190986,                              //10
                0,                                     //11
                99999999                               //12
            };

            for (int i = 0; i < voucherNumbers.Length; i++)
            {
                string actualVoucherType;
                int    actualVoucherSerialNo;
                bool   actualCanParsed = VoucherNoUtils.TryParse(voucherNumbers[i], out actualVoucherType, out actualVoucherSerialNo);

                Assert.AreEqual(expectedCanParsed[i], actualCanParsed, "TestMethod TestTryParseWithSeveralData for expectedCanParsed with index " + i);
                Assert.AreEqual(expectedVoucherTypes[i], actualVoucherType, "TestMethod TestTryParseWithSeveralData for expectedVoucherTypes with index " + i);
                Assert.AreEqual(expectedVoucherSerialNo[i], actualVoucherSerialNo, "TestMethod TestTryParseWithSeveralData for expectedVoucherSerialNo with index " + i);
            }
        }