예제 #1
0
        public void ToFile_RebaseDocumentHasOneCompleteItem_ItemIsWritten()
        {
            const string filePath = "COMMIT_EDITMSG";

            var fileSystemMock = new Mock <IFileSystem>();

            var rebaseItem = new RebaseItem
            {
                Action     = RebaseAction.Edit,
                CommitHash = "Hash",
                Subject    = "Subject"
            };

            var rebaseDocument = new RebaseDocument
            {
                Items = rebaseItem.AsArray()
            };

            var rebaseFileWriter = new RebaseFileWriter(fileSystemMock.Object);

            rebaseFileWriter.ToFile(filePath, rebaseDocument);

            fileSystemMock.Verify(fs => fs.WriteAllLines(filePath, It.Is <IEnumerable <string> >(c =>
                                                                                                 c.Contains(rebaseItem.ToString()))), Times.Once());
        }
예제 #2
0
        public void ToFile_RebaseDocumentHasNullItems_ThrowsArgumentException()
        {
            var rebaseFileWriter = new RebaseFileWriter(Mock.Of <IFileSystem>());

            Action toFile = () => rebaseFileWriter.ToFile("NotNullString", new RebaseDocument());

            toFile.ShouldThrow <ArgumentException>();
        }
예제 #3
0
        public void ToFile_FilePathIsInvalid_ThrowsArgumentException(string filePath)
        {
            var rebaseFileWriter = new RebaseFileWriter(Mock.Of <IFileSystem>());

            Action toFile = () => rebaseFileWriter.ToFile(filePath, null);

            toFile.ShouldThrow <ArgumentException>();
        }
예제 #4
0
        public void ToFile_DiskAccessFails_ThrowsGitModelExceptionWithCorrectInnerException()
        {
            var innerException = new UnauthorizedAccessException();

            var fileSystemMock = new Mock <IFileSystem>();

            fileSystemMock.Setup(fs => fs.WriteAllLines(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()))
            .Throws(innerException);

            var rebaseDocument = new RebaseDocument
            {
                Items = new RebaseItem[0]
            };

            var rebaseFileWriter = new RebaseFileWriter(fileSystemMock.Object);

            Action toFile = () => rebaseFileWriter.ToFile("Valid File Path", rebaseDocument);

            toFile.ShouldThrow <GitModelException>().Which.InnerException.Should().Be(innerException);
        }