public void TestOverFlow() { // 插入数据. my_serial_number mySeq = new my_serial_number(); mySeq.sn_name = "TEST_SEQ_OVERFLOW"; mySeq.sn_desc = "测试流水号溢出"; mySeq.sn_howto = "Normal"; mySeq.sn_format = "ABCDEF-[@Today:YYYY]_[@Seq:00]"; mySeq.sn_seq_max = 99; mySeq.sn_seq_min = 1; mySeq.sn_seq_curr = 1; mySeq.sn_auto_close_date = true; context.my_serial_number.InsertOnSubmit(mySeq); context.SubmitChanges(); // 预期的序列号. string sn = null; for (int i = 1; i < 100; i++) { // 调用 存储过程 获取的 流水号. context.MySerialNumber_NextVal("TEST_SEQ_OVERFLOW", ref sn); // C# 中模拟计算的 流水号. string csn = String.Format( "ABCDEF-{0}_{1}", DateTime.Today.ToString("yyyy"), i.ToString("00")); Assert.AreEqual(csn, sn); context.MySerialNumber_CurrVal("TEST_SEQ_OVERFLOW", ref sn); Assert.AreEqual(csn, sn); } // 前面已经获取了 流水号 01 - 99 // 下面再次获取流水号, 将为 100, 大于 流水的最大序号 99; context.MySerialNumber_NextVal("TEST_SEQ_OVERFLOW", ref sn); // 由于上面的代码发生了异常,下面这句应该执行不到。 Assert.Fail("本测试应该触发一个异常。"); }
public void TestSample1() { // 插入数据. my_serial_number mySeq = new my_serial_number(); mySeq.sn_name = "TEST_SEQ1"; mySeq.sn_desc = "测试流水号1"; mySeq.sn_howto = "Normal"; mySeq.sn_format = "X-[@Today:YYYYMMDD]_[@Seq:0000]"; mySeq.sn_seq_max = 9999; mySeq.sn_seq_min = 1; mySeq.sn_seq_curr = 1; mySeq.sn_auto_close_date = true; context.my_serial_number.InsertOnSubmit(mySeq); context.SubmitChanges(); // 预期的序列号. string sn = null; for (int i = 1; i < 100; i++) { // 调用 存储过程 获取的 流水号. context.MySerialNumber_NextVal("TEST_SEQ1", ref sn); // C# 中模拟计算的 流水号. string csn = String.Format( "X-{0}_{1}", DateTime.Today.ToString("yyyyMMdd"), i.ToString("0000")); Assert.AreEqual(csn, sn); context.MySerialNumber_CurrVal("TEST_SEQ1", ref sn); Assert.AreEqual(csn, sn); } }