From aa709dc0df9c6ab181f559fa1ffdb7667451586e Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sat, 7 May 2016 15:27:18 -0500 Subject: [PATCH 001/223] Create a more generic catch all data mapper, including support for datetime. --- src/SparkPost.Tests/DataMapperTests.cs | 18 ++++++++++++++++++ src/SparkPost/DataMapper.cs | 8 ++++++++ src/SparkPost/SparkPost.csproj | 1 + .../ValueMappers/DateTimeValueMapper.cs | 17 +++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 src/SparkPost/ValueMappers/DateTimeValueMapper.cs diff --git a/src/SparkPost.Tests/DataMapperTests.cs b/src/SparkPost.Tests/DataMapperTests.cs index 238b2693..78559528 100644 --- a/src/SparkPost.Tests/DataMapperTests.cs +++ b/src/SparkPost.Tests/DataMapperTests.cs @@ -872,5 +872,23 @@ public void ComplianceStatus() dataMapper.ToDictionary(subaccount)["compliance_status"].ShouldEqual(subaccount.ComplianceStatus); } } + + [TestFixture] + public class AnythingTests + { + [Test] + public void It_should_map_anything_using_our_conventions() + { + var dataMapper = new DataMapper(); + + var dateTime = new DateTime(2016, 1, 2, 3, 4, 5); + + var result = dataMapper.CatchAll(new {FirstName = "Test1", LastName = "Test2", TheDate = dateTime}); + + result["first_name"].ShouldEqual("Test1"); + result["last_name"].ShouldEqual("Test2"); + ((string)result["the_date"]).Substring(0, 19).ShouldEqual("2016-01-02T03:04:05"); + } + } } } \ No newline at end of file diff --git a/src/SparkPost/DataMapper.cs b/src/SparkPost/DataMapper.cs index 4107081c..7691f274 100644 --- a/src/SparkPost/DataMapper.cs +++ b/src/SparkPost/DataMapper.cs @@ -20,6 +20,7 @@ public interface IDataMapper IDictionary ToDictionary(Suppression suppression); IDictionary ToDictionary(Webhook webhook); IDictionary ToDictionary(Subaccount subaccount); + IDictionary CatchAll(object anything); object GetTheValue(Type propertyType, object value); } @@ -36,6 +37,8 @@ public DataMapper(string version = "v1") new BooleanValueMapper(), new EnumValueMapper(), new DateTimeOffsetValueMapper(), + new DateTimeValueMapper(), + new DateTimeNullableValueMapper(), new StringObjectDictionaryValueMapper(this), new StringStringDictionaryValueMapper(), new EnumerableValueMapper(this), @@ -120,6 +123,11 @@ public IDictionary ToDictionary(Subaccount subaccount) return WithCommonConventions(subaccount); } + public IDictionary CatchAll(object anything) + { + return WithCommonConventions(anything); + } + private static bool AnyValuesWereSetOn(object target) { return target.GetType() diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index 13864198..529d1781 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -120,6 +120,7 @@ + diff --git a/src/SparkPost/ValueMappers/DateTimeValueMapper.cs b/src/SparkPost/ValueMappers/DateTimeValueMapper.cs new file mode 100644 index 00000000..4eb92402 --- /dev/null +++ b/src/SparkPost/ValueMappers/DateTimeValueMapper.cs @@ -0,0 +1,17 @@ +using System; + +namespace SparkPost.ValueMappers +{ + public class DateTimeValueMapper : IValueMapper + { + public bool CanMap(Type propertyType, object value) + { + return value is DateTime; + } + + public object Map(Type propertyType, object value) + { + return string.Format("{0:s}{0:zzz}", (DateTime) value); + } + } +} \ No newline at end of file From 52d7901eab051053fc1086a2bfc3069a3368d981 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 15:20:55 -0500 Subject: [PATCH 002/223] This does not exist yet. --- src/SparkPost/DataMapper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SparkPost/DataMapper.cs b/src/SparkPost/DataMapper.cs index 7691f274..25fe836c 100644 --- a/src/SparkPost/DataMapper.cs +++ b/src/SparkPost/DataMapper.cs @@ -38,7 +38,6 @@ public DataMapper(string version = "v1") new EnumValueMapper(), new DateTimeOffsetValueMapper(), new DateTimeValueMapper(), - new DateTimeNullableValueMapper(), new StringObjectDictionaryValueMapper(this), new StringStringDictionaryValueMapper(), new EnumerableValueMapper(this), From 88b01ca55ceb1cd01b40d65aa17848c1668910d0 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 15:31:59 -0500 Subject: [PATCH 003/223] Drop the attributes from the query object. --- src/SparkPost/IsoDateTimeMinuteConverter.cs | 12 ------------ src/SparkPost/MessageEventsQuery.cs | 5 ----- src/SparkPost/SparkPost.csproj | 1 - 3 files changed, 18 deletions(-) delete mode 100644 src/SparkPost/IsoDateTimeMinuteConverter.cs diff --git a/src/SparkPost/IsoDateTimeMinuteConverter.cs b/src/SparkPost/IsoDateTimeMinuteConverter.cs deleted file mode 100644 index af241ce2..00000000 --- a/src/SparkPost/IsoDateTimeMinuteConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Newtonsoft.Json.Converters; - -namespace SparkPost -{ - public class IsoDateTimeMinuteConverter : IsoDateTimeConverter - { - public IsoDateTimeMinuteConverter() - { - this.DateTimeFormat = "yyyy-MM-ddTHH:mm"; - } - } -} diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index 54edfe57..645af1c5 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using SparkPost.Utilities; using System; using System.Collections.Generic; @@ -30,7 +29,6 @@ public MessageEventsQuery() /// events : List : Comma-delimited list of event types to search. Defaults to all event types. /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. /// - [Newtonsoft.Json.JsonProperty("Events")] public string EventsJson { get @@ -43,7 +41,6 @@ public string EventsJson /// events : List : Comma-delimited list of event types to search. Defaults to all event types. /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. /// - [Newtonsoft.Json.JsonIgnore] public IList Events { get; set; } /// @@ -56,7 +53,6 @@ public string EventsJson /// Example: 2014-07-20T08:00. /// Default: One hour ago. /// - [JsonConverter(typeof(IsoDateTimeMinuteConverter))] public DateTime? From { get; set; } /// @@ -115,7 +111,6 @@ public string EventsJson /// Example: 2014-07-20T09:00. /// Default: now. /// - [JsonConverter(typeof(IsoDateTimeMinuteConverter))] public DateTime? To { get; set; } /// diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index 529d1781..dedf57ea 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -57,7 +57,6 @@ - From 66a6d61e686d2da8f24062f6f33b1366a33c9d60 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:04:25 -0500 Subject: [PATCH 004/223] Get the date time checks to work through Get, also started using the data mapper for the get requests. --- src/SparkPost/MessageEventsQuery.cs | 14 +++++++------- src/SparkPost/RequestMethods/Get.cs | 14 ++++++++++---- src/SparkPost/ValueMappers/DateTimeValueMapper.cs | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index 645af1c5..5a48c552 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -29,13 +29,13 @@ public MessageEventsQuery() /// events : List : Comma-delimited list of event types to search. Defaults to all event types. /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. /// - public string EventsJson - { - get - { - return string.Join(",", this.Events.Select(e => SnakeCase.Convert(e.ToString())).ToArray()); - } - } + //public string EventsJson + //{ + // get + // { + // return string.Join(",", this.Events.Select(e => SnakeCase.Convert(e.ToString())).ToArray()); + // } + //} /// /// events : List : Comma-delimited list of event types to search. Defaults to all event types. diff --git a/src/SparkPost/RequestMethods/Get.cs b/src/SparkPost/RequestMethods/Get.cs index f83bb19d..be145b58 100644 --- a/src/SparkPost/RequestMethods/Get.cs +++ b/src/SparkPost/RequestMethods/Get.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -26,12 +28,16 @@ public override Task Execute(Request request) private static string ConvertToQueryString(object data) { + var dataMapper = new DataMapper(); + if (data == null) return null; - var dictionary = - JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(data)); + var original = dataMapper.CatchAll(data); + + var dictionary = new Dictionary(); + foreach(var thing in original.Where(x=>string.IsNullOrEmpty(x.Value.ToString()) == false)) + dictionary[thing.Key] = thing.Value.ToString(); var values = dictionary - .Where(x => string.IsNullOrEmpty(x.Value) == false) .Select(x => HttpUtility.UrlEncode(SnakeCase.Convert(x.Key)) + "=" + HttpUtility.UrlEncode(x.Value)); return string.Join("&", values); diff --git a/src/SparkPost/ValueMappers/DateTimeValueMapper.cs b/src/SparkPost/ValueMappers/DateTimeValueMapper.cs index 4eb92402..8f6c4ba5 100644 --- a/src/SparkPost/ValueMappers/DateTimeValueMapper.cs +++ b/src/SparkPost/ValueMappers/DateTimeValueMapper.cs @@ -11,7 +11,7 @@ public bool CanMap(Type propertyType, object value) public object Map(Type propertyType, object value) { - return string.Format("{0:s}{0:zzz}", (DateTime) value); + return ((DateTime) value).ToString("yyyy-MM-ddTHH:mm"); } } } \ No newline at end of file From 05db17e7312c5f82826f8e8ca3c0e77d2b989591 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:12:17 -0500 Subject: [PATCH 005/223] Thread the data mapper dependency, and fix a date test. --- src/SparkPost.Tests/DataMapperTests.cs | 2 +- .../RequestSenders/AsyncRequestSenderTests.cs | 2 +- src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs | 2 +- src/SparkPost/Client.cs | 2 +- src/SparkPost/RequestMethodFinder.cs | 6 ++++-- src/SparkPost/RequestMethods/Get.cs | 8 ++++---- src/SparkPost/RequestSenders/AsyncRequestSender.cs | 6 ++++-- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/SparkPost.Tests/DataMapperTests.cs b/src/SparkPost.Tests/DataMapperTests.cs index 78559528..9a7a0f49 100644 --- a/src/SparkPost.Tests/DataMapperTests.cs +++ b/src/SparkPost.Tests/DataMapperTests.cs @@ -887,7 +887,7 @@ public void It_should_map_anything_using_our_conventions() result["first_name"].ShouldEqual("Test1"); result["last_name"].ShouldEqual("Test2"); - ((string)result["the_date"]).Substring(0, 19).ShouldEqual("2016-01-02T03:04:05"); + ((string)result["the_date"]).Substring(0, 16).ShouldEqual("2016-01-02T03:04"); } } } diff --git a/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs b/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs index a7f43522..ba50ece3 100644 --- a/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs +++ b/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs @@ -131,7 +131,7 @@ public class AsyncTesting : AsyncRequestSender { private Func responseBuilder; - public AsyncTesting(IClient client) : base(client) + public AsyncTesting(IClient client) : base(client, null) { } diff --git a/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs b/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs index ecdba772..95296398 100644 --- a/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs +++ b/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs @@ -22,7 +22,7 @@ public void Setup() request = new Request(); - async = new Mock(null); + async = new Mock(null, null); sync = new Mock(null); Mocker.SetInstance(client); diff --git a/src/SparkPost/Client.cs b/src/SparkPost/Client.cs index 67060789..cb687423 100644 --- a/src/SparkPost/Client.cs +++ b/src/SparkPost/Client.cs @@ -29,7 +29,7 @@ public Client(string apiKey, string apiHost, long subAccountId) ApiHost = apiHost; var dataMapper = new DataMapper(Version); - var asyncRequestSender = new AsyncRequestSender(this); + var asyncRequestSender = new AsyncRequestSender(this, dataMapper); var syncRequestSender = new SyncRequestSender(asyncRequestSender); var requestSender = new RequestSender(asyncRequestSender, syncRequestSender, this); diff --git a/src/SparkPost/RequestMethodFinder.cs b/src/SparkPost/RequestMethodFinder.cs index 4c36530b..64f98908 100644 --- a/src/SparkPost/RequestMethodFinder.cs +++ b/src/SparkPost/RequestMethodFinder.cs @@ -13,10 +13,12 @@ public interface IRequestMethodFinder public class RequestMethodFinder : IRequestMethodFinder { private readonly HttpClient client; + private readonly IDataMapper dataMapper; - public RequestMethodFinder(HttpClient client) + public RequestMethodFinder(HttpClient client, IDataMapper dataMapper) { this.client = client; + this.dataMapper = dataMapper; } public IRequestMethod FindFor(Request request) @@ -26,7 +28,7 @@ public IRequestMethod FindFor(Request request) new Delete(client), new Post(client), new Put(client), - new Get(client) + new Get(client, dataMapper) }.First(x => x.CanExecute(request)); } } diff --git a/src/SparkPost/RequestMethods/Get.cs b/src/SparkPost/RequestMethods/Get.cs index be145b58..fad8c843 100644 --- a/src/SparkPost/RequestMethods/Get.cs +++ b/src/SparkPost/RequestMethods/Get.cs @@ -13,10 +13,12 @@ namespace SparkPost.RequestMethods public class Get : RequestMethod { private readonly HttpClient client; + private readonly IDataMapper dataMapper; - public Get(HttpClient client) + public Get(HttpClient client, IDataMapper dataMapper) { this.client = client; + this.dataMapper = dataMapper; } public override Task Execute(Request request) @@ -26,10 +28,8 @@ public override Task Execute(Request request) .Where(x => string.IsNullOrEmpty(x) == false))); } - private static string ConvertToQueryString(object data) + private string ConvertToQueryString(object data) { - var dataMapper = new DataMapper(); - if (data == null) return null; var original = dataMapper.CatchAll(data); diff --git a/src/SparkPost/RequestSenders/AsyncRequestSender.cs b/src/SparkPost/RequestSenders/AsyncRequestSender.cs index 55c9f30b..2d68c692 100644 --- a/src/SparkPost/RequestSenders/AsyncRequestSender.cs +++ b/src/SparkPost/RequestSenders/AsyncRequestSender.cs @@ -8,10 +8,12 @@ namespace SparkPost.RequestSenders public class AsyncRequestSender : IRequestSender { private readonly IClient client; + private readonly IDataMapper dataMapper; - public AsyncRequestSender(IClient client) + public AsyncRequestSender(IClient client, IDataMapper dataMapper) { this.client = client; + this.dataMapper = dataMapper; } public virtual async Task Send(Request request) @@ -38,7 +40,7 @@ public virtual async Task Send(Request request) protected virtual async Task GetTheResponse(Request request, HttpClient httpClient) { - return await new RequestMethodFinder(httpClient) + return await new RequestMethodFinder(httpClient, dataMapper) .FindFor(request) .Execute(request); } From 2c5791dcfb5d674cc3fe7677ef0d20334871ad3b Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:18:09 -0500 Subject: [PATCH 006/223] These comma-delimited lists should be lists, not manually-built strings. --- src/SparkPost.Tests/SparkPost.Tests.csproj | 1 + src/SparkPost/MessageEventsQuery.cs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SparkPost.Tests/SparkPost.Tests.csproj b/src/SparkPost.Tests/SparkPost.Tests.csproj index 86fd49f1..d04e0582 100644 --- a/src/SparkPost.Tests/SparkPost.Tests.csproj +++ b/src/SparkPost.Tests/SparkPost.Tests.csproj @@ -88,6 +88,7 @@ + diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index 5a48c552..f562dc71 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -11,6 +11,9 @@ public class MessageEventsQuery public MessageEventsQuery() { this.Events = new List(); + this.BounceClasses = new List(); + this.CampaignIds = new List(); + this.FriendlyFroms = new List(); } /// @@ -18,12 +21,12 @@ public MessageEventsQuery() /// See Bounce Classification Codes at https://support.sparkpost.com/customer/portal/articles/1929896. /// Example: 1,10,20. /// - public string BounceClasses { get; set; } + public IList BounceClasses { get; set; } /// /// campaign_ids : ? : (optional, string, `Example Campaign Name`) ... Comma-delimited list of campaign ID's to search (i.e. campaign_id used during creation of a transmission). /// - public string CampaignIds { get; set; } + public IList CampaignIds { get; set; } /// /// events : List : Comma-delimited list of event types to search. Defaults to all event types. @@ -46,7 +49,7 @@ public MessageEventsQuery() /// /// friendly_froms : ? : (optional, list, `sender@mail.example.com`) ... Comma-delimited list of friendly_froms to search. /// - public string FriendlyFroms { get; set; } + public IList FriendlyFroms { get; set; } /// /// from : Datetime : Datetime in format of YYYY-MM-DDTHH:MM. From db6e3236028b27f5a33c7aafb0669595a0e48a6c Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:23:21 -0500 Subject: [PATCH 007/223] Get the rest of the string lists as string lists. --- .../MessageEventsQueryTests.cs | 61 +++++++++++++++++++ src/SparkPost/MessageEventsQuery.cs | 15 +++-- 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/SparkPost.Tests/MessageEventsQueryTests.cs diff --git a/src/SparkPost.Tests/MessageEventsQueryTests.cs b/src/SparkPost.Tests/MessageEventsQueryTests.cs new file mode 100644 index 00000000..9c3186ab --- /dev/null +++ b/src/SparkPost.Tests/MessageEventsQueryTests.cs @@ -0,0 +1,61 @@ +using NUnit.Framework; +using Should; + +namespace SparkPost.Tests +{ + public class MessageEventsQueryTests + { + [TestFixture] + public class Defaults + { + [Test] + public void It_should_have_a_default_build_list() + { + new MessageEventsQuery().BounceClasses.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_defualt_campaign_ids_list() + { + new MessageEventsQuery().CampaignIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_default_friendly_froms_list() + { + new MessageEventsQuery().FriendlyFroms.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_default_message_ids_list() + { + new MessageEventsQuery().MessageIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_recipients_list() + { + new MessageEventsQuery().Recipients.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_Subaccounts_list() + { + new MessageEventsQuery().Subaccounts.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_TemplateIds_list() + { + new MessageEventsQuery().TemplateIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_Transmissions_list() + { + new MessageEventsQuery().TransmissionIds.ShouldNotBeNull(); + } + + } + } +} \ No newline at end of file diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index f562dc71..366dc299 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -14,6 +14,11 @@ public MessageEventsQuery() this.BounceClasses = new List(); this.CampaignIds = new List(); this.FriendlyFroms = new List(); + this.MessageIds = new List(); + this.Recipients = new List(); + this.Subaccounts = new List(); + this.TemplateIds = new List(); + this.TransmissionIds = new List(); } /// @@ -62,7 +67,7 @@ public MessageEventsQuery() /// message_ids : List : Comma-delimited list of message ID's to search. /// Example: 0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e. /// - public string MessageIds { get; set; } + public IList MessageIds { get; set; } /// /// page : number : The results page number to return. Used with per_page for paging through results. @@ -88,19 +93,19 @@ public MessageEventsQuery() /// recipients : List : Comma-delimited list of recipients to search. /// Example: recipient @example.com. /// - public string Recipients { get; set; } + public IList Recipients { get; set; } /// /// subaccounts : List : Comma-delimited list of subaccount ID's to search. /// Example: 101. /// - public string Subaccounts { get; set; } + public IList Subaccounts { get; set; } /// /// template_ids : List : Comma-delimited list of template ID's to search. /// Example: templ-1234. /// - public string TemplateIds { get; set; } + public IList TemplateIds { get; set; } /// /// timezone : String : Standard timezone identification string. @@ -120,7 +125,7 @@ public MessageEventsQuery() /// transmission_ids : List : Comma-delimited list of transmission ID's to search (i.e. id generated during creation of a transmission). /// Example: 65832150921904138. /// - public string TransmissionIds { get; set; } + public IList TransmissionIds { get; set; } } } \ No newline at end of file From 0d0d03f4a673b15315daae3d93e3ae87982d8e92 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:44:03 -0500 Subject: [PATCH 008/223] If passed something we know how to parse, then use that. So we will have the same mapping for querystring as we do for others. --- src/SparkPost/DataMapper.cs | 23 +++++++++++++++++++ .../MapASingleItemUsingToDictionary.cs | 6 ++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/SparkPost/DataMapper.cs b/src/SparkPost/DataMapper.cs index 25fe836c..73683e41 100644 --- a/src/SparkPost/DataMapper.cs +++ b/src/SparkPost/DataMapper.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using SparkPost.Utilities; using SparkPost.ValueMappers; @@ -122,8 +124,29 @@ public IDictionary ToDictionary(Subaccount subaccount) return WithCommonConventions(subaccount); } + public IDictionary ToDictionary(MessageEventsQuery query) + { + return WithCommonConventions(query, new Dictionary() + { + ["events"] = string.Join(",", query.Events), + ["campaign_ids"] = string.Join(",", query.CampaignIds), + ["bounce_classes"] = string.Join(",", query.BounceClasses), + ["campaign_ids"] = string.Join(",", query.CampaignIds), + ["friendly_froms"] = string.Join(",", query.FriendlyFroms), + ["message_ids"] = string.Join(",", query.MessageIds), + ["recipients"] = string.Join(",", query.Recipients), + ["subaccounts"] = string.Join(",", query.Subaccounts), + ["template_ids"] = string.Join(",", query.TemplateIds), + ["transmission_ids"] = string.Join(",", query.TransmissionIds) + }); + } + public IDictionary CatchAll(object anything) { + var converters = MapASingleItemUsingToDictionary.GetTheConverters(this); + if (converters.ContainsKey(anything.GetType())) + return converters[anything.GetType()].Invoke(this, BindingFlags.Default, null, + new[] {anything}, CultureInfo.CurrentCulture) as IDictionary; return WithCommonConventions(anything); } diff --git a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs index eadd59ed..258c7fd4 100644 --- a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs @@ -14,7 +14,7 @@ public class MapASingleItemUsingToDictionary : IValueMapper public MapASingleItemUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = GetTheConverters(); + converters = GetTheConverters(dataMapper); } public bool CanMap(Type propertyType, object value) @@ -28,9 +28,9 @@ public object Map(Type propertyType, object value) new[] {value}, CultureInfo.CurrentCulture); } - private static Dictionary GetTheConverters() + public static Dictionary GetTheConverters(IDataMapper dataMapper) { - return typeof (DataMapper).GetMethods() + return dataMapper.GetType().GetMethods() .Where(x => x.Name == "ToDictionary") .Where(x => x.GetParameters().Length == 1) .Select(x => new From 94bc0afa350bfbee75614ab08a479e4349dbd90e Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:44:17 -0500 Subject: [PATCH 009/223] These should be string as well. --- src/SparkPost/MessageEventsQuery.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index 366dc299..b2de8939 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -10,7 +10,7 @@ public class MessageEventsQuery public MessageEventsQuery() { - this.Events = new List(); + this.Events = new List(); this.BounceClasses = new List(); this.CampaignIds = new List(); this.FriendlyFroms = new List(); @@ -49,7 +49,7 @@ public MessageEventsQuery() /// events : List : Comma-delimited list of event types to search. Defaults to all event types. /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. /// - public IList Events { get; set; } + public IList Events { get; set; } /// /// friendly_froms : ? : (optional, list, `sender@mail.example.com`) ... Comma-delimited list of friendly_froms to search. From c5b11b4429340be388e4f0016e50edb4962ce013 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:46:02 -0500 Subject: [PATCH 010/223] Dry up this portion of the code. --- .../MapASetOfItemsUsingToDictionary.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs index df8b1b37..efc946a8 100644 --- a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs @@ -14,7 +14,7 @@ public class MapASetOfItemsUsingToDictionary : IValueMapper public MapASetOfItemsUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = GetTheConverters(); + converters = MapASingleItemUsingToDictionary.GetTheConverters(dataMapper); } public bool CanMap(Type propertyType, object value) @@ -38,18 +38,5 @@ public object Map(Type propertyType, object value) return value; } - - private static Dictionary GetTheConverters() - { - return typeof (DataMapper).GetMethods() - .Where(x => x.Name == "ToDictionary") - .Where(x => x.GetParameters().Length == 1) - .Select(x => new - { - TheType = x.GetParameters().First().ParameterType, - TheMethod = x - }).ToList() - .ToDictionary(x => x.TheType, x => x.TheMethod); - } } } \ No newline at end of file From c1c9419348e5b53e13adc8855ab967635dc699d5 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:50:35 -0500 Subject: [PATCH 011/223] Move this method to its own class. --- src/SparkPost/DataMapper.cs | 2 +- src/SparkPost/SparkPost.csproj | 1 + .../Utilities/ToDictionaryMethodFinder.cs | 23 +++++++++++++++++++ .../MapASetOfItemsUsingToDictionary.cs | 3 ++- .../MapASingleItemUsingToDictionary.cs | 16 ++----------- 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/SparkPost/Utilities/ToDictionaryMethodFinder.cs diff --git a/src/SparkPost/DataMapper.cs b/src/SparkPost/DataMapper.cs index 73683e41..99d39945 100644 --- a/src/SparkPost/DataMapper.cs +++ b/src/SparkPost/DataMapper.cs @@ -143,7 +143,7 @@ public IDictionary ToDictionary(MessageEventsQuery query) public IDictionary CatchAll(object anything) { - var converters = MapASingleItemUsingToDictionary.GetTheConverters(this); + var converters = ToDictionaryMethodFinder.GetTheConverters(this); if (converters.ContainsKey(anything.GetType())) return converters[anything.GetType()].Invoke(this, BindingFlags.Default, null, new[] {anything}, CultureInfo.CurrentCulture) as IDictionary; diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index dedf57ea..4a6aa242 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -65,6 +65,7 @@ + diff --git a/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs b/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs new file mode 100644 index 00000000..e3bbad6e --- /dev/null +++ b/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace SparkPost.Utilities +{ + public static class ToDictionaryMethodFinder + { + public static Dictionary GetTheConverters(IDataMapper dataMapper) + { + return dataMapper.GetType().GetMethods() + .Where(x => x.Name == "ToDictionary") + .Where(x => x.GetParameters().Length == 1) + .Select(x => new + { + TheType = x.GetParameters().First().ParameterType, + TheMethod = x + }).ToList() + .ToDictionary(x => x.TheType, x => x.TheMethod); + } + } +} \ No newline at end of file diff --git a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs index efc946a8..ec7d4a48 100644 --- a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using System.Reflection; +using SparkPost.Utilities; namespace SparkPost.ValueMappers { @@ -14,7 +15,7 @@ public class MapASetOfItemsUsingToDictionary : IValueMapper public MapASetOfItemsUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = MapASingleItemUsingToDictionary.GetTheConverters(dataMapper); + converters = ToDictionaryMethodFinder.GetTheConverters(dataMapper); } public bool CanMap(Type propertyType, object value) diff --git a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs index 258c7fd4..a10711f9 100644 --- a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using System.Reflection; +using SparkPost.Utilities; namespace SparkPost.ValueMappers { @@ -14,7 +15,7 @@ public class MapASingleItemUsingToDictionary : IValueMapper public MapASingleItemUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = GetTheConverters(dataMapper); + converters = ToDictionaryMethodFinder.GetTheConverters(dataMapper); } public bool CanMap(Type propertyType, object value) @@ -27,18 +28,5 @@ public object Map(Type propertyType, object value) return converters[propertyType].Invoke(dataMapper, BindingFlags.Default, null, new[] {value}, CultureInfo.CurrentCulture); } - - public static Dictionary GetTheConverters(IDataMapper dataMapper) - { - return dataMapper.GetType().GetMethods() - .Where(x => x.Name == "ToDictionary") - .Where(x => x.GetParameters().Length == 1) - .Select(x => new - { - TheType = x.GetParameters().First().ParameterType, - TheMethod = x - }).ToList() - .ToDictionary(x => x.TheType, x => x.TheMethod); - } } } \ No newline at end of file From 4864d2b4abbe6b30c6be5445f82e200ca5662be1 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:53:48 -0500 Subject: [PATCH 012/223] Include this in the data mapper interface, since it is proving to be so useful. --- src/SparkPost/DataMapper.cs | 16 ++++++++++++- src/SparkPost/SparkPost.csproj | 1 - .../Utilities/ToDictionaryMethodFinder.cs | 23 ------------------- .../MapASetOfItemsUsingToDictionary.cs | 4 ++-- .../MapASingleItemUsingToDictionary.cs | 4 ++-- 5 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 src/SparkPost/Utilities/ToDictionaryMethodFinder.cs diff --git a/src/SparkPost/DataMapper.cs b/src/SparkPost/DataMapper.cs index 99d39945..669e63d8 100644 --- a/src/SparkPost/DataMapper.cs +++ b/src/SparkPost/DataMapper.cs @@ -24,6 +24,7 @@ public interface IDataMapper IDictionary ToDictionary(Subaccount subaccount); IDictionary CatchAll(object anything); object GetTheValue(Type propertyType, object value); + IDictionary ToDictionaryMethods(); } public class DataMapper : IDataMapper @@ -143,13 +144,26 @@ public IDictionary ToDictionary(MessageEventsQuery query) public IDictionary CatchAll(object anything) { - var converters = ToDictionaryMethodFinder.GetTheConverters(this); + var converters = ToDictionaryMethods(); if (converters.ContainsKey(anything.GetType())) return converters[anything.GetType()].Invoke(this, BindingFlags.Default, null, new[] {anything}, CultureInfo.CurrentCulture) as IDictionary; return WithCommonConventions(anything); } + public IDictionary ToDictionaryMethods() + { + return this.GetType().GetMethods() + .Where(x => x.Name == "ToDictionary") + .Where(x => x.GetParameters().Length == 1) + .Select(x => new + { + TheType = x.GetParameters().First().ParameterType, + TheMethod = x + }).ToList() + .ToDictionary(x => x.TheType, x => x.TheMethod); + } + private static bool AnyValuesWereSetOn(object target) { return target.GetType() diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index 4a6aa242..dedf57ea 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -65,7 +65,6 @@ - diff --git a/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs b/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs deleted file mode 100644 index e3bbad6e..00000000 --- a/src/SparkPost/Utilities/ToDictionaryMethodFinder.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SparkPost.Utilities -{ - public static class ToDictionaryMethodFinder - { - public static Dictionary GetTheConverters(IDataMapper dataMapper) - { - return dataMapper.GetType().GetMethods() - .Where(x => x.Name == "ToDictionary") - .Where(x => x.GetParameters().Length == 1) - .Select(x => new - { - TheType = x.GetParameters().First().ParameterType, - TheMethod = x - }).ToList() - .ToDictionary(x => x.TheType, x => x.TheMethod); - } - } -} \ No newline at end of file diff --git a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs index ec7d4a48..daab9d03 100644 --- a/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASetOfItemsUsingToDictionary.cs @@ -9,13 +9,13 @@ namespace SparkPost.ValueMappers { public class MapASetOfItemsUsingToDictionary : IValueMapper { - private readonly Dictionary converters; + private readonly IDictionary converters; private readonly IDataMapper dataMapper; public MapASetOfItemsUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = ToDictionaryMethodFinder.GetTheConverters(dataMapper); + converters = dataMapper.ToDictionaryMethods(); } public bool CanMap(Type propertyType, object value) diff --git a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs index a10711f9..d5f0a5c1 100644 --- a/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs +++ b/src/SparkPost/ValueMappers/MapASingleItemUsingToDictionary.cs @@ -9,13 +9,13 @@ namespace SparkPost.ValueMappers { public class MapASingleItemUsingToDictionary : IValueMapper { - private readonly Dictionary converters; + private readonly IDictionary converters; private readonly IDataMapper dataMapper; public MapASingleItemUsingToDictionary(IDataMapper dataMapper) { this.dataMapper = dataMapper; - converters = ToDictionaryMethodFinder.GetTheConverters(dataMapper); + converters = dataMapper.ToDictionaryMethods(); } public bool CanMap(Type propertyType, object value) From 7ad13fd5767d3bc20156c9cefbdc8bb8f66f4dd2 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Sun, 8 May 2016 23:55:18 -0500 Subject: [PATCH 013/223] Drop the commented code. --- src/SparkPost/MessageEventsQuery.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/SparkPost/MessageEventsQuery.cs b/src/SparkPost/MessageEventsQuery.cs index b2de8939..03912fc5 100644 --- a/src/SparkPost/MessageEventsQuery.cs +++ b/src/SparkPost/MessageEventsQuery.cs @@ -33,18 +33,6 @@ public MessageEventsQuery() /// public IList CampaignIds { get; set; } - /// - /// events : List : Comma-delimited list of event types to search. Defaults to all event types. - /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. - /// - //public string EventsJson - //{ - // get - // { - // return string.Join(",", this.Events.Select(e => SnakeCase.Convert(e.ToString())).ToArray()); - // } - //} - /// /// events : List : Comma-delimited list of event types to search. Defaults to all event types. /// Example: delivery, injection, bounce, delay, policy_rejection, out_of_band, open, click, generation_failure, generation_rejection, spam_complaint, list_unsubscribe, link_unsubscribe. From 55a18c6119264d43a6d48143b9b07610ba91e5d0 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Mon, 9 May 2016 20:20:14 -0500 Subject: [PATCH 014/223] Allow this query to be made with or without a query. --- src/SparkPost/IMessageEvents.cs | 4 ++-- src/SparkPost/MessageEvents.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SparkPost/IMessageEvents.cs b/src/SparkPost/IMessageEvents.cs index 25ea3b4b..e26bc988 100644 --- a/src/SparkPost/IMessageEvents.cs +++ b/src/SparkPost/IMessageEvents.cs @@ -4,7 +4,7 @@ namespace SparkPost { public interface IMessageEvents { - Task List(MessageEventsQuery messageEventsQuery); - Task List(object query = null); + Task List(); + Task List(object query); } } \ No newline at end of file diff --git a/src/SparkPost/MessageEvents.cs b/src/SparkPost/MessageEvents.cs index c191ca9e..4ee67f49 100644 --- a/src/SparkPost/MessageEvents.cs +++ b/src/SparkPost/MessageEvents.cs @@ -17,12 +17,12 @@ public MessageEvents(IClient client, IRequestSender requestSender) this.requestSender = requestSender; } - public async Task List(MessageEventsQuery messageEventsQuery) + public async Task List() { - return await List(messageEventsQuery as object); + return await List(null); } - public async Task List(object messageEventsQuery = null) + public async Task List(object messageEventsQuery) { if (messageEventsQuery == null) messageEventsQuery = new { }; From 62fd70ff5548365bd2558cfa18b919b9b58f8557 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Wed, 11 May 2016 07:03:59 -0500 Subject: [PATCH 015/223] Bumped the version. --- src/SparkPost/Properties/AssemblyInfo.cs | 4 ++-- src/SparkPost/SparkPost.nuspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SparkPost/Properties/AssemblyInfo.cs b/src/SparkPost/Properties/AssemblyInfo.cs index fb10660f..d8b54baf 100644 --- a/src/SparkPost/Properties/AssemblyInfo.cs +++ b/src/SparkPost/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.*")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.*")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/src/SparkPost/SparkPost.nuspec b/src/SparkPost/SparkPost.nuspec index 65df4416..196ed09e 100644 --- a/src/SparkPost/SparkPost.nuspec +++ b/src/SparkPost/SparkPost.nuspec @@ -2,7 +2,7 @@ $id$ - 1.4.0 + 1.5.0 $title$ $author$ $author$ From d6ce88f5753bb647e8b6cadd00a3a4b7d47d7b10 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Wed, 11 May 2016 07:19:14 -0500 Subject: [PATCH 016/223] Start to filter the json work through an internal class. --- src/SparkPost/JsonStuff.cs | 17 +++++++++++++++++ src/SparkPost/MessageEvents.cs | 11 +++++------ src/SparkPost/SparkPost.csproj | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/SparkPost/JsonStuff.cs diff --git a/src/SparkPost/JsonStuff.cs b/src/SparkPost/JsonStuff.cs new file mode 100644 index 00000000..d882dc09 --- /dev/null +++ b/src/SparkPost/JsonStuff.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace SparkPost +{ + internal static class JsonStuff + { + internal static T DeserializeObject(string json) + { + return JsonConvert.DeserializeObject(json); + } + + internal static string SerializeObject(object @object) + { + return JsonConvert.SerializeObject(@object); + } + } +} \ No newline at end of file diff --git a/src/SparkPost/MessageEvents.cs b/src/SparkPost/MessageEvents.cs index 4ee67f49..b75b69d0 100644 --- a/src/SparkPost/MessageEvents.cs +++ b/src/SparkPost/MessageEvents.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; using SparkPost.RequestSenders; using System.Net; using System.Threading.Tasks; @@ -36,7 +35,7 @@ public async Task List(object messageEventsQuery) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - dynamic content = JsonConvert.DeserializeObject(response.Content); + dynamic content = JsonStuff.DeserializeObject(response.Content); var listMessageEventsResponse = new ListMessageEventsResponse { @@ -77,11 +76,11 @@ private static IEnumerable ConvertResultsToAListOfMessageEvents(dy foreach (var result in results) { var metadata = - JsonConvert.DeserializeObject>( - JsonConvert.SerializeObject(result.rcpt_meta)); + JsonStuff.DeserializeObject>( + JsonStuff.SerializeObject(result.rcpt_meta)); var tags = - JsonConvert.DeserializeObject>( - JsonConvert.SerializeObject(result.rcpt_tags)); + JsonStuff.DeserializeObject>( + JsonStuff.SerializeObject(result.rcpt_tags)); messageEvents.Add(new MessageEvent { Type = result.type, diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index dedf57ea..7413ad8d 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -58,6 +58,7 @@ + From fd49c10aa0ba5069045b01b83ba8029f55052ad2 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Wed, 11 May 2016 07:23:58 -0500 Subject: [PATCH 017/223] Consolidate the json serializing and deserializing. --- src/SparkPost/ListSubaccountResponse.cs | 3 +-- src/SparkPost/ListWebhookResponse.cs | 3 +-- src/SparkPost/MessageEvent.cs | 3 +-- src/SparkPost/Request.cs | 6 ++---- src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs | 3 +-- src/SparkPost/RetrieveWebhookResponse.cs | 3 +-- src/SparkPost/Subaccounts.cs | 7 +++---- src/SparkPost/Suppressions.cs | 5 ++--- src/SparkPost/Transmissions.cs | 5 ++--- 9 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/SparkPost/ListSubaccountResponse.cs b/src/SparkPost/ListSubaccountResponse.cs index 62c2c57d..9e93848d 100644 --- a/src/SparkPost/ListSubaccountResponse.cs +++ b/src/SparkPost/ListSubaccountResponse.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -13,7 +12,7 @@ public static ListSubaccountResponse CreateFromResponse(Response response) var result = new ListSubaccountResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; var subaccounts = new List(); foreach (var r in results) subaccounts.Add(ConvertToSubaccount(r)); diff --git a/src/SparkPost/ListWebhookResponse.cs b/src/SparkPost/ListWebhookResponse.cs index e1648c76..cf7ed2f6 100644 --- a/src/SparkPost/ListWebhookResponse.cs +++ b/src/SparkPost/ListWebhookResponse.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace SparkPost { @@ -12,7 +11,7 @@ public static ListWebhookResponse CreateFromResponse(Response response) var result = new ListWebhookResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonConvert.DeserializeObject(result.Content).results; + var results = JsonStuff.DeserializeObject(result.Content).results; var webhooks = new List(); foreach(var r in results) webhooks.Add(ConvertToAWebhook(r)); diff --git a/src/SparkPost/MessageEvent.cs b/src/SparkPost/MessageEvent.cs index 51c7da3d..8332bb64 100644 --- a/src/SparkPost/MessageEvent.cs +++ b/src/SparkPost/MessageEvent.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using SparkPost.Utilities; +using SparkPost.Utilities; using System; using System.Collections.Generic; diff --git a/src/SparkPost/Request.cs b/src/SparkPost/Request.cs index 16328ea5..9630fdc5 100644 --- a/src/SparkPost/Request.cs +++ b/src/SparkPost/Request.cs @@ -1,6 +1,4 @@ -using Newtonsoft.Json; - -namespace SparkPost +namespace SparkPost { public class Request { @@ -10,7 +8,7 @@ public class Request public string ToJson() { - return JsonConvert.SerializeObject(this); + return JsonStuff.SerializeObject(this); } } } \ No newline at end of file diff --git a/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs b/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs index 529b5deb..3745addb 100644 --- a/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs +++ b/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs @@ -1,7 +1,6 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json; namespace SparkPost.RequestMethods { @@ -28,7 +27,7 @@ private static StringContent ContentFrom(Request request) private static string SerializeObject(object data) { - return JsonConvert.SerializeObject(data, + return JsonStuff.SerializeObject(data, new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.None}); } } diff --git a/src/SparkPost/RetrieveWebhookResponse.cs b/src/SparkPost/RetrieveWebhookResponse.cs index 02df5f49..cc3b4135 100644 --- a/src/SparkPost/RetrieveWebhookResponse.cs +++ b/src/SparkPost/RetrieveWebhookResponse.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; namespace SparkPost { @@ -11,7 +10,7 @@ public static RetrieveWebhookResponse CreateFromResponse(Response response) var result = new RetrieveWebhookResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; result.Webhook = ListWebhookResponse.ConvertToAWebhook(results); diff --git a/src/SparkPost/Subaccounts.cs b/src/SparkPost/Subaccounts.cs index c198293d..45a8b907 100644 --- a/src/SparkPost/Subaccounts.cs +++ b/src/SparkPost/Subaccounts.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using System.Net; +using System.Net; using System.Threading.Tasks; using SparkPost.RequestSenders; @@ -49,7 +48,7 @@ public async Task Create(SubaccountCreate subaccount) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; return new CreateSubaccountResponse { @@ -79,7 +78,7 @@ public async Task Update(SubaccountUpdate subaccount) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; return new UpdateSubaccountResponse { diff --git a/src/SparkPost/Suppressions.cs b/src/SparkPost/Suppressions.cs index 0eaef83e..2af23ce4 100644 --- a/src/SparkPost/Suppressions.cs +++ b/src/SparkPost/Suppressions.cs @@ -3,7 +3,6 @@ using System.Net; using System.Threading.Tasks; using System.Web; -using Newtonsoft.Json; using SparkPost.RequestSenders; namespace SparkPost @@ -39,7 +38,7 @@ public async Task List(object query = null) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; return new ListSuppressionResponse { @@ -64,7 +63,7 @@ public async Task Retrieve(string email) throw new ResponseException(response); dynamic results = response.StatusCode == HttpStatusCode.OK - ? JsonConvert.DeserializeObject(response.Content).results + ? JsonStuff.DeserializeObject(response.Content).results : null; return new ListSuppressionResponse diff --git a/src/SparkPost/Transmissions.cs b/src/SparkPost/Transmissions.cs index e7b8dad0..408bff63 100644 --- a/src/SparkPost/Transmissions.cs +++ b/src/SparkPost/Transmissions.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Net; using System.Threading.Tasks; -using Newtonsoft.Json; using SparkPost.RequestSenders; namespace SparkPost @@ -32,7 +31,7 @@ public async Task Send(Transmission transmission) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; return new SendTransmissionResponse() { Id = results.id, @@ -66,7 +65,7 @@ public async Task Retrieve(string transmissionId) try { - var results = JsonConvert.DeserializeObject(response.Content).results; + var results = JsonStuff.DeserializeObject(response.Content).results; if (results.transmission == null) return transmissionResponse; transmissionResponse.Id = results.transmission.id; From 18e0c9212fbd64e305fd0d49397430f90e784ea5 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Wed, 11 May 2016 09:04:30 -0500 Subject: [PATCH 018/223] Move this to utilities. --- src/SparkPost/ListSubaccountResponse.cs | 3 ++- src/SparkPost/ListWebhookResponse.cs | 3 ++- src/SparkPost/MessageEvents.cs | 11 ++++++----- src/SparkPost/Request.cs | 6 ++++-- src/SparkPost/RequestMethods/Get.cs | 1 - src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs | 5 +++-- src/SparkPost/RetrieveWebhookResponse.cs | 4 +++- src/SparkPost/SparkPost.csproj | 2 +- src/SparkPost/Subaccounts.cs | 5 +++-- src/SparkPost/Suppressions.cs | 5 +++-- src/SparkPost/Transmissions.cs | 5 +++-- .../{JsonStuff.cs => Utilities/Jsonification.cs} | 7 ++++--- 12 files changed, 34 insertions(+), 23 deletions(-) rename src/SparkPost/{JsonStuff.cs => Utilities/Jsonification.cs} (55%) diff --git a/src/SparkPost/ListSubaccountResponse.cs b/src/SparkPost/ListSubaccountResponse.cs index 9e93848d..7669f769 100644 --- a/src/SparkPost/ListSubaccountResponse.cs +++ b/src/SparkPost/ListSubaccountResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using SparkPost.Utilities; namespace SparkPost { @@ -12,7 +13,7 @@ public static ListSubaccountResponse CreateFromResponse(Response response) var result = new ListSubaccountResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; var subaccounts = new List(); foreach (var r in results) subaccounts.Add(ConvertToSubaccount(r)); diff --git a/src/SparkPost/ListWebhookResponse.cs b/src/SparkPost/ListWebhookResponse.cs index cf7ed2f6..4a3a1e89 100644 --- a/src/SparkPost/ListWebhookResponse.cs +++ b/src/SparkPost/ListWebhookResponse.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using SparkPost.Utilities; namespace SparkPost { @@ -11,7 +12,7 @@ public static ListWebhookResponse CreateFromResponse(Response response) var result = new ListWebhookResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonStuff.DeserializeObject(result.Content).results; + var results = Jsonification.DeserializeObject(result.Content).results; var webhooks = new List(); foreach(var r in results) webhooks.Add(ConvertToAWebhook(r)); diff --git a/src/SparkPost/MessageEvents.cs b/src/SparkPost/MessageEvents.cs index b75b69d0..2dffb1bc 100644 --- a/src/SparkPost/MessageEvents.cs +++ b/src/SparkPost/MessageEvents.cs @@ -2,6 +2,7 @@ using SparkPost.RequestSenders; using System.Net; using System.Threading.Tasks; +using SparkPost.Utilities; namespace SparkPost { @@ -35,7 +36,7 @@ public async Task List(object messageEventsQuery) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - dynamic content = JsonStuff.DeserializeObject(response.Content); + dynamic content = Jsonification.DeserializeObject(response.Content); var listMessageEventsResponse = new ListMessageEventsResponse { @@ -76,11 +77,11 @@ private static IEnumerable ConvertResultsToAListOfMessageEvents(dy foreach (var result in results) { var metadata = - JsonStuff.DeserializeObject>( - JsonStuff.SerializeObject(result.rcpt_meta)); + Jsonification.DeserializeObject>( + Jsonification.SerializeObject(result.rcpt_meta)); var tags = - JsonStuff.DeserializeObject>( - JsonStuff.SerializeObject(result.rcpt_tags)); + Jsonification.DeserializeObject>( + Jsonification.SerializeObject(result.rcpt_tags)); messageEvents.Add(new MessageEvent { Type = result.type, diff --git a/src/SparkPost/Request.cs b/src/SparkPost/Request.cs index 9630fdc5..2f202cbc 100644 --- a/src/SparkPost/Request.cs +++ b/src/SparkPost/Request.cs @@ -1,4 +1,6 @@ -namespace SparkPost +using SparkPost.Utilities; + +namespace SparkPost { public class Request { @@ -8,7 +10,7 @@ public class Request public string ToJson() { - return JsonStuff.SerializeObject(this); + return Jsonification.SerializeObject(this); } } } \ No newline at end of file diff --git a/src/SparkPost/RequestMethods/Get.cs b/src/SparkPost/RequestMethods/Get.cs index fad8c843..b49220fc 100644 --- a/src/SparkPost/RequestMethods/Get.cs +++ b/src/SparkPost/RequestMethods/Get.cs @@ -5,7 +5,6 @@ using System.Net.Http; using System.Threading.Tasks; using System.Web; -using Newtonsoft.Json; using SparkPost.Utilities; namespace SparkPost.RequestMethods diff --git a/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs b/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs index 3745addb..ff937a6d 100644 --- a/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs +++ b/src/SparkPost/RequestMethods/PutAndPostAreTheSame.cs @@ -1,6 +1,8 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; +using SparkPost.Utilities; namespace SparkPost.RequestMethods { @@ -27,8 +29,7 @@ private static StringContent ContentFrom(Request request) private static string SerializeObject(object data) { - return JsonStuff.SerializeObject(data, - new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.None}); + return Jsonification.SerializeObject(data); } } } \ No newline at end of file diff --git a/src/SparkPost/RetrieveWebhookResponse.cs b/src/SparkPost/RetrieveWebhookResponse.cs index cc3b4135..99b42638 100644 --- a/src/SparkPost/RetrieveWebhookResponse.cs +++ b/src/SparkPost/RetrieveWebhookResponse.cs @@ -1,4 +1,6 @@ +using SparkPost.Utilities; + namespace SparkPost { public class RetrieveWebhookResponse : Response @@ -10,7 +12,7 @@ public static RetrieveWebhookResponse CreateFromResponse(Response response) var result = new RetrieveWebhookResponse(); LeftRight.SetValuesToMatch(result, response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; result.Webhook = ListWebhookResponse.ConvertToAWebhook(results); diff --git a/src/SparkPost/SparkPost.csproj b/src/SparkPost/SparkPost.csproj index 7413ad8d..971b9d41 100644 --- a/src/SparkPost/SparkPost.csproj +++ b/src/SparkPost/SparkPost.csproj @@ -58,7 +58,7 @@ - + diff --git a/src/SparkPost/Subaccounts.cs b/src/SparkPost/Subaccounts.cs index 45a8b907..5cb917a7 100644 --- a/src/SparkPost/Subaccounts.cs +++ b/src/SparkPost/Subaccounts.cs @@ -1,6 +1,7 @@ using System.Net; using System.Threading.Tasks; using SparkPost.RequestSenders; +using SparkPost.Utilities; namespace SparkPost { @@ -48,7 +49,7 @@ public async Task Create(SubaccountCreate subaccount) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; return new CreateSubaccountResponse { @@ -78,7 +79,7 @@ public async Task Update(SubaccountUpdate subaccount) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; return new UpdateSubaccountResponse { diff --git a/src/SparkPost/Suppressions.cs b/src/SparkPost/Suppressions.cs index 2af23ce4..599ecb6d 100644 --- a/src/SparkPost/Suppressions.cs +++ b/src/SparkPost/Suppressions.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using System.Web; using SparkPost.RequestSenders; +using SparkPost.Utilities; namespace SparkPost { @@ -38,7 +39,7 @@ public async Task List(object query = null) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; return new ListSuppressionResponse { @@ -63,7 +64,7 @@ public async Task Retrieve(string email) throw new ResponseException(response); dynamic results = response.StatusCode == HttpStatusCode.OK - ? JsonStuff.DeserializeObject(response.Content).results + ? Jsonification.DeserializeObject(response.Content).results : null; return new ListSuppressionResponse diff --git a/src/SparkPost/Transmissions.cs b/src/SparkPost/Transmissions.cs index 408bff63..42c09478 100644 --- a/src/SparkPost/Transmissions.cs +++ b/src/SparkPost/Transmissions.cs @@ -3,6 +3,7 @@ using System.Net; using System.Threading.Tasks; using SparkPost.RequestSenders; +using SparkPost.Utilities; namespace SparkPost { @@ -31,7 +32,7 @@ public async Task Send(Transmission transmission) var response = await requestSender.Send(request); if (response.StatusCode != HttpStatusCode.OK) throw new ResponseException(response); - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; return new SendTransmissionResponse() { Id = results.id, @@ -65,7 +66,7 @@ public async Task Retrieve(string transmissionId) try { - var results = JsonStuff.DeserializeObject(response.Content).results; + var results = Jsonification.DeserializeObject(response.Content).results; if (results.transmission == null) return transmissionResponse; transmissionResponse.Id = results.transmission.id; diff --git a/src/SparkPost/JsonStuff.cs b/src/SparkPost/Utilities/Jsonification.cs similarity index 55% rename from src/SparkPost/JsonStuff.cs rename to src/SparkPost/Utilities/Jsonification.cs index d882dc09..7ec2e964 100644 --- a/src/SparkPost/JsonStuff.cs +++ b/src/SparkPost/Utilities/Jsonification.cs @@ -1,8 +1,8 @@ using Newtonsoft.Json; -namespace SparkPost +namespace SparkPost.Utilities { - internal static class JsonStuff + internal static class Jsonification { internal static T DeserializeObject(string json) { @@ -11,7 +11,8 @@ internal static T DeserializeObject(string json) internal static string SerializeObject(object @object) { - return JsonConvert.SerializeObject(@object); + return JsonConvert.SerializeObject(@object, + new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.None}); } } } \ No newline at end of file From e765d079a0a50e6a816790f2388bf230bf68219f Mon Sep 17 00:00:00 2001 From: Richard Leland Date: Thu, 12 May 2016 15:51:43 -0400 Subject: [PATCH 019/223] Update Travis badge to point to csharp-sparkpost --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dd4f8ff..d1d11c7a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # SparkPost C# Library -[![Travis CI](https://travis-ci.org/SparkPost/ruby-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/csharp-sparkpost) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com) +[![Travis CI](https://travis-ci.org/SparkPost/csharp-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/csharp-sparkpost) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com) The official C# package for the [SparkPost API](https://www.sparkpost.com/api). Xamarin.iOS and Xamarin.Android support provided in the Portable Package (PCL Profile7). From 12ec8bca6a9982668c5b00ffd1ce623dd04f69d2 Mon Sep 17 00:00:00 2001 From: ZA1 Date: Sat, 14 May 2016 17:24:46 +0200 Subject: [PATCH 020/223] Added support for inbound domains --- src/SparkPost.Tests/InboundDomainTests.cs | 10 +++ src/SparkPost.Tests/SparkPost.Tests.csproj | 5 +- src/SparkPost/Client.cs | 2 + src/SparkPost/DataMapper.cs | 6 ++ src/SparkPost/IClient.cs | 5 ++ src/SparkPost/InboundDomain.cs | 14 ++++ src/SparkPost/InboundDomainResponse.cs | 21 ++++++ src/SparkPost/InboundDomains.cs | 87 ++++++++++++++++++++++ src/SparkPost/ListInboundDomainResponse.cs | 33 ++++++++ src/SparkPost/SparkPost.csproj | 4 + 10 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/SparkPost.Tests/InboundDomainTests.cs create mode 100644 src/SparkPost/InboundDomain.cs create mode 100644 src/SparkPost/InboundDomainResponse.cs create mode 100644 src/SparkPost/InboundDomains.cs create mode 100644 src/SparkPost/ListInboundDomainResponse.cs diff --git a/src/SparkPost.Tests/InboundDomainTests.cs b/src/SparkPost.Tests/InboundDomainTests.cs new file mode 100644 index 00000000..1d3f7a6c --- /dev/null +++ b/src/SparkPost.Tests/InboundDomainTests.cs @@ -0,0 +1,10 @@ +using NUnit.Framework; +using Should; + +namespace SparkPost.Tests +{ + public class InboundDomainTests + { + + } +} \ No newline at end of file diff --git a/src/SparkPost.Tests/SparkPost.Tests.csproj b/src/SparkPost.Tests/SparkPost.Tests.csproj index d04e0582..58ac8f76 100644 --- a/src/SparkPost.Tests/SparkPost.Tests.csproj +++ b/src/SparkPost.Tests/SparkPost.Tests.csproj @@ -102,6 +102,7 @@ + @@ -117,7 +118,9 @@ - + + + + \ No newline at end of file diff --git a/src/SparkPost.sln b/src/SparkPost.sln index 8cdddad9..6f49a75f 100644 --- a/src/SparkPost.sln +++ b/src/SparkPost.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SparkPost", "SparkPost\SparkPost.csproj", "{A5DDA3E3-7B3D-46C3-B4BB-C627FBA37812}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SparkPost.Tests", "SparkPost.Tests\SparkPost.Tests.csproj", "{52F2F4F4-3DE2-49C6-87D8-BD6F825B9372}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SparkPost.Specs", "SparkPost.Specs\SparkPost.Specs.csproj", "{E78B12E0-B84E-4B68-9B44-30F4A22792AF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {52F2F4F4-3DE2-49C6-87D8-BD6F825B9372}.Debug|Any CPU.Build.0 = Debug|Any CPU {52F2F4F4-3DE2-49C6-87D8-BD6F825B9372}.Release|Any CPU.ActiveCfg = Release|Any CPU {52F2F4F4-3DE2-49C6-87D8-BD6F825B9372}.Release|Any CPU.Build.0 = Release|Any CPU + {E78B12E0-B84E-4B68-9B44-30F4A22792AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E78B12E0-B84E-4B68-9B44-30F4A22792AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E78B12E0-B84E-4B68-9B44-30F4A22792AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E78B12E0-B84E-4B68-9B44-30F4A22792AF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 7ad059466177afd5715414db999a0ffe48c12c31 Mon Sep 17 00:00:00 2001 From: Darren Cauthon Date: Mon, 3 Oct 2016 16:55:00 -0500 Subject: [PATCH 114/223] Produce the first failing acceptance test. --- src/SparkPost.Acceptance/App.config | 9 ++ .../Properties/AssemblyInfo.cs | 6 +- .../RecipientLists.feature | 6 ++ .../RecipientLists.feature.cs | 85 +++++++++++++++++++ .../SparkPost.Acceptance.csproj} | 32 ++++++- src/SparkPost.Acceptance/Steps.cs | 40 +++++++++ src/SparkPost.Acceptance/packages.config | 6 ++ src/SparkPost.sln | 10 +-- 8 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 src/SparkPost.Acceptance/App.config rename src/{SparkPost.Specs => SparkPost.Acceptance}/Properties/AssemblyInfo.cs (88%) create mode 100644 src/SparkPost.Acceptance/RecipientLists.feature create mode 100644 src/SparkPost.Acceptance/RecipientLists.feature.cs rename src/{SparkPost.Specs/SparkPost.Specs.csproj => SparkPost.Acceptance/SparkPost.Acceptance.csproj} (62%) create mode 100644 src/SparkPost.Acceptance/Steps.cs create mode 100644 src/SparkPost.Acceptance/packages.config diff --git a/src/SparkPost.Acceptance/App.config b/src/SparkPost.Acceptance/App.config new file mode 100644 index 00000000..8f6a4f76 --- /dev/null +++ b/src/SparkPost.Acceptance/App.config @@ -0,0 +1,9 @@ + + + +
+ + + + + \ No newline at end of file diff --git a/src/SparkPost.Specs/Properties/AssemblyInfo.cs b/src/SparkPost.Acceptance/Properties/AssemblyInfo.cs similarity index 88% rename from src/SparkPost.Specs/Properties/AssemblyInfo.cs rename to src/SparkPost.Acceptance/Properties/AssemblyInfo.cs index e79cdc39..10a3c4eb 100644 --- a/src/SparkPost.Specs/Properties/AssemblyInfo.cs +++ b/src/SparkPost.Acceptance/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("SparkPost.Specs")] +[assembly: AssemblyTitle("SparkPost.Acceptance")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SparkPost.Specs")] +[assembly: AssemblyProduct("SparkPost.Acceptance")] [assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e78b12e0-b84e-4b68-9b44-30f4a22792af")] +[assembly: Guid("8f62193b-1c44-4e92-96c7-8ebd610f7669")] // Version information for an assembly consists of the following four values: // diff --git a/src/SparkPost.Acceptance/RecipientLists.feature b/src/SparkPost.Acceptance/RecipientLists.feature new file mode 100644 index 00000000..27ddf98c --- /dev/null +++ b/src/SparkPost.Acceptance/RecipientLists.feature @@ -0,0 +1,6 @@ +Feature: Recipient Lists + +Scenario: Retrieving things + Given my api key is '1234' + When I retrieve the "my-list" recipient list + Then it should return a 200 \ No newline at end of file diff --git a/src/SparkPost.Acceptance/RecipientLists.feature.cs b/src/SparkPost.Acceptance/RecipientLists.feature.cs new file mode 100644 index 00000000..05341602 --- /dev/null +++ b/src/SparkPost.Acceptance/RecipientLists.feature.cs @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:2.1.0.0 +// SpecFlow Generator Version:2.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Recipient Lists")] + public partial class RecipientListsFeature + { + + private TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "RecipientLists.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Recipient Lists", null, ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Retrieving things")] + public virtual void RetrievingThings() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Retrieving things", ((string[])(null))); +#line 3 +this.ScenarioSetup(scenarioInfo); +#line 4 + testRunner.Given("my api key is \'1234\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 5 + testRunner.When("I retrieve the \"my-list\" recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 6 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Specs/SparkPost.Specs.csproj b/src/SparkPost.Acceptance/SparkPost.Acceptance.csproj similarity index 62% rename from src/SparkPost.Specs/SparkPost.Specs.csproj rename to src/SparkPost.Acceptance/SparkPost.Acceptance.csproj index 58ec045d..f2de8d5f 100644 --- a/src/SparkPost.Specs/SparkPost.Specs.csproj +++ b/src/SparkPost.Acceptance/SparkPost.Acceptance.csproj @@ -4,11 +4,11 @@ Debug AnyCPU - {E78B12E0-B84E-4B68-9B44-30F4A22792AF} + {8F62193B-1C44-4E92-96C7-8EBD610F7669} Library Properties - SparkPost.Specs - SparkPost.Specs + SparkPost.Acceptance + SparkPost.Acceptance v4.5.2 512 @@ -30,6 +30,14 @@ 4 + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + ..\packages\Should.1.1.20\lib\Should.dll + True + @@ -38,9 +46,19 @@ + + ..\packages\SpecFlow.2.1.0\lib\net45\TechTalk.SpecFlow.dll + True + + + True + True + RecipientLists.feature + + @@ -48,6 +66,14 @@ SparkPost + + + + + SpecFlowSingleFileGenerator + RecipientLists.feature.cs + +