public void Setting_the_cryptoprovider_that_causes_failure_should_restore_the_original_provider() { /* Arrange */ var p = A.Fake<IConfigProvider>(); A.CallTo(() => p.LoadConfig()).ReturnsLazily(_ => new[] { TestConfigFactory.CreateConfig() }); var cryptoNew = A.Fake<ICryptoProvider>(); A.CallTo(() => cryptoNew.Encrypt(A<string>.Ignored)).Throws(new Exception()); var settingOne = new ConfigComplex { Encrypted = "One" }; /* Act */ var mgr = ConfigManager.Create(p); mgr.SetSettings(TestSection.SectionOne, settingOne); Action a = () => mgr.SetCryptoProvider(cryptoNew); /* Assert */ a.ShouldThrow<Exception>(); mgr.CryptoProvider.Should().BeOfType<AesCryptoProvider>(); }
public void Setting_the_cryptoprovider_by_type_should_work_as_expected() { /* Arrange */ var doc = TestConfigFactory.CreateConfig(); var p = A.Fake<IConfigProvider>(); A.CallTo(() => p.LoadConfig()).Returns(new[] { doc }); var settingOne = new ConfigComplex { Encrypted = "One" }; /* Act */ var mgr = ConfigManager.Create(p); mgr.SetSettings(TestSection.SectionOne, settingOne); mgr.SetCryptoProvider(typeof(CryptoCustom)); mgr.Reload(); /* Assert */ mgr.CryptoProvider.Should().BeOfType<CryptoCustom>(); }
public void Setting_the_cryptoprovider_should_work_as_expected() { /* Arrange */ var doc = TestConfigFactory.CreateConfig(); var p = A.Fake<IConfigProvider>(); A.CallTo(() => p.LoadConfig()).Returns(new[] { doc }); var settingOne = new ConfigComplex { Encrypted = "One" }; var settingTwo = new ConfigComplex { Encrypted = "Two" }; var cryptoNew = A.Fake<ICryptoProvider>(); A.CallTo(() => cryptoNew.Encrypt(A<string>.Ignored)).ReturnsLazily(h => h.Arguments[0].ToString()); /* Act */ var mgr = ConfigManager.Create(p); mgr.SetSettings(TestSection.SectionOne, settingOne); mgr.SetSettings(TestSection.SectionTwo, settingTwo); mgr.SetCryptoProvider(cryptoNew); /* Assert */ A.CallTo(() => cryptoNew.Encrypt(A<string>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(2)); }
public void Setting_and_getting_complex_settings_should_work() { /* Arrange */ var doc = TestConfigFactory.CreateConfig(); var p = A.Fake<IConfigProvider>(); A.CallTo(() => p.LoadConfig()).Returns(new[] { doc }); var settingsOne = new ConfigWithBasicProps { StringValue = "One" }; var settingsTwo = new ConfigWithBasicProps { StringValue = "Two" }; var settingsThree = new ConfigComplex { Name = "Three" }; /* Act */ var mgr = ConfigManager.Create(p); mgr.MonitorEvents(); mgr.SetSettings(TestSection.SectionOne, settingsOne); mgr.SetSettings(settingsTwo); mgr.SetSettings(settingsThree); var readSectionOne = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne); var readSectionTwo = mgr.GetSettings<ConfigWithBasicProps>(); var allBasics = mgr.GetSettingsList<ConfigWithBasicProps>(); mgr.Reload(); var readSectionOneAfterReload = mgr.GetSettings<ConfigWithBasicProps>(TestSection.SectionOne); var readSectionTwoAfterReload = mgr.GetSettings<ConfigWithBasicProps>(); int sectionCount = mgr.Sections.Count(); /* Assert */ A.CallTo(() => p.SaveConfig(doc)).MustNotHaveHappened(); readSectionOne.Should().NotBeNull(); readSectionOne.Should().NotBeSameAs(settingsOne); readSectionOne.ShouldBeEquivalentTo(settingsOne); readSectionTwo.Should().NotBeNull(); readSectionTwo.Should().NotBeSameAs(settingsTwo); readSectionTwo.ShouldBeEquivalentTo(settingsTwo); readSectionOneAfterReload.Should().NotBeNull(); readSectionOneAfterReload.ShouldBeEquivalentTo(settingsOne); readSectionTwoAfterReload.Should().NotBeNull(); readSectionTwoAfterReload.ShouldBeEquivalentTo(settingsTwo); allBasics.Count.Should().Be(2); sectionCount.Should().Be(3); mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "SectionOne" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged && e.SectionType == typeof(ConfigWithBasicProps)); mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "ConfigWithBasicProps" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged); mgr.ShouldRaise("ConfigChanged").WithArgs<ConfigChangedEventArgs>(e => e.SectionName == "ConfigComplex" && e.Cause == ConfigChangedEventArgs.ChangeCause.SectionChanged); }