Skip to content

Commit

Permalink
fix: add missing enum to string parsing in several places (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda committed Mar 31, 2022
1 parent 7c73025 commit e370282
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Box.V2.Test/BoxFileRequestsManagerTest.cs
Expand Up @@ -3,6 +3,7 @@
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Box.V2.Test.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

Expand Down Expand Up @@ -146,6 +147,7 @@ public async Task UpdateFileRequest_Success()
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Put, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/file_requests/42037322"), boxRequest.AbsoluteUri);
Assert.IsTrue(boxRequest.Payload.ContainsKeyValue("status", "inactive"));

// Response check
Assert.AreEqual("42037322", response.Id);
Expand Down
6 changes: 5 additions & 1 deletion Box.V2.Test/BoxSignRequestsManagerTest.cs
Expand Up @@ -4,8 +4,10 @@
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Box.V2.Test.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json.Linq;

namespace Box.V2.Test
{
Expand Down Expand Up @@ -45,7 +47,8 @@ public async Task CreateSignRequest_RequiredParams_Success()
{
new BoxSignRequestSignerCreate()
{
Email = "example@gmail.com"
Email = "example@gmail.com",
Role = BoxSignRequestSignerRole.signer,
}
};

Expand All @@ -70,6 +73,7 @@ public async Task CreateSignRequest_RequiredParams_Success()
Assert.IsNotNull(boxRequest);
Assert.AreEqual(RequestMethod.Post, boxRequest.Method);
Assert.AreEqual(new Uri("https://api.box.com/2.0/sign_requests"), boxRequest.AbsoluteUri);
Assert.IsTrue(boxRequest.Payload.ContainsKeyValue("signers[0].role", "signer"));

// Response check
Assert.AreEqual(1, response.SourceFiles.Count);
Expand Down
2 changes: 2 additions & 0 deletions Box.V2.Test/BoxTasksManagerTest.cs
Expand Up @@ -4,6 +4,7 @@
using Box.V2.Managers;
using Box.V2.Models;
using Box.V2.Models.Request;
using Box.V2.Test.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Newtonsoft.Json;
Expand Down Expand Up @@ -483,6 +484,7 @@ public async Task CreateTask_WithCompletionRule()
Assert.AreEqual(taskCreateRequest.Item.Type, payload.Item.Type);
Assert.AreEqual(taskCreateRequest.Message, payload.Message);
Assert.AreEqual(taskCreateRequest.CompletionRule, payload.CompletionRule);
Assert.IsTrue(boxRequest.Payload.ContainsKeyValue("completion_rule", "any_assignee"));

//Response check
Assert.AreEqual(BoxCompletionRule.any_assignee, result.CompletionRule);
Expand Down
9 changes: 9 additions & 0 deletions Box.V2.Test/Extensions/DictionaryExtensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace Box.V2.Test.Extensions
{
Expand All @@ -10,5 +11,13 @@ public static class DictionaryExtensions
{
return dictionary.TryGetValue(expectedKey, out T actualValue) && EqualityComparer<T>.Default.Equals(actualValue, expectedValue);
}

public static bool ContainsKeyValue(this string json,
string expectedKey, string expectedValue)
{
var jObject = JObject.Parse(json);
var token = jObject.SelectToken(expectedKey);
return expectedValue == token.ToString();
}
}
}
2 changes: 2 additions & 0 deletions Box.V2/Models/BoxFileRequestObject.cs
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
Expand Down Expand Up @@ -80,6 +81,7 @@ public class BoxFileRequestObject : BoxEntity
/// Describes the status of the sign request.
/// </summary>
[JsonProperty(PropertyName = FieldStatus)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxFileRequestStatus Status { get; private set; }

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Box.V2/Models/BoxSignRequest.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
Expand Down Expand Up @@ -125,6 +126,7 @@ public class BoxSignRequest : BoxEntity
/// Describes the status of the sign request.
/// </summary>
[JsonProperty(PropertyName = FieldStatus)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSignRequestStatus Status { get; private set; }
}

Expand Down
4 changes: 4 additions & 0 deletions Box.V2/Models/BoxSignRequestSigner.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
Expand Down Expand Up @@ -67,6 +68,7 @@ public class BoxSignRequestSigner
/// Value is one of signer,approver,final_copy_reader
/// </summary>
[JsonProperty(PropertyName = FieldRole)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSignRequestSignerRole Role { get; private set; }

/// <summary>
Expand Down Expand Up @@ -103,6 +105,7 @@ public class BoxSignRequestSignerInput
/// Type of input.
/// </summary>
[JsonProperty(PropertyName = FieldType)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSignRequestSingerInputType Type { get; private set; }

/// <summary>
Expand Down Expand Up @@ -159,6 +162,7 @@ public class BoxSignRequestSignerDecision
/// Type of decision made by the signer.
/// </summary>
[JsonProperty(PropertyName = FieldType)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSignRequestSingerDecisionType Type { get; private set; }

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Box.V2/Models/BoxSortOrder.cs
@@ -1,16 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
public class BoxSortOrder
{
[JsonProperty(PropertyName = "by")]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSortBy By { get; private set; }

[JsonProperty(PropertyName = "sort")]
public virtual string Sort { get; private set; }

[JsonProperty(PropertyName = "direction")]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxSortDirection Direction { get; private set; }
}

Expand Down
2 changes: 2 additions & 0 deletions Box.V2/Models/BoxTask.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
Expand Down Expand Up @@ -59,6 +60,7 @@ public class BoxTask : BoxEntity
/// Gets value indicating which assignees need to complete this task before the task is considered completed.
/// </summary>
[JsonProperty(PropertyName = FieldCompletionRule)]
[JsonConverter(typeof(StringEnumConverter))]
public virtual BoxCompletionRule CompletionRule { get; private set; }
}
}
2 changes: 2 additions & 0 deletions Box.V2/Models/Request/BoxFileRequestCopyRequest.cs
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models.Request
{
Expand Down Expand Up @@ -51,6 +52,7 @@ public class BoxFileRequestCopyRequest
/// This will default to the value on the existing file request.
/// </summary>
[JsonProperty(PropertyName = "status")]
[JsonConverter(typeof(StringEnumConverter))]
public BoxFileRequestStatus? Status { get; set; }

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Box.V2/Models/Request/BoxFileRequestUpdateRequest.cs
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models.Request
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public class BoxFileRequestUpdateRequest
/// This will default to the value on the existing file request.
/// </summary>
[JsonProperty(PropertyName = "status")]
[JsonConverter(typeof(StringEnumConverter))]
public BoxFileRequestStatus? Status { get; set; }

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Box.V2/Models/Request/BoxSignRequestCreateRequest.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models.Request
{
Expand Down Expand Up @@ -156,6 +157,7 @@ public class BoxSignRequestSignerCreate
/// Value is one of signer,approver,final_copy_reader
/// </summary>
[JsonProperty(PropertyName = "role")]
[JsonConverter(typeof(StringEnumConverter))]
public BoxSignRequestSignerRole? Role { get; set; }
}
}
2 changes: 2 additions & 0 deletions Box.V2/Models/Request/BoxTaskCreateRequest.cs
@@ -1,5 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Box.V2.Models
{
Expand Down Expand Up @@ -42,6 +43,7 @@ public string Action
/// Defines which assignees need to complete this task before the task is considered completed.
/// </summary>
[JsonProperty(PropertyName = "completion_rule")]
[JsonConverter(typeof(StringEnumConverter))]
public BoxCompletionRule? CompletionRule { get; set; }
}
}

0 comments on commit e370282

Please sign in to comment.