Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using System.IO;
  5.  
  6. using Happy.Domain.CodeRule;
  7. using Happy.Domain.CodeRule.Generators;
  8.  
  9. namespace Happy.Test.Doamin.CodeRule
  10. {
  11.     [TestClass]
  12.     public class CodeRuleInterceptorTest
  13.     {
  14.         [TestMethod]
  15.         public void Intercept_Test()
  16.         {
  17.             var seedKey = "销售订单";
  18.             var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Seeds", seedKey + ".txt");
  19.             if (File.Exists(file))
  20.             {
  21.                 File.Delete(file);
  22.             }
  23.  
  24.             var interceptor = new CodeRuleInterceptor();
  25.  
  26.             interceptor
  27.                 .RegisterInterceptor(new DateTimeCodeGeneratorInterceptor())
  28.                 .RegisterInterceptor(new LiteralCodeGeneratorInterceptor())
  29.                 .RegisterInterceptor(new SeedCodeGeneratorInterceptor(new FileSeedStore()));
  30.  
  31.             var generator = interceptor.Intercept("前缀---<日期:yyyyMMdd>---中缀---<种子:销售订单>---后缀");
  32.  
  33.             Assert.IsNotNull(generator);
  34.  
  35.  
  36.             Assert.AreEqual("前缀---20130705---中缀---00001---后缀", generator.Generate(new GenerateContext()));
  37.             Assert.AreEqual("前缀---20130705---中缀---00002---后缀", generator.Generate(new GenerateContext()));
  38.             Assert.AreEqual("前缀---20130705---中缀---00003---后缀", generator.Generate(new GenerateContext()));
  39.         }
  40.     }
  41. }

Last edited Jul 5, 2013 at 9:57 AM by happyframework, version 1

Comments

No comments yet.