Esempio n. 1
0
        public async Task DeleteRepository_GiteaServiceIsCalled()
        {
            // Arrange
            string org       = "ttd";
            string app       = "app-for-deletion";
            string developer = "testUser";

            await PrepareTestData(org, app, developer);

            Mock <IGitea> mock = new Mock <IGitea>();

            mock.Setup(m => m.DeleteRepository(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true);

            SourceControlSI sut = GetServiceForTest(developer, mock);

            // Act
            await sut.DeleteRepository(org, app);

            string expectedPath = TestDataHelper.GetTestDataRepositoryDirectory(org, app, developer);

            // Assert
            mock.VerifyAll();
            Assert.False(Directory.Exists(expectedPath));
        }
Esempio n. 2
0
        public async Task CreatePullRequest_InputMappedCorectlyToCreatePullRequestOption()
        {
            // Arrange
            string target = "master";
            string source = "branch";

            Mock <IGitea> mock = new Mock <IGitea>();

            mock.Setup(m => m.CreatePullRequest(
                           It.IsAny <string>(),
                           It.IsAny <string>(),
                           It.Is <CreatePullRequestOption>(o => o.Base == target && o.Head == source)))
            .ReturnsAsync(true);

            SourceControlSI sut = GetServiceForTest("testUser", mock);

            // Act
            await sut.CreatePullRequest("ttd", "apps-test", target, source, "title");

            // Assert
            mock.VerifyAll();
        }
Esempio n. 3
0
        private static SourceControlSI GetServiceForTest(string developer, Mock <IGitea> giteaMock = null)
        {
            HttpContext ctx = GetHttpContextForTestUser(developer);

            Mock <IHttpContextAccessor> httpContextAccessorMock = new Mock <IHttpContextAccessor>();

            httpContextAccessorMock.Setup(s => s.HttpContext).Returns(ctx);

            giteaMock ??= new Mock <IGitea>();
            IOptions <ServiceRepositorySettings> repoSettings = Options.Create(new ServiceRepositorySettings());
            string unitTestFolder = Path.GetDirectoryName(new Uri(typeof(RepositorySITests).Assembly.Location).LocalPath);

            repoSettings.Value.RepositoryLocation = Path.Combine(unitTestFolder, "..", "..", "..", "_TestData", "Repositories") + Path.DirectorySeparatorChar;

            SourceControlSI service = new SourceControlSI(
                repoSettings,
                new Mock <IOptions <GeneralSettings> >().Object,
                new Mock <IDefaultFileFactory>().Object,
                httpContextAccessorMock.Object,
                giteaMock.Object,
                new Mock <ILogger <SourceControlSI> >().Object);

            return(service);
        }