public void Init2() { RetryFile.WriteAllText(s_testFilePath, "abc", Encoding.UTF8); // 设置 FileDependencyManager.RemovedCallback 的等待时间 typeof(FileDependencyManager <string>).SetValue("s_WaitFileCloseTimeout", null, 100); }
public void Test_生成实体代理类型代码() { EntityGenerator g = new EntityGenerator(); string code = g.GetCode <Product>(); code = EntityGenerator.UsingCodeBlock + code; //RetryFile.WriteAllText("..\\AutoCode1.cs", code, Encoding.UTF8); RetryFile.WriteAllText("EntityGeneratorTest_code.cs", code, Encoding.UTF8); }
internal static void SaveLastTempCode(string code, string tempOutPath) { if (string.IsNullOrEmpty(tempOutPath)) { return; } try { string filePath = Path.Combine(tempOutPath, "__last_temp_code.cs"); RetryFile.WriteAllText(filePath, code, Encoding.UTF8); } catch { /* 输出最近一次运行时运行的代码,方便调试程序,忽略写文件出现的异常。 */ } }
internal static void SaveLastComplieError(CompilerResults cr, string tempOutPath) { if (string.IsNullOrEmpty(tempOutPath)) { return; } try { string errorText = GetCompileErrorMessage(cr); string filePath = Path.Combine(tempOutPath, "__last_CompilerError.txt"); RetryFile.WriteAllText(filePath, errorText, Encoding.UTF8); } catch { /* 输出最近一次运行时运行的异常,方便调试程序,忽略写文件出现的异常。 */ } }
public void Test_正常的文件缓存依赖行为() { FileDependencyManager <string> cacheItem = new FileDependencyManager <string>( files => SafeReadFile(files[0]), s_testFilePath); Assert.AreEqual("abc", cacheItem.Result); // 修改文件 RetryFile.WriteAllText(s_testFilePath, "Fish Li", Encoding.UTF8); // FileDependencyManager.RemovedCallback 有等待时间,所以这里要比那个时间再长一点 System.Threading.Thread.Sleep(300); // 确认能拿到最新的结果 Assert.AreEqual("Fish Li", cacheItem.Result); }
public void Test_FormDataCollection_AddObject_File() { string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test_FormDataCollection_AddObject_bytes.txt"); RetryFile.WriteAllText(filePath, "不能直接重载 -= 运算符", Encoding.UTF8); FormDataCollection form = new FormDataCollection(); form.AddObject("a", new byte[] { 1, 2, 3, 4, 5 }); form.AddString("b", "xyz中文汉字"); form.AddObject("c", new FileInfo(filePath)); form.AddObject("d", new HttpFile { FileName = "c:\\test1.dat", FileBody = Encoding.UTF8.GetBytes("XML 的输出文件,由编译的源代码文件中的注释填充") }); string md5 = null; using (MemoryStream ms = new MemoryStream()) { form.WriteToStream(ms, Encoding.UTF8); ms.Position = 0; byte[] buffer = ms.ToArray(); string s = Encoding.UTF8.GetString(buffer); Console.WriteLine(s); // byte 数组太难写断言,所以就计算 MD5 来比较 byte[] bb = (new MD5CryptoServiceProvider()).ComputeHash(buffer); md5 = bb.ToHexString().ToLower(); } Assert.IsTrue(form.HasFile); Assert.AreEqual("fbf3628c4d1415ace6e56084d3edcc18", md5); }
public static void Init(TestContext context) { RetryFile.WriteAllText(s_filename, "禁止使用 ViewState,Session", Encoding.UTF8); }