public async Task AddHookValid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var repo = new Data.Repository();

            repo.Token     = "1";
            repo.Url       = "http://github.com/lyzerk/TriggrTestProject";
            repo.OwnerName = "lyzerk";
            repo.Name      = "TriggrTestProject";

            var mockResult = new RepositoryHook(1, null, null, null, DateTimeOffset.Now, DateTimeOffset.Now, null, null, false, null);
            var mockConfig = new Mock <IOptions <TriggrConfig> >();
            var mockClient = new Mock <GithubWrapper>();

            mockConfig.Setup(i => i.Value).Returns(config);
            mockClient.Setup(i => i.CreateWebhook(repo.OwnerName, repo.Name, config.Url + "GithubWebhook/HandlerForPush", "1"))
            .ReturnsAsync(mockResult);

            WebhookService service = new WebhookService(null, mockConfig.Object, mockClient.Object);

            var result = await service.AddHookAsync(repo);

            Assert.True(result);
            Assert.True(repo.WebHook);
            Assert.NotNull(repo.WebHookId);
        }
        public void IsSupportInvalid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);

            Assert.False(service.IsSupport("http://bitbucket.com/lyzerk/TriggrTestProject"));
        }
        public void WebhookUrlWithEmptyString()
        {
            var config = new TriggrConfig();

            config.Url     = string.Empty;
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);
            Action         action  = () => service.WebhookUrl();

            Assert.ThrowsAny <UriFormatException>(action);
        }
        public void WebhookUrlWithValid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);

            var result = service.WebhookUrl();

            Assert.Equal(config.Url + "GithubWebhook/HandlerForPush", result);
        }
        public void WebhookUrlWithLocalhostAndNoProtocol()
        {
            var config = new TriggrConfig();

            config.Url     = "localhost";
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);

            var result = service.WebhookUrl();

            Assert.Equal($"http://{config.Url}/GithubWebhook/HandlerForPush", result);
        }
        public async Task AddHookInvalid()
        {
            var config = new TriggrConfig();

            config.Url     = "http://www.triggr.com/";
            config.Webhook = true;

            var mock = new Mock <IOptions <TriggrConfig> >();

            mock.Setup(i => i.Value).Returns(config);

            WebhookService service = new WebhookService(null, mock.Object, null);
            var            repo    = new Data.Repository();

            repo.Token = "1";
            repo.Url   = "http://githu1b.com/lyzerk/TriggrTestProject";
            var result = await service.AddHookAsync(repo);

            Assert.False(result);
        }
Esempio n. 7
0
 public WebhookService(IProviderFactory providerFactory, IOptions <TriggrConfig> config, GithubWrapper client)
 {
     _providerFactory = providerFactory;
     _config          = config.Value;
     _client          = client;
 }