Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Articles Object Model #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
262 changes: 90 additions & 172 deletions README.md

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions src/Intercom.Tests/Clients/ArticlesClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using NUnit.Framework;
using System;
using Intercom.Core;
using Intercom.Data;
using Intercom.Clients;
using Intercom.Exceptions;
using Intercom.Factories;
using RestSharp;
using RestSharp.Authenticators;
using System.Collections.Generic;
using Newtonsoft.Json;
using Moq;

namespace Intercom.Test
{
[TestFixture()]
internal class ArticlesClientTest : TestBase
{
private ArticlesClient articlesClient;

public ArticlesClientTest()
: base()
{
var auth = new Authentication(AppId, AppKey);
var restClientFactory = new RestClientFactory(auth);
articlesClient = new ArticlesClient(restClientFactory);
}

[Test()]
public void View_WithEmptyString_ThrowException()
{
Assert.Throws<ArgumentNullException>(() => articlesClient.View(String.Empty));
}

[Test()]
public void View_NoId_ThrowException()
{
Assert.Throws<ArgumentException>(() => articlesClient.View(new Article()));
}

[Test()]
public void Create_WithNull_ThrowException()
{
Assert.Throws<ArgumentNullException>(() => articlesClient.Create(null));
}

[Test()]
public void GetArticles_WithNull_ThrowException()
{
Assert.Throws<ArgumentNullException>(() => articlesClient.GetArticles(null));
}

[Test()]
public void GetArticles_WithNoId_ThrowException()
{
Assert.Throws<ArgumentNullException>(() => articlesClient.GetArticles(new Article()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.IO;

using Intercom.Test;
using Newtonsoft.Json;
using NUnit.Framework;

using Intercom.Converters.ClassConverters;

namespace Intercom.Tests.Converters.ClassConverters
{
[TestFixture]
public class DateTimeOffsetJsonConverterTest : TestBase
{
private const string _DateCreatedISO = "1989-04-16T00:15:00Z";
private const string _DateCreatedUnix = "608688900";
private const string _Null = "null";

private readonly DateTimeOffsetJsonConverter _converter;

public DateTimeOffsetJsonConverterTest()
{
_converter = new DateTimeOffsetJsonConverter();
}

[TestCase(_DateCreatedUnix)]
public void ReadJson_ForDateTimeOffset_ReturnsValidDateTimeOffset(string json)
{
using (StringReader stringReader = new StringReader(json))
using (JsonReader jsonReader = new JsonTextReader(stringReader))
{
DateTimeOffset dateCreated = (DateTimeOffset)_converter.ReadJson(jsonReader, typeof(DateTimeOffset), null, null);

Assert.AreEqual(_ParseUtcDateString(_DateCreatedISO), dateCreated);
}
}

[TestCase(_DateCreatedISO)]
public void WriteJsonForDateTimeOffset_ForcesUtc(string input)
{
DateTimeOffset inputDate;

try
{
inputDate = _ParseUtcDateString(input);
}

catch (Exception ex)
{
throw new Exception("Failed to properly parse the test input.", ex);
}

inputDate.ToOffset(TimeSpan.FromHours(-5));

using (StringWriter stringWriter = new StringWriter())
using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter))
{
_converter.WriteJson(jsonWriter, inputDate, null);

Assert.AreEqual(_DateCreatedUnix, stringWriter.GetStringBuilder().ToString());
}
}

[TestCase(_Null)]
public void ReadJson_ForNullableDateTimeOffset_ReturnsNull(string json)
{
using (StringReader stringReader = new StringReader(json))
using (JsonReader jsonReader = new JsonTextReader(stringReader))
{
DateTimeOffset? dateCreated = (DateTimeOffset?)_converter.ReadJson(jsonReader, typeof(DateTimeOffset?), null, null);

Assert.AreEqual(null, dateCreated);
}
}

[TestCase(null)]
public void WriteJsonForNullableDateTimeOffset_ReturnsNull(DateTimeOffset? input)
{
using (StringWriter stringWriter = new StringWriter())
using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter))
{
_converter.WriteJson(jsonWriter, input, null);

Assert.AreEqual(_Null, stringWriter.GetStringBuilder().ToString());
}
}

[TestCase(_DateCreatedISO)]
public void WriteJson_ForDateTimeOffset_ReturnsValidUnixTimestamp(string input)
{
DateTimeOffset inputDate;

try
{
inputDate = _ParseUtcDateString(input);
}

catch (Exception ex)
{
throw new Exception("Failed to properly parse the test input.", ex);
}

using (StringWriter stringWriter = new StringWriter())
using (JsonWriter jsonWriter = new JsonTextWriter(stringWriter))
{
_converter.WriteJson(jsonWriter, inputDate, null);

Assert.AreEqual(_DateCreatedUnix, stringWriter.GetStringBuilder().ToString());
}
}

private DateTimeOffset _ParseUtcDateString(string input)
{
return DateTimeOffset.Parse(input);
}
}
}
Loading