Ejemplo n.º 1
0
        public async Task <string> CreateGist(string description, IEnumerable <SnippetFile> files, bool isPublic)
        {
            var request = new CreateGistRequest
            {
                Public      = isPublic,
                Description = description,
                Files       = files.Select(x => new GistFile {
                    FileName = x.Name, Content = x.ReadAllText()
                }).ToList()
            };

            var response = await _gitHub.CreateGist(request.ToJObject());

            return(response.Url);
        }
Ejemplo n.º 2
0
        public void ToJObject_CreatesValidJsonObject()
        {
            var request = new CreateGistRequest
            {
                Description = "Here is a gist I created.",
                Public      = true,
                Files       = new List <GistFile>
                {
                    new GistFile
                    {
                        FileName = "blah.cs",
                        Content  = "Console.WriteLine(\"This is a test!\");"
                    },
                    new GistFile
                    {
                        FileName = "readme.md",
                        Content  = "# This is a header"
                    }
                }
            };

            const string expected = @"{
                                        ""public"": true,
                                        ""description"": ""Here is a gist I created."",
                                        ""files"": {
                                            ""0"" : {
                                                ""filename"": ""blah.cs"",
                                                ""content"": ""Console.WriteLine(\""This is a test!\"");""
                                            },
                                            ""1"": {
                                                ""filename"": ""readme.md"",
                                                ""content"": ""# This is a header""
                                            }
                                        }
                                    }";

            var jo = request.ToJObject();
            var e  = JObject.Parse(expected);

            jo.Should().BeEquivalentTo(e);
        }