Beispiel #1
0
        public void ReadExceptionFileFailureDoesNotThrow()
        {
            var mockFile = Mock.Of <File>();

            Mock.Get(mockFile).Setup(file => file.ReadAllText()).Throws(new System.IO.IOException());
            Assert.IsNull(ErrorLogHelper.ReadExceptionFile(mockFile));
        }
Beispiel #2
0
        public void ReadExceptionFile()
        {
            var expectedException = new ArgumentException("test");
            var mockFile          = Mock.Of <File>();
            var mockStream        = new System.IO.MemoryStream();

            new BinaryFormatter().Serialize(mockStream, expectedException);
            mockStream.Position = 0;
            string actualFullFileName = null;

            System.IO.FileMode?actualFileMode = null;

            Mock.Get(mockFile).Setup(f => f.FullName).Returns("test.exception");
            ErrorLogHelper.Instance.NewFileStream = (name, mode) =>
            {
                actualFullFileName = name;
                actualFileMode     = mode;
                return(mockStream);
            };

            var actualException = ErrorLogHelper.ReadExceptionFile(mockFile);

            Assert.IsInstanceOfType(actualException, expectedException.GetType());
            Assert.AreEqual(expectedException.Message, actualException.Message);
            Assert.AreEqual(mockFile.FullName, actualFullFileName);
            Assert.AreEqual(System.IO.FileMode.Open, actualFileMode);
        }
Beispiel #3
0
        public void ReadExceptionFile()
        {
            var expectedException = new ArgumentException("test");
            var mockFile          = Mock.Of <File>();

            Mock.Get(mockFile).Setup(file => file.ReadAllText()).Returns(expectedException.ToString());

            var actualException = ErrorLogHelper.ReadExceptionFile(mockFile);

            Assert.AreEqual(expectedException.ToString(), actualException);
        }
Beispiel #4
0
        public void ReadExceptionFileFailureDoesNotThrow()
        {
            var    mockFile           = Mock.Of <File>();
            var    mockStream         = Mock.Of <System.IO.Stream>();
            string actualFullFileName = null;

            System.IO.FileMode?actualFileMode = null;

            Mock.Get(mockFile).Setup(f => f.FullName).Returns("test.exception");
            ErrorLogHelper.Instance.NewFileStream = (name, mode) =>
            {
                actualFullFileName = name;
                actualFileMode     = mode;
                return(mockStream);
            };

            var actualException = ErrorLogHelper.ReadExceptionFile(mockFile);

            Assert.IsNull(actualException);
            Assert.AreEqual(mockFile.FullName, actualFullFileName);
            Assert.AreEqual(System.IO.FileMode.Open, actualFileMode);
        }