protected override void OnExecute(CommandProcessor theProcessor)
        {
            var rand = new Random();

            if (Diagnostics.Settings.SimulateFileCorruption)
            {
                RandomError.Generate(
                    rand.Next() % 2 == 0,
                    String.Format("Corrupting the file {0}", _path),
                    delegate
                {
                    var f     = new FileInfo(_path);
                    long size = rand.Next(0, (int)f.Length / 2);
                    if (size <= 0)
                    {
                        FileStream s = FileStreamOpener.OpenForSoleUpdate(_path, FileMode.Truncate);
                        s.Flush();
                        s.Close();
                    }
                    else
                    {
                        FileStream s  = FileStreamOpener.OpenForRead(_path, FileMode.Open);
                        var buffer    = new byte[size];
                        int bytesRead = s.Read(buffer, 0, buffer.Length);
                        s.Close();

                        s = FileStreamOpener.OpenForSoleUpdate(_path, FileMode.Truncate);
                        s.Write(buffer, 0, bytesRead);
                        s.Flush();
                        s.Close();
                    }
                }
                    );
            }
        }
        public void ShouldReturnErrorCodeInCaseOfException()
        {
            IErraticService  erraticServiceTest  = new ErraticServiceImpl();
            ExceptionService stubService         = new ExceptionService();
            RandomError      randomError         = erraticServiceTest.Execute(stubService);
            RandomException  lastExceptionThrown = stubService.GetLastExceptionThrown();

            Assert.Equals(lastExceptionThrown.GetError().GetCode(), randomError.GetCode());
        }
Beispiel #3
0
 private static void SimulateErrors()
 {
     RandomError.Generate(Settings.SimulateEditError, "Update study errors");
 }