Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified SendWithUs.Client.Tests/Component/BufferedJsonStringWriter.cs
100644 → 100755
Empty file.
118 changes: 117 additions & 1 deletion SendWithUs.Client.Tests/Component/ComponentTestsBase.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace SendWithUs.Client.Tests.Component
using System.Collections.Generic;
using RenderNames = SendWithUs.Client.RenderRequestConverter.PropertyNames;
using SendNames = SendWithUs.Client.SendRequestConverter.PropertyNames;

using CustomerUpdateNames = SendWithUs.Client.CustomerUpdateRequestConverter.PropertyNames;
using CustomerDeleteNames = SendWithUs.Client.CustomerDeleteRequestConverter.PropertyNames;
using System.Linq;
public abstract class ComponentTestsBase
{
protected void ValidateSendRequest(SendRequest request, JObject jsonObject)
Expand Down Expand Up @@ -117,6 +119,48 @@ protected void ValidateRenderRequest(JObject jsonObject, string expectedTemplate
Assert.IsTrue(templateIdFound);
}

protected void ValidateCustomerUpdateRequest(CustomerUpdateRequest request, JObject jsonObject)
{
var emailFound = false;

foreach(var pair in jsonObject)
{
switch (pair.Key)
{
case CustomerUpdateNames.Email:
Assert.AreEqual(request.Email, pair.Value.Value<string>());
emailFound = true;
break;
case CustomerUpdateNames.Locale:
Assert.AreEqual(request.Locale, pair.Value.Value<string>());
break;
case CustomerUpdateNames.Groups:
Assert.IsTrue(Enumerable.SequenceEqual(request.Groups, pair.Value.Values<string>()));
break;
}
}

Assert.IsTrue(emailFound);
}

protected void ValidateCustomerDeleteRequest(CustomerDeleteRequest request, JObject jsonObject)
{
var emailFound = false;

foreach (var pair in jsonObject)
{
switch (pair.Key)
{
case CustomerDeleteNames.Email:
Assert.AreEqual(request.Email, pair.Value.Value<string>());
emailFound = true;
break;
}
}

Assert.IsTrue(emailFound);
}

protected void ValidateRequestData(JObject actualData, IDictionary<string, string> expectedData)
{
Assert.AreEqual(expectedData.Count, actualData.Count);
Expand All @@ -127,5 +171,77 @@ protected void ValidateRequestData(JObject actualData, IDictionary<string, strin
Assert.AreEqual(expectedData[pair.Key], pair.Value.Value<string>());
}
}

protected void ValidateDripCampaignActivateRequest(JObject jsonObject, string expectedRecipientAddress, bool allowOtherProperties)
{
var recipientAddressFound = false;

foreach (var pair in jsonObject)
{
switch (pair.Key)
{
case "recipient":
Assert.AreEqual(expectedRecipientAddress, pair.Value["address"].Value<string>());
recipientAddressFound = true;
break;
default:
if (!allowOtherProperties)
{
Assert.Fail("Unexpected object property '{0}'", pair.Key);
}
break;
}
}

Assert.IsTrue(recipientAddressFound);
}

protected void ValidateDripCampaignDeactivateRequest(JObject jsonObject, string expectedRecipientAddress, bool allowOtherProperties)
{
var recipientAddressFound = false;

foreach (var pair in jsonObject)
{
switch (pair.Key)
{
case "recipient_address":
Assert.AreEqual(expectedRecipientAddress, pair.Value);
recipientAddressFound = true;
break;
default:
if (!allowOtherProperties)
{
Assert.Fail("Unexpected object property '{0}'", pair.Key);
}
break;
}
}

Assert.IsTrue(recipientAddressFound);
}

protected void ValidateDripCampaignDeactivateAllRequest(JObject jsonObject, string expectedRecipientAddress, bool allowOtherProperties)
{
var recipientAddressFound = false;

foreach (var pair in jsonObject)
{
switch (pair.Key)
{
case "recipient_address":
Assert.AreEqual(expectedRecipientAddress, pair.Value);
recipientAddressFound = true;
break;
default:
if (!allowOtherProperties)
{
Assert.Fail("Unexpected object property '{0}'", pair.Key);
}
break;
}
}

Assert.IsTrue(recipientAddressFound);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2015 Mimeo, Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

namespace SendWithUs.Client.Tests.Component
{
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SendWithUs.Client;

[TestClass]
public class CustomerDeleteRequestConverterTests : ComponentTestsBase
{
[TestMethod]
public void WriteJson_MinimalCustomerDeleteRequest_Succeeds()
{
var email = TestHelper.GetUniqueId();
var request = new CustomerDeleteRequest(email);
var writer = BufferedJsonStringWriter.Create();
var serializer = JsonSerializer.Create();
var converter = new CustomerDeleteRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateCustomerDeleteRequest(request, jsonObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright © 2015 Mimeo, Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

namespace SendWithUs.Client.Tests.Component
{
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SendWithUs.Client;

[TestClass]
public class CustomerUpdateRequestConverterTests : ComponentTestsBase
{
[TestMethod]
public void WriteJson_MinimalCustomerUpdateRequest_Succeeds()
{
var email = TestHelper.GetUniqueId();
var request = new CustomerUpdateRequest(email);
var writer = BufferedJsonStringWriter.Create();
var serializer = JsonSerializer.Create();
var converter = new CustomerUpdateRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateCustomerUpdateRequest(request, jsonObject);
}

[TestMethod]
public void WriteJson_WithData_IncludesAllData()
{
var email = TestHelper.GetUniqueId();
var data = TestHelper.GetRandomDictionary();
var dataAsKeyPair = data.Select(d => new KeyValuePair<string, object>(d.Key, d.Value));
var request = new CustomerUpdateRequest(email, dataAsKeyPair);
request.Locale = "US";
request.Groups = new List<string>
{
"Hello",
"World"
};

var writer = BufferedJsonStringWriter.Create();
var serializer = JsonSerializer.Create();
var converter = new CustomerUpdateRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateCustomerUpdateRequest(request, jsonObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

namespace SendWithUs.Client.Tests.Component
{
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SendWithUs.Client;

[TestClass]
public class DripCampaignActivateConverterTests : ComponentTestsBase
{
#region Helpers

#endregion

#region Test methods

[TestMethod]
public void WriteJson_MinimalDripCampaignActivateRequest_Succeeds()
{
var campaignId = TestHelper.GetUniqueId();
var recipientAddress = TestHelper.GetUniqueId();
var request = new DripCampaignActivateRequest(campaignId, recipientAddress);
var writer = BufferedJsonStringWriter.Create();
var serializer = JsonSerializer.Create();
var converter = new DripCampaignActivateRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateDripCampaignActivateRequest(jsonObject, recipientAddress, false);
}

[TestMethod]
public void WriteJson_WithData_IncludesAllData()
{
var campaignId = TestHelper.GetUniqueId();
var recipientAddress = TestHelper.GetUniqueId();
var data = TestHelper.GetRandomDictionary();
var request = new DripCampaignActivateRequest(campaignId, recipientAddress, data);
var writer = BufferedJsonStringWriter.Create();
var serializer = new JsonSerializer();
var converter = new DripCampaignActivateRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateDripCampaignActivateRequest(jsonObject, recipientAddress, true);
var jsonData = jsonObject.GetValue("email_data") as JObject;
Assert.IsNotNull(jsonData);
Assert.AreEqual(data.Count, jsonData.Count);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

namespace SendWithUs.Client.Tests.Component
{
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SendWithUs.Client;

[TestClass]
public class DripCampaignDeactivateAllConverterTests : ComponentTestsBase
{
#region Helpers

#endregion

#region Test methods

[TestMethod]
public void WriteJson_MinimalDripCampaignDeactivateAllRequest_Succeeds()
{
var recipientAddress = TestHelper.GetUniqueId();
var request = new DripCampaignDeactivateAllRequest(recipientAddress);
var writer = BufferedJsonStringWriter.Create();
var serializer = JsonSerializer.Create();
var converter = new DripCampaignDeactivateAllRequestConverter();

converter.WriteJson(writer, request, serializer);
var jsonObject = writer.GetBufferAs<JObject>();

Assert.IsNotNull(jsonObject);
this.ValidateDripCampaignDeactivateAllRequest(jsonObject, recipientAddress, false);
}
#endregion
}
}
Loading