public void 定義したカスタムアクセッサを使えるか() { ApplicationRegistry.RegistCustomAccessor("CUSTOM", new CustomAccessor()); Assert.That(ApplicationRegistry.Get <ICustomRegistry>().AssemblyName, Is.EqualTo(Assembly.GetExecutingAssembly().GetName().Name)); }
public void データが見つからない場合は例外が発生する() { Assert.Throws <DataNotFoundException>(() => { Environment.SetEnvironmentVariable("ApplicationRegistries2.Test_IEnvironmentVariableRegistry_ListenPortNo", null); // ReSharper disable once UnusedVariable var listenPortNo = ApplicationRegistry.Get <IEnvironmentVariableRegistry>().ListenPortNo; }); }
public void Test() { var listenPortNo = ApplicationRegistry.Get <IDefaultValueRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80)); var testName = ApplicationRegistry.Get <IDefaultValueRegistry>().TestName; Assert.That(testName, Is.EqualTo("temp")); }
public void Prefixが変更された場合はそれに従う() { Environment.SetEnvironmentVariable("ApplicationRegistoryTest_PortNo", "81"); var listenPortNo = ApplicationRegistry.Get <IEnvironmentVariableRegistryWithPrefix>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(81)); Environment.SetEnvironmentVariable("ApplicationRegistoryTest_TestName", TestContext.CurrentContext.Test.Name); var testName = ApplicationRegistry.Get <IEnvironmentVariableRegistryWithPrefix>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void デフォルトの挙動() { Environment.SetEnvironmentVariable("ApplicationRegistries2.Test_IEnvironmentVariableRegistry_ListenPortNo", "80"); var listenPortNo = ApplicationRegistry.Get <IEnvironmentVariableRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80)); Environment.SetEnvironmentVariable("ApplicationRegistries2.Test_IEnvironmentVariableRegistry_TestName", TestContext.CurrentContext.Test.Name); var testName = ApplicationRegistry.Get <IEnvironmentVariableRegistry>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void 空のプレフィックスの場合はプロパティの名前だけでアクセスする() { Accessors.CommandlineArgumentsAccessor.OverrideCommandlineArgumentsForUnitTests(new[] { "--PortNo", "82", $"--TestName={TestContext.CurrentContext.Test.Name}", }); var listenPortNo = ApplicationRegistry.Get <ICommandlineRegistryWithNoPrefix>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(82)); var testName = ApplicationRegistry.Get <ICommandlineRegistryWithNoPrefix>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void プレフィックス付きの場合() { Accessors.CommandlineArgumentsAccessor.OverrideCommandlineArgumentsForUnitTests(new[] { "--Test_PortNo", "81", $"--Test_TestName={TestContext.CurrentContext.Test.Name}", }); var listenPortNo = ApplicationRegistry.Get <ICommandlineRegistryWithPrefix>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(81)); var testName = ApplicationRegistry.Get <ICommandlineRegistryWithPrefix>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void Test() { Accessors.CommandlineArgumentsAccessor.OverrideCommandlineArgumentsForUnitTests(new[] { "--ICommandlineRegistry_ListenPortNo=80", "--ICommandlineRegistry_TestName", TestContext.CurrentContext.Test.Name }); var listenPortNo = ApplicationRegistry.Get <ICommandlineRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80)); var testName = ApplicationRegistry.Get <ICommandlineRegistry>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void プレフィックス付きの場合はそのキーと名前から取得する() { using (var key = Registry.CurrentUser.CreateSubKey(@"Software\ApplicationRegistries\Temp")) { // ReSharper disable once PossibleNullReferenceException key.SetValue("ListenPortNo", 81, RegistryValueKind.DWord); key.SetValue("Temp", TestContext.CurrentContext.Test.Name, RegistryValueKind.String); } var listenPortNo = ApplicationRegistry.Get <IUserRegistryRegistryWithPrefix>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(81)); var testName = ApplicationRegistry.Get <IUserRegistryRegistryWithPrefix>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void Test() { using (var key = Registry.CurrentUser.CreateSubKey(@"Software\ApplicationRegistries\ApplicationRegistries2.Test\IUserRegistryRegistry")) { // ReSharper disable once PossibleNullReferenceException key.SetValue("ListenPortNo", 80, RegistryValueKind.DWord); key.SetValue("TestName", TestContext.CurrentContext.Test.Name, RegistryValueKind.String); } var listenPortNo = ApplicationRegistry.Get <IUserRegistryRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80)); var testName = ApplicationRegistry.Get <IUserRegistryRegistry>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void キーが指定されない場合はデフォルトの優先順位になる() { var listenPortNo = ApplicationRegistry.Get <IDefaultAttributeRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80), "外部設定がない場合はデフォルト値が使われる"); var xmlContents = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ApplicationRegisties> <IDefaultAttributeRegistry> <ListenPortNo>81</ListenPortNo> </IDefaultAttributeRegistry> </ApplicationRegisties> "; File.WriteAllText(_defaultXmlFilePath, xmlContents, Encoding.UTF8); listenPortNo = ApplicationRegistry.Get <IDefaultAttributeRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(81), "XMLファイルがあればそれに従う"); using (var key = Registry.CurrentUser.CreateSubKey(@"Software\ApplicationRegistries\ApplicationRegistries2.Test\IDefaultAttributeRegistry")) { // ReSharper disable once PossibleNullReferenceException key.SetValue("ListenPortNo", 82, RegistryValueKind.DWord); } listenPortNo = ApplicationRegistry.Get <IDefaultAttributeRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(82), "ユーザーレジストリがあれば、XMLを上書きする"); Environment.SetEnvironmentVariable("ApplicationRegistries2.Test_IDefaultAttributeRegistry_ListenPortNo", "83"); listenPortNo = ApplicationRegistry.Get <IDefaultAttributeRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(83), "環境変数があれば、ユーザーレジストリを上書きする"); Accessors.CommandlineArgumentsAccessor.OverrideCommandlineArgumentsForUnitTests(new[] { "--IDefaultAttributeRegistry_ListenPortNo=84" }); listenPortNo = ApplicationRegistry.Get <IDefaultAttributeRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(84), "コマンドライン引数があれば、環境変数を上書きする"); }
public void Xmlのルートパスを変える() { var xmlContents = $@"<?xml version=""1.0"" encoding=""utf-8"" ?> <XmlFileRegistryTest> <PortNo>82</PortNo> <TestName>{TestContext.CurrentContext.Test.Name}</TestName> </XmlFileRegistryTest> "; File.WriteAllText(_otherXmlFilePath, xmlContents, Encoding.UTF8); var listenPortNo = ApplicationRegistry.Get <IXmlFileRegistryWithOtherFileAndOtherRoot>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(82)); var testName = ApplicationRegistry.Get <IXmlFileRegistryWithOtherFileAndOtherRoot>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void 別のXmlファイルの指定() { var xmlContents = $@"<?xml version=""1.0"" encoding=""utf-8"" ?> <ApplicationRegisties> <IXmlFileRegistryWithOtherFile> <PortNo>81</PortNo> <TestName>{TestContext.CurrentContext.Test.Name}</TestName> </IXmlFileRegistryWithOtherFile> </ApplicationRegisties> "; File.WriteAllText(_otherXmlFilePath, xmlContents, Encoding.UTF8); var listenPortNo = ApplicationRegistry.Get <IXmlFileRegistryWithOtherFile>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(81)); var testName = ApplicationRegistry.Get <IXmlFileRegistryWithOtherFile>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }
public void Test() { var xmlContents = $@"<?xml version=""1.0"" encoding=""utf-8"" ?> <ApplicationRegisties> <IXmlFileRegistry> <ListenPortNo>80</ListenPortNo> <TestName>{TestContext.CurrentContext.Test.Name}</TestName> </IXmlFileRegistry> </ApplicationRegisties> "; File.WriteAllText(_defaultXmlFilePath, xmlContents, Encoding.UTF8); var listenPortNo = ApplicationRegistry.Get <IXmlFileRegistry>().ListenPortNo; Assert.That(listenPortNo, Is.EqualTo(80)); var testName = ApplicationRegistry.Get <IXmlFileRegistry>().TestName; Assert.That(testName, Is.EqualTo(TestContext.CurrentContext.Test.Name)); }