コード例 #1
0
        public static void ShouldReturnTrueWhenCalled()
        {
            // Arrange
            var msbuildCloneTask = new Clone(new Mock<IGitFacade>().Object)
            {
                // Mock away IBuildEngine cause we are not interested in the logging functionality.
                BuildEngine = new Mock<IBuildEngine>().Object,
                RepositoryToClone = string.Empty,
                TargetDirectory = string.Empty
            };

            // Act
            bool result = msbuildCloneTask.Execute();

            // Assert
            Assert.IsTrue(result);
        }
コード例 #2
0
        public static void CloneRepository()
        {
            // Arrange
            var mock = new Mock<IGitFacade>();
            var msbuildCloneTask = new Clone(mock.Object)
            {
                // Mock away IBuildEngine cause we are not interested in the logging functionality.
                BuildEngine = new Mock<IBuildEngine>().Object,
                RepositoryToClone = string.Empty,
                TargetDirectory = string.Empty
            };

            // Act
            Assert.IsTrue(msbuildCloneTask.Execute());

            // Assert
            mock.Verify(git => git.Clone(msbuildCloneTask.RepositoryToClone, msbuildCloneTask.TargetDirectory), Times.Once());
            mock.Verify(git => git.GetLatestSHA(msbuildCloneTask.TargetDirectory), Times.Once());
        }
コード例 #3
0
        public static void ShouldReturnFalseWhenExceptionOccurs()
        {
            // Arrange
            var gitMock = new Mock<IGitFacade>();
            var msbuildCloneTask = new Clone(gitMock.Object)
            {
                BuildEngine = new Mock<IBuildEngine>().Object,
                RepositoryToClone = string.Empty,
                TargetDirectory = string.Empty
            };

            gitMock.Setup(git => git.Clone(msbuildCloneTask.RepositoryToClone, msbuildCloneTask.TargetDirectory)).Throws<InvalidOperationException>();

            // Act 
            bool result = msbuildCloneTask.Execute();

            // Assert
            Assert.IsFalse(result);
        }
コード例 #4
0
        public static void ShouldLogErrorWhenExceptionErrors()
        {
            // Arrange
            var gitMock = new Mock<IGitFacade>();
            var buildengineMock = new Mock<IBuildEngine>();
            var msbuildCloneTask = new Clone(gitMock.Object)
            {
                BuildEngine = buildengineMock.Object,
                RepositoryToClone = string.Empty,
                TargetDirectory = string.Empty
            };
            gitMock.Setup(git => git.Clone(msbuildCloneTask.RepositoryToClone, msbuildCloneTask.TargetDirectory)).Throws<InvalidOperationException>();

            // Act 
            msbuildCloneTask.Execute();

            // Assert
            buildengineMock.Verify(msbuild => msbuild.LogErrorEvent(It.IsAny<BuildErrorEventArgs>()));
        }