本文整理匯總了C#中System.IO.TempDirectory.AddFile方法的典型用法代碼示例。如果您正苦於以下問題:C# TempDirectory.AddFile方法的具體用法?C# TempDirectory.AddFile怎麽用?C# TempDirectory.AddFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.TempDirectory
的用法示例。
在下文中一共展示了TempDirectory.AddFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateFromImageFilesTest
public void CreateFromImageFilesTest()
{
using (var tempDirectory = new TempDirectory(true))
{
tempDirectory.AddFile("help0.png", "");
tempDirectory.AddFile("help1.png", "");
var helpDocument = HelpDocument.CreateFromImageFiles(new [] { tempDirectory.FullPath("help0.png"), tempDirectory.FullPath("help1.png"), });
CollectionAssert.AreEqual(new [] { "help0", "help1" }, helpDocument.Items.Select(item => item.Id));
CollectionAssert.AreEqual(new [] { "help0.png", "help1.png" }, helpDocument.Items.Select(item => item.ImageFile));
}
}
示例2: Test0
public void Test0()
{
using (var tempDirectory = new TempDirectory(true))
{
EPuzzlePronuncer.Instance.DirectoryName = tempDirectory.Name;
Assert.Null(EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));
tempDirectory.AddFile("pronunce.wav", "");
Assert.AreEqual(tempDirectory.GetFullPath("pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));
Assert.AreEqual(tempDirectory.GetFullPath("Pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("Pronunce"));
}
}
示例3: Test1
public void Test1()
{
var player = new EPuzzleSoundPlayer();
using (var tempDir = new TempDirectory(true))
using (var tempDir2 = new TempDirectory(true))
{
tempDir2.AddFile("test.wav", "");
player.Directories.Add(tempDir.Name);
player.Directories.Add(tempDir2.Name);
Assert.AreEqual(tempDir2.FullPath("test.wav"), TestUtility.Inv(player, "FindFile", "test.wav"));
Assert.Null(TestUtility.Inv(player, "FindFile", "test_xxxx.wav"));
}
}
示例4: using
public void 並び順テスト()
{
using (var tempDirectory = new TempDirectory(true))
{
var manager = new ResultImageManager();
tempDirectory.AddFile(@"A\file0.png", "");
tempDirectory.AddFile(@"A\file1.png", "");
tempDirectory.AddFile(@"A\file2.png", "");
var now = new DateTime(2013, 7, 11, 0, 0, 0); // UTC
EPuzzleTime.Now = now;
var file0 = tempDirectory.GetFullPath(@"A\file0.png");
var file1 = tempDirectory.GetFullPath(@"A\file1.png");
var file2 = tempDirectory.GetFullPath(@"A\file2.png");
Assert.False(manager.最後に表示してからもっとも時間が経過しているファイルから表示する);
manager.DirectoryName = tempDirectory.Name;
manager.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
Assert.True(manager.最後に表示してからもっとも時間が経過しているファイルから表示する);
manager.UpdateAccessTime(file1, now + TimeSpan.FromSeconds(1d));
manager.UpdateAccessTime(file0, now + TimeSpan.FromSeconds(2d));
manager.UpdateAccessTime(file2, now + TimeSpan.FromSeconds(3d));
Assert.AreEqual(file1, manager.GetFile("A"));
Assert.AreEqual(file0, manager.GetFile("A"));
Assert.AreEqual(file2, manager.GetFile("A"));
Assert.AreEqual(file1, manager.GetFile("A"));
Assert.AreEqual(file0, manager.GetFile("A"));
Assert.AreEqual(file2, manager.GetFile("A"));
EPuzzleTime.Now = now + TimeSpan.FromMinutes(1d);
manager.UpdateAccessTime(file1);
Assert.AreEqual(file0, manager.GetFile("A"));
Assert.AreEqual(file2, manager.GetFile("A"));
Assert.AreEqual(file1, manager.GetFile("A"));
Assert.AreEqual(file0, manager.GetFile("A"));
Assert.AreEqual(file2, manager.GetFile("A"));
Assert.AreEqual(file1, manager.GetFile("A"));
using (var tempFile = new TempFile())
{
manager.ImageInfoContainerFileName = tempFile.Name;
manager.Save();
var manager2 = new ResultImageManager();
manager2.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
manager2.DirectoryName = tempDirectory.Name;
manager2.ImageInfoContainerFileName = tempFile.Name;
manager2.Load();
Assert.AreEqual(file0, manager2.GetFile("A"));
Assert.AreEqual(file2, manager2.GetFile("A"));
Assert.AreEqual(file1, manager2.GetFile("A"));
}
using (var tempFile = new TempFile())
{
// 消したファイルの情報は保存しない
manager.ImageInfoContainerFileName = tempFile.Name;
tempDirectory.DeleteFile(@"A\file1.png");
tempDirectory.DeleteFile(@"A\file2.png");
manager.Save();
var manager2 = new ResultImageManager();
manager2.最後に表示してからもっとも時間が経過しているファイルから表示する = true;
manager2.DirectoryName = tempDirectory.Name;
manager2.ImageInfoContainerFileName = tempFile.Name;
manager2.Load();
var imageInfoContainer = (ImageInfoContainer)TestUtility.GetValue(manager2, "_imageInfoContainer");
Assert.NotNull(imageInfoContainer);
Assert.AreEqual(1, imageInfoContainer.ImageInfos.Count());
CollectionAssert.AreEqual(new [] { file0, }, imageInfoContainer.ImageInfos.Keys);
}
// UpdateAccessTimeにnullなどを渡した場合
Assert.Throws<ArgumentNullException>(() =>
{
manager.UpdateAccessTime(null);
});
Assert.Throws<ArgumentException>(() =>
{
manager.UpdateAccessTime(" ");
});
Assert.Throws<ArgumentException>(() =>
{
manager.UpdateAccessTime("");
});
}
}
示例5: PrepareForImagesTest
public void PrepareForImagesTest()
{
using (var tempDirectory = new TempDirectory(true))
{
var manager = new ResultImageManager();
manager.DirectoryName = tempDirectory.Name;
// ファイルがない場合
manager.PrepareForImages();
{
Assert.Null(manager.GetImage("A"));
Assert.Null(manager.GetImage("A"));
}
// ファイルがある場合
tempDirectory.AddFile(@"A\a.bmp", new Bitmap(10, 10));
tempDirectory.AddFile(@"B\b.bmp", new Bitmap(11, 10));
tempDirectory.AddFile(@"cdef.bmp", new Bitmap(12, 10));
Assert.True(File.Exists(tempDirectory.FullPath(@"A\a.bmp")));
Assert.True(File.Exists(tempDirectory.FullPath(@"B\b.bmp")));
Assert.True(File.Exists(tempDirectory.FullPath(@"cdef.bmp")));
Assert.Null(manager.PeekCache_TESTONLY("A"));
Assert.Null(manager.PeekCache_TESTONLY("B"));
Assert.Null(manager.PeekCache_TESTONLY("C"));
{
manager.PrepareForImages();
// var task = manager.GetTask_TESTONLY();
// task.Wait();
}
var imageA0 = manager.PeekCache_TESTONLY("A");
Assert.AreEqual(10, imageA0.Width);
Assert.AreEqual(11, manager.PeekCache_TESTONLY("B").Width);
Assert.AreEqual(12, manager.PeekCache_TESTONLY("C").Width);
Assert.AreEqual(12, manager.PeekCache_TESTONLY("D").Width);
Assert.AreEqual(12, manager.PeekCache_TESTONLY("F").Width);
var imageA1 = manager.GetImage("A");
Assert.AreSame(imageA0, imageA1);
Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), imageA0.Tag);
Assert.Null(manager.PeekCache_TESTONLY("A"));
{
manager.PrepareForImages();
// var task = manager.GetTask_TESTONLY();
// task.Wait();
}
Assert.AreEqual(10, manager.PeekCache_TESTONLY("A").Width);
{
var image0 = manager.GetImage("A");
var image1 = manager.GetImage("A");
Assert.AreNotSame(image0, image1);
Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image0.Tag);
Assert.AreEqual(tempDirectory.FullPath(@"A\a.bmp"), image1.Tag);
}
}
}
示例6: Test1
public void Test1()
{
WindowState.NowObject = new TestNowObject();
WindowState.NowObject.Now = DateTime.MinValue;
using (var tempDirectory = new TempDirectory(true))
{
tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
tempDirectory.AddFile(@"mondai\MondaiDocument2.xml", TestResources.Mondai03);
{
var data56 = EPuzzleData.Create(tempDirectory.Name);
data56.Save();
}
var data = EPuzzleData.Create(tempDirectory.Name);
var userInfo = data.CurrentUserInfo;
var window = new EPuzzleWindow(data);
Assert.AreEqual("DocumentA", data.MondaiDocuments[0].Name);
Assert.AreEqual("DocumentB", data.MondaiDocuments[1].Name);
var mondaiDocumentMenuState = new MondaiDocumentMenuState(window, data.MondaiDocuments);
window.State = mondaiDocumentMenuState;
{
var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
Assert.AreEqual(2, buttons.Count());
Assert.AreEqual("DocumentA", buttons[0].Text);
Assert.AreSame(data.MondaiDocuments[0], buttons[0].Tag);
Assert.AreEqual("DocumentB", buttons[1].Text);
Assert.AreSame(data.MondaiDocuments[1], buttons[1].Tag);
}
var daimonA1 = (Daimon)data.MondaiDocuments[0].Items[1];
var daimonB1 = (Daimon)data.MondaiDocuments[1].Items[1];
Assert.AreEqual("daimon2", daimonA1.Id);
Assert.AreSame(data.MondaiDocuments[0], daimonA1.Parent);
Assert.AreEqual("daimon2", daimonB1.Id);
Assert.AreSame(data.MondaiDocuments[1], daimonB1.Parent);
userInfo.SetLastDaimonInfo(daimonA1);
userInfo.SetLastDaimonInfo(daimonB1);
// button[0]
{
var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
window.State.CurrentItem = buttons[0];
window.State.OnAction0();
Assert.AreSame(data.MondaiDocuments[0], window.EPuzzleData.CurrentMondaiDocument);
Assert.IsInstanceOf<FadeoutState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<FadeinState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<DaimonState>(window.State);
Assert.AreSame(daimonA1, ((DaimonState)window.State).Daimon);
}
// button[1]
{
window.State = mondaiDocumentMenuState;
var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
window.State.CurrentItem = buttons[1];
window.State.OnAction0();
Assert.AreSame(data.MondaiDocuments[1], window.EPuzzleData.CurrentMondaiDocument);
Assert.IsInstanceOf<FadeoutState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<FadeinState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<DaimonState>(window.State);
Assert.AreSame(daimonB1, ((DaimonState)window.State).Daimon);
}
// マウスクリックで遷移テスト
{
window.State = mondaiDocumentMenuState;
var buttons = mondaiDocumentMenuState.GetAllItems().Where(x => x is EigoTestButtonItem && x.Tag is MondaiDocument).ToArray();
var button = buttons[0];
Assert.IsInstanceOf<MondaiDocumentMenuState>(window.State);
window.State.CurrentItem = button;
Assert.True(window.State.CurrentItem.Contains(button.BorderLeft, button.BorderTop));
window.MouseUp(button.BorderLeft, button.BorderTop, MouseButtons.Left);
Assert.AreSame(data.MondaiDocuments[0], window.EPuzzleData.CurrentMondaiDocument);
Assert.IsInstanceOf<FadeoutState>(window.State);
}
//.........這裏部分代碼省略.........
示例7: GetImageTest
public void GetImageTest()
{
using (var tempDirectory = new TempDirectory(true))
{
var manager = new ResultImageManager2();
manager.DirectoryName = tempDirectory.Name;
tempDirectory.AddFile(@"A\a0.bmp", new Bitmap(10, 10));
{
var image = manager.GetImage("A");
Assert.NotNull(image);
Assert.AreEqual(tempDirectory.FullPath(@"A\a0.bmp"), image.Tag);
}
tempDirectory.AddFile(@"A\a1.bmp", new Bitmap(11, 10));
tempDirectory.AddFile(@"A\a2.bmp", new Bitmap(12, 10));
manager.PrepareForImages();
CollectionAssert.AreEquivalent(new []
{
tempDirectory.FullPath(@"A\a0.bmp"),
tempDirectory.FullPath(@"A\a1.bmp"),
tempDirectory.FullPath(@"A\a2.bmp"),
}, manager.Files);
manager.PrepareForImages();
tempDirectory.DeleteFile(@"A\a0.bmp");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.FullPath(@"A\a1.bmp"),
tempDirectory.FullPath(@"A\a2.bmp"),
}, new [] { manager.GetImage("A").Tag, manager.GetImage("A").Tag, }.Cast<string>());
manager.PrepareForImages();
tempDirectory.DeleteFile(@"A\a1.bmp");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.FullPath(@"A\a2.bmp"),
tempDirectory.FullPath(@"A\a2.bmp"),
}, new [] { manager.GetImage("A").Tag, manager.GetImage("A").Tag, }.Cast<string>());
manager.PrepareForImages();
tempDirectory.DeleteFile(@"A\a2.bmp");
Assert.Null(manager.GetImage("A"));
Assert.Null(manager.GetImage("A"));
}
}
示例8: using
public void ファイルを暗號化してディレクトリをバックアップする([Values(true, false)] bool verify)
{
using (var dir1 = new TempDirectory(true))
using (var dir2 = new TempDirectory(true))
{
var password = "xxx";
var backup = new EncryptionDirectoryBackup(dir1.Name, dir2.Name, password, verify);
var file1 = "a.txt";
var file2 = "b.txt";
var text = "abc";
{
var a = dir1.FullPath(file1);
var b = dir2.FullPath(file1);
FileUtility.Save(a, text);
Assert.AreEqual(text, FileUtility.Load(a));
TestUtility.Inv(backup, "Copy", a, b);
Assert.True(File.Exists(b));
Assert.AreEqual(File.GetLastWriteTime(a), File.GetLastWriteTime(b));
FileAssert.AreNotEqual(a, b);
var tt = FileUtility.Load(b, StreamOptions.Encryption3, password);
Assert.AreEqual(FileUtility.Load(a), tt);
Assert.AreEqual(text, tt);
FileUtility.Load(b, sb =>
{
using (var sr = new StreamReader(sb))
{
Assert.AreEqual(text, sr.ReadToEnd());
}
}, StreamOptions.Encryption3, password);
TestUtility.Inv(backup, "Verify", a, b);
}
{
var a = dir1.FullPath(file1);
var b = dir2.FullPath(file2);
FileUtility.Save(b, text);
FileAssert.AreEqual(a, b);
Assert.Throws<System.Security.Cryptography.CryptographicException>(() =>
{
TestUtility.Inv(backup, "Verify", a, b);
});
}
{
var a = dir1.FullPath(file1);
var b = dir2.FullPath(file2);
FileUtility.Save(a, "abc");
FileUtility.Save(b, "abd", StreamOptions.Encryption3, password);
FileAssert.AreNotEqual(a, b);
Assert.Throws<ApplicationException>(() =>
{
TestUtility.Inv(backup, "Verify", a, b);
});
}
{
var a = dir1.FullPath("c.txt");
var b = dir2.FullPath("d.txt");
var c = dir2.FullPath("e.txt");
var t1 = new DateTime(2014, 3, 1, 0, 0, 0); // UTC
var t2 = new DateTime(2013, 3, 1, 0, 0, 0); // UTC
FileUtility.Save(a, "abc");
FileUtility.Save(b, "defg");
FileUtility.Save(c, "hijkl");
File.SetLastWriteTime(a, t1);
File.SetLastWriteTime(b, t1);
File.SetLastWriteTime(c, t2);
Assert.False(TestUtility.Inv(backup, "AreDifferent", a, b));
Assert.True(TestUtility.Inv(backup, "AreDifferent", a, c));
}
}
using (var dirA = new TempDirectory(true))
using (var dirB = new TempDirectory(true))
{
var fileName = "a.txt";
var text = "abc";
var password = "xxx";
dirA.AddFile(fileName, text);
var a = dirA.FullPath(fileName);
var b = dirB.FullPath(fileName);
var backup = new EncryptionDirectoryBackup(dirA.Name, dirB.Name, password, verify);
backup.Start();
Assert.True(File.Exists(b));
TestUtility.Inv(backup, "Verify", a, b);
Assert.AreEqual(FileUtility.Load(a), FileUtility.Load(b, StreamOptions.Encryption3, password));
}
}
示例9: using
public void Chumon遷移テスト()
{
EPuzzleWindow window = null;
using (var tempDirectory = new TempDirectory(true))
{
tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
WindowState.NowObject = new TestNowObject();
var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
EPuzzleTime.Now = t0;
window = new EPuzzleWindow(ePuzzleData);
window.State = WindowState.Fi(new StartGameState(window), EPuzzleConstants.畫麵切替時間);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
// ゲームスタート畫麵
Assert.IsInstanceOf<StartGameState>(window.State);
{
var item = window.State.Items.First(x => x.Name == "StartGameButton");
item.OnClick(new MouseEventInfo(MouseButtons.Left));
}
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<MondaiDocumentMenuState>(window.State);
{
var button = window.State.GetAllItems().Where(x => x.Tag is MondaiDocument).First();
window.State.CurrentItem = button;
window.State.OnAction0();
}
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<DaimonState>(window.State);
Assert.AreEqual("基礎I", ((DaimonState)window.State).Daimon.Name);
{
var item = window.State.GetAllItems().First(x => x.Text == "This is a pen.");
Assert.IsInstanceOf<EigoTestButtonItem>(item);
window.MouseMove(item.BorderLeft, item.BorderTop);
window.Tick();
window.MouseUp(item.BorderLeft, item.BorderTop, MouseButtons.Left);
}
/*
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
*/
Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
window.MouseUp(100f, 100f, MouseButtons.Left);
Assert.IsInstanceOf<ShomonState>(window.State);
Assert.AreEqual("[英訳] これはノートです。", ((ShomonState)window.State).Shomon.Mondaibun);
var mondaiId = ((ShomonState)window.State).Shomon.Parent.Id;
Assert.AreEqual("d1_chumon1", mondaiId);
var startTime = WindowState.NowObject.Now;
Assert.AreEqual(startTime, window.ChumonResult.StartTime);
{
var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "This is");
window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
}
{
var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == "a notebook");
window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
}
{
var wordCard = window.State.GetAllItems().First(x => x is WordCard && x.Text == ".");
window.MouseUp(wordCard.BorderLeft, wordCard.BorderTop, MouseButtons.Left);
}
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
window.Tick();
Assert.IsInstanceOf<FadeoutState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<FadeinState>(window.State);
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<ShomonState>(window.State);
Assert.AreEqual("[英訳] これはボールです。", ((ShomonState)window.State).Shomon.Mondaibun);
// エスケープ畫麵では時間が経過しない
window.State.OnAction3();
//.........這裏部分代碼省略.........
示例10: using
public void 新しいグレード指定フォーマット()
{
using (var tempDirectory = new TempDirectory(true))
{
{
var manager = new ResultImageManager2();
manager.DirectoryName = tempDirectory.Name;
tempDirectory.AddFile(@"A\file0.png", "");
tempDirectory.AddFile(@"x[A]x[B]x\file0.bmp", "");
tempDirectory.AddFile(@"x[AB]x\file2.bmp", "");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
}, new []
{
manager.GetFile("A"),
manager.GetFile("A"),
manager.GetFile("A"),
manager.GetFile("A"),
});
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
}, new []
{
manager.GetFile("B"),
manager.GetFile("B"),
});
}
}
}
示例11: using
public void EPuzzleData2_問題ファイル以外何も用意しない場合のテスト()
{
using (var tempDirectory = new TempDirectory(true))
{
{
tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai02);
tempDirectory.AddFile(@"mondai\MondaiDocument2.xml", TestResources.Mondai03);
tempDirectory.AddFile(@"PronunciationInfoContainer.xml", TestResources.PronunciationInfoContainerXml);
// 読み込んではいけないファイル
tempDirectory.AddFile(@"mondai\help.xml", TestResources.HelpDocumentXml);
var data = EPuzzleData.Create(tempDirectory.Value);
// ファイルがない場合は作成する
Assert.True(File.Exists(data.SettingsFileName));
Assert.AreEqual(tempDirectory.Value, data.DataDir.DirectoryName);
CollectionAssert.AreEqual(new [] { "mondaiDocument1", "mondaiDocument2", }, data.MondaiDocuments.Select(x => x.Id));
Assert.AreEqual("User's Name", data.CurrentUserInfo.UserName);
Assert.AreEqual("mondaiDocument1", data.CurrentMondaiDocument.Id);
Assert.AreEqual("daimon1", data.GetDaimon(data.CurrentMondaiDocument.Id).Id);
Assert.False((bool)data.Settings.GetValue("常にカーソルを表示"));
data.Settings.SetValue("常にカーソルを表示", true);
// data.MondaiDocumentFileNames = new [] { "md.xml", "md2.xml", };
Assert.False(data.カード選択時に音聲ファイルを再生する);
data.カード選択時に音聲ファイルを再生する = true;
Assert.AreEqual(data.DataDir.FullPath("help"), data.HelpDirectory);
CollectionAssert.AreEqual(new [] { data.DataDir.FullPath(@"help\HelpDocument.xml"), }, data.HelpDocumentFileNames);
Assert.AreEqual("ResultImages", data.結果畫像のディレクトリ名);
// Assert.AreEqual("ResultImages", ResultImageManager.Instance.DirectoryName);
Assert.False(data.最後の問題を解いたあと次の畫麵に遷移しない);
Assert.AreEqual("PronunciationInfoContainer.xml", data.発音情報ファイルのパス);
data.発音情報ファイルのパス = tempDirectory.GetFullPath("PronunciationInfoContainer.xml");
Assert.NotNull(data.PronunciationInfoContainer);
var daimon1 = (Daimon)data.MondaiDocuments[1].GetItem("daimon1");
Assert.AreEqual("mondaiDocument2", daimon1.Parent.Id);
Assert.AreEqual("daimon1", daimon1.Id);
Assert.AreEqual(2, daimon1.Items.Count());
Assert.False(data.発音問題を有効にする);
data.発音問題を有効にする = true;
// 発音情報ファイルを設定する
tempDirectory.AddFile(@"p.xml", TestResources.PronunciationInfoContainerXml);
data.発音情報ファイルのパス = tempDirectory.FullPath(@"p.xml");
CollectionAssert.AreEqual(new []
{
"mondaiDocument1",
"mondaiDocument2",
}, data.家庭教師モードの対象になる問題ファイルのIDの配列);
data.家庭教師モードの対象になる問題ファイルのIDの配列 = new [] { "mondai2", "mondai3", };
Assert.AreEqual(TimeSpan.FromHours(12d), data.家庭教師モードにてこの時間以內の問題は無視する);
data.家庭教師モードにてこの時間以內の問題は無視する = TimeSpan.FromHours(6d);
Assert.AreEqual("ResultImages", data.CurrentUserInfo.ResultImageManager.DirectoryName);
Assert.AreEqual(tempDirectory.GetFullPath("ResultImageInfos.dat"), data.ResultImageInfoContainerFileName);
// ユーザー情報の保存
Assert.NotNull(data.CurrentUserInfo);
data.CurrentUserInfo.MondaiResults.AddNew("id_1", DateTime.MinValue, TimeSpan.FromSeconds(10d));
// 保存する
data.Save();
}
{
tempDirectory.DeleteFile(@"mondai\MondaiDocument.xml");
tempDirectory.DeleteFile(@"mondai\MondaiDocument2.xml");
tempDirectory.AddFile(@"mondai\md.xml", TestResources.Mondai02);
tempDirectory.AddFile(@"mondai\md2.xml", TestResources.Mondai03);
var data2 = EPuzzleData.Create(tempDirectory.DirectoryName);
var mondaiResult = data2.CurrentUserInfo.MondaiResults.First();
Assert.AreEqual("id_1", mondaiResult.MondaiId);
Assert.AreEqual(TimeSpan.FromSeconds(10d), mondaiResult.所要時間);
// Assert.AreEqual(new [] { "md.xml", "md2.xml" }, data2.MondaiDocumentFileNames);
Assert.True((bool)data2.Settings.GetValue("常にカーソルを表示"));
Assert.True(data2.カード選択時に音聲ファイルを再生する);
Assert.False(WindowState.常にカーソルを表示);
var window = new EPuzzleWindow(data2);
Assert.True(WindowState.常にカーソルを表示);
EPuzzleTime.NowObject = new TestNowObject();
EPuzzleTime.Now = DateTime.MinValue;
var daimon0 = (Daimon)data2.MondaiDocuments[0].GetItem("daimon3");
data2.CurrentUserInfo.SetLastDaimonInfo(daimon0);
//.........這裏部分代碼省略.........
示例12: GetRankTest
public void GetRankTest()
{
using (var tempDirectory = new TempDirectory(true))
{
tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
var userInfo = ePuzzleData.CurrentUserInfo;
var daimon2 = ePuzzleData.CurrentMondaiDocument.Items[1];
Assert.Throws<ArgumentNullException>(() =>
{
daimon2.Items[0].GetGradeString(null);
});
Assert.AreEqual("-", daimon2.Items[0].GetGradeString(userInfo));
}
}
示例13: ResultImageManagerCoreATest
public void ResultImageManagerCoreATest()
{
using (var tempDirectory = new TempDirectory(true))
{
{
var manager = new ResultImageManagerCoreA(tempDirectory.Name);
tempDirectory.AddFile(@"A\file0.png", "");
tempDirectory.AddFile(@"x[A]x[B]x\file0.bmp", "");
tempDirectory.AddFile(@"x[AB]x\file2.bmp", "");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath("A"),
tempDirectory.GetFullPath("x[A]x[B]x"),
}, manager.GetDirectories("A"));
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"x[A]x[B]x\file0.bmp"),
}, manager.GetNamesOfImageFilesFromDirectories("A"));
Assert.AreEqual("A", manager.GetDirectoryName(tempDirectory.GetFullPath(@"A\file0.png")));
Assert.AreEqual("", manager.GetDirectoryName(tempDirectory.GetFullPath(@"file0.png")));
tempDirectory.AddFile(@"c\file4.png", "");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"c\file4.png"),
}, manager.GetNamesOfImageFilesFromDirectories("C"));
}
}
}
示例14: Test1
public void Test1()
{
using (var tempDirectory = new TempDirectory(true))
{
{
var manager = new ResultImageManager2();
manager.DirectoryName = tempDirectory.Name;
tempDirectory.AddFile(@"A\file0.png", "");
tempDirectory.AddFile(@"B\file0.bmp", "");
tempDirectory.AddFile(@"D\file0.txt", "");
manager.PrepareForImages();
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"B\file0.bmp"),
}, manager.Files);
Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"B\file0.bmp"),
}, manager.Files);
Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
Assert.AreEqual(tempDirectory.GetFullPath(@"A\file0.png"), manager.GetFile("A"));
Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
Assert.AreEqual(tempDirectory.GetFullPath(@"B\file0.bmp"), manager.GetFile("B"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("D"));
Assert.Null(manager.GetFile("D"));
Assert.Null(manager.GetFile("D"));
tempDirectory.AddFile(@"file3.jpg", "");
/* Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("C"));
Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
Assert.AreEqual(tempDirectory.GetFullPath(@"file3.jpg"), manager.GetFile("D"));
*/
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("C"));
Assert.Null(manager.GetFile("D"));
Assert.Null(manager.GetFile("D"));
}
{
var manager = new ResultImageManager2();
manager.DirectoryName = tempDirectory.Name;
tempDirectory.AddFile(@"A\file1.png", "");
CollectionAssert.AreEquivalent(new []
{
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"A\file0.png"),
tempDirectory.GetFullPath(@"A\file1.png"),
tempDirectory.GetFullPath(@"A\file1.png"),
}, new []
{
manager.GetFile("A"),
manager.GetFile("A"),
manager.GetFile("A"),
manager.GetFile("A"),
});
}
}
}
示例15: using
public void AnkimonStateへの遷移()
{
EPuzzleWindow window = null;
using (var tempDirectory = new TempDirectory(true))
{
tempDirectory.AddFile(@"mondai\MondaiDocument.xml", TestResources.Mondai03);
tempDirectory.AddFile(@"help\HelpDocument.xml", TestResources.HelpDocumentXml);
var ePuzzleData = EPuzzleData.Create(tempDirectory.Name);
var data = ePuzzleData;
var userInfo = ePuzzleData.CurrentUserInfo;
WindowState.NowObject = new TestNowObject();
var t0 = new DateTime(2013, 8, 22, 0, 0, 0); // UTC
WindowState.NowObject.Now = t0;
window = new EPuzzleWindow(ePuzzleData);
var a = new Fish.eigotest.TestState(window);
a.MoveToStartGameState();
Assert.IsInstanceOf<FadeoutState>(window.State);
EPuzzleTime.Now += TimeSpan.FromSeconds(5d);
window.Tick();
Assert.IsInstanceOf<FadeinState>(window.State);
EPuzzleTime.Now += TimeSpan.FromSeconds(5d);
window.Tick();
userInfo.SetLastDaimonInfo(new LastDaimonInfo(data.CurrentMondaiDocument.Id, "daimon3", t0));
userInfo.MondaiResults.AddNew("3-1", t0, TimeSpan.FromSeconds(1d));
userInfo.MondaiResults.AddNew("3-2", t0, TimeSpan.FromSeconds(1d));
// ゲームスタート畫麵
Assert.IsInstanceOf<StartGameState>(window.State);
{
var item = window.State.Items.First(x => x.Name == "StartGameButton");
item.OnClick(new MouseEventInfo(MouseButtons.Left));
}
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<MondaiDocumentMenuState>(window.State);
{
var button = window.State.GetAllItems().Where(x => x.Tag is MondaiDocument).First();
window.State.CurrentItem = button;
window.State.OnAction0();
}
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
var daimonState = (DaimonState)window.State;
Assert.IsInstanceOf<DaimonState>(daimonState);
Assert.AreEqual("daimon3", daimonState.Daimon.Id);
var chumonButton = daimonState.GetAllItems().OfType<ChumonButton>().Single(x => "3-3" == x.Chumon.Id);
window.State.CurrentItem = chumonButton;
window.State.OnAction0();
window.Tick();
Assert.IsInstanceOf<ClickDeKaishiState>(window.State);
window.State.OnAction0();
window.Tick();
Assert.IsInstanceOf<AnkimonState>(window.State);
var ankimonState = (AnkimonState)window.State;
var ankimonRowContainer0 = ankimonState.GetAllItems().OfType<AnkimonRowContainer>().First();
var ankimonRowContainer1 = ankimonState.GetAllItems().OfType<AnkimonRowContainer>().ElementAt(1);
Assert.False(ankimonState.正解判定());
// Action3でエスケープステートに
window.State.OnAction3();
Assert.IsInstanceOf<PauseState>(window.State);
window.State.OnAction3();
Assert.IsInstanceOf<AnkimonState>(window.State);
var wordCards = ankimonRowContainer0.GetAllItems().Concat(ankimonRowContainer1.GetAllItems()).
Where(x => x is WordCard).ToArray();
ankimonRowContainer0.WordCardContainer.Items.Clear();
ankimonRowContainer1.WordCardContainer.Items.Clear();
Assert.False(ankimonState.正解判定());
ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swim"));
ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swam"));
ankimonRowContainer0.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "swum"));
ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "run"));
ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.First(x => x.Text == "ran"));
ankimonRowContainer1.WordCardContainer.Items.Add(wordCards.Where(x => x.Text == "run").ElementAt(1));
Assert.True(ankimonState.正解判定());
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
WindowState.NowObject.Now += TimeSpan.FromSeconds(10d);
window.Tick();
Assert.IsInstanceOf<ShomonState>(window.State);
window.Tick();
//.........這裏部分代碼省略.........