public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var fileAccess = new FakeFileAccess(() => { // ReSharper disable once AccessToModifiedClosure if (fail) { throw new Exception("Simulated"); } return XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>"); }); var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); await monitor.PerformStartup(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var fileAccess = new FakeFileAccess(() => { // ReSharper disable once AccessToModifiedClosure if (fail) { throw new Exception("Simulated"); } return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>")); }); var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); await monitor.Start(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public void Should_log_added_endpoints() { var fileAccess = new FakeFileAccess(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>")); var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances()); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath': Added endpoint 'A' with 2 instances")); }
public void Should_log_added_endpoints() { var fileAccess = new FakeFileAccess(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>")); var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances()); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath': Added endpoint 'A' with 2 instances")); }
public void Should_log_removed_endpoints() { var fileData = new Queue <string>(); fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"); fileData.Enqueue("<endpoints></endpoints>"); var fileAccess = new FakeFileAccess(() => XDocument.Parse(fileData.Dequeue())); var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances()); monitor.ReloadData(); logOutput.Clear(); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath': Removed all instances of endpoint 'A'")); }
public void Reload_should_throw_when_file_does_not_exist() { const string filePath = "some file path"; var timer = new FakeTimer(); var fileAccessException = new Exception("Simulated"); var fileAccess = new FakeFileAccess(() => { throw fileAccessException; }); var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); var exception = Assert.Throws <Exception>(() => monitor.ReloadData()); Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details.")); Assert.That(exception.InnerException, Is.EqualTo(fileAccessException)); }
public void Reload_should_throw_when_file_does_not_exist() { const string filePath = "some file path"; var timer = new FakeTimer(); var fileAccessException = new Exception("Simulated"); var fileAccess = new FakeFileAccess(() => { throw fileAccessException; }); var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances()); var exception = Assert.Throws<Exception>(() => monitor.ReloadData()); Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details.")); Assert.That(exception.InnerException, Is.EqualTo(fileAccessException)); }
public static void BeforeFeatures() { var fakeFileAccess = new FakeFileAccess(); var fakePathProvider = new FakePathProvider { PathToXmlFile = @"c:\temp\file.xml", PathToYnabFile = @"c:\temp\file.ynab", PathToCsvFile = @"c:\temp\file.csv" }; CurrentScenarioContext.FakeFileAccess = fakeFileAccess; CurrentScenarioContext.InitializeEasyBankContext( new EasyBankContext( new CsvAgent(new CsvGateway(fakeFileAccess, fakePathProvider), new CsvMapper()), new YnabAgent(new YnabGateway(fakeFileAccess, fakePathProvider, CultureSettings.American()), new YnabMapper()), new XmlAgent(new XmlGateway(fakeFileAccess, fakePathProvider), new XmlMapper()), fakeFileAccess, new FakePathProvider())); }
public void Should_log_removed_endpoints() { var fileData = new Queue<string>(); fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"); fileData.Enqueue(@"<endpoints></endpoints>"); var fileAccess = new FakeFileAccess(() => XDocument.Parse(fileData.Dequeue())); var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances()); monitor.ReloadData(); logOutput.Clear(); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath': Removed all instances of endpoint 'A'")); }