From 3c5726c7bad28165f446885048e6137fd2f13f98 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Tue, 29 Sep 2015 00:22:34 +1000 Subject: [PATCH] Add unit tests --- .../Models/NewRepositoryWebHookTests.cs | 71 +++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + 2 files changed, 72 insertions(+) create mode 100644 Octokit.Tests/Models/NewRepositoryWebHookTests.cs diff --git a/Octokit.Tests/Models/NewRepositoryWebHookTests.cs b/Octokit.Tests/Models/NewRepositoryWebHookTests.cs new file mode 100644 index 0000000000..efa4d3dde5 --- /dev/null +++ b/Octokit.Tests/Models/NewRepositoryWebHookTests.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using Xunit; + +namespace Octokit.Tests.Models +{ + public class NewRepositoryWebHookTests + { + public class TheCtor + { + [Fact] + public void UsesDefaultValuesForDefaultConfig() + { + var create = new NewRepositoryWebHook("windowsazure", new Dictionary(), "http://test.com/example"); + + Assert.Equal(create.Config.Count, 4); + + Assert.True(create.Config.ContainsKey("url")); + Assert.True(create.Config.ContainsKey("content_type")); + Assert.True(create.Config.ContainsKey("secret")); + Assert.True(create.Config.ContainsKey("insecure_ssl")); + + Assert.Equal(create.Config["url"], "http://test.com/example"); + Assert.Equal(create.Config["content_type"], WebHookContentType.Form.ToParameter()); + Assert.Equal(create.Config["secret"], ""); + Assert.Equal(create.Config["insecure_ssl"], "0"); + + Assert.Equal(create.Url, "http://test.com/example"); + Assert.Equal(create.ContentType, WebHookContentType.Form); + Assert.Empty(create.Secret); + Assert.False(create.InsecureSsl); + } + + [Fact] + public void CombinesUserSpecifiedContentTypeWithConfig() + { + var config = new Dictionary + { + {"hostname", "http://hostname.url"}, + {"username", "username"}, + {"password", "password"} + }; + + var create = new NewRepositoryWebHook("windowsazure", config, "http://test.com/example", WebHookContentType.Json, string.Empty, true); + + Assert.Equal(create.Config.Count, 7); + + Assert.True(create.Config.ContainsKey("url")); + Assert.True(create.Config.ContainsKey("content_type")); + Assert.True(create.Config.ContainsKey("secret")); + Assert.True(create.Config.ContainsKey("insecure_ssl")); + + Assert.Equal(create.Config["url"], "http://test.com/example"); + Assert.Equal(create.Config["content_type"], WebHookContentType.Json.ToParameter()); + Assert.Equal(create.Config["secret"], ""); + Assert.Equal(create.Config["insecure_ssl"], "1"); + + Assert.True(create.Config.ContainsKey("hostname")); + Assert.Equal(create.Config["hostname"], config["hostname"]); + Assert.True(create.Config.ContainsKey("username")); + Assert.Equal(create.Config["username"], config["username"]); + Assert.True(create.Config.ContainsKey("password")); + Assert.Equal(create.Config["password"], config["password"]); + + Assert.Equal(create.Url, "http://test.com/example"); + Assert.Equal(create.ContentType, WebHookContentType.Json); + Assert.Empty(create.Secret); + Assert.True(create.InsecureSsl); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 9c00502159..804ebfc417 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -157,6 +157,7 @@ +