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 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); }