From 0e283733549c160b354f73b270cadaa9482f4501 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Wed, 19 Jun 2024 12:54:35 +0200 Subject: [PATCH 1/5] fix: Add missing fields of EventSource --- Box.V2.Test/BoxEventsManagerTest.cs | 5 ++++- Box.V2/Models/BoxFileEventSource.cs | 7 +++++++ Box.V2/Models/BoxFolderEventSource.cs | 7 +++++++ .../Models/BoxGroupFileCollaborationEventSource.cs | 7 +++++++ .../BoxGroupFolderCollaborationEventSource.cs | 7 +++++++ .../Models/BoxUserFileCollaborationEventSource.cs | 14 ++++++++++++++ .../BoxUserFolderCollaborationEventSource.cs | 14 ++++++++++++++ Box.V2/Models/BoxWebLinkEventSource.cs | 7 +++++++ 8 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Box.V2.Test/BoxEventsManagerTest.cs b/Box.V2.Test/BoxEventsManagerTest.cs index a74b6e1e4..5e86542e1 100644 --- a/Box.V2.Test/BoxEventsManagerTest.cs +++ b/Box.V2.Test/BoxEventsManagerTest.cs @@ -70,7 +70,7 @@ public async Task GetGroupEvents_ValidResponse() [TestMethod] public async Task GetUserEventsFile_ValidResponse() { - var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_id\":\"285663442\",\"user_name\":\"foo\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; + var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_id\":\"285663442\",\"user_name\":\"foo\",\"user_email\": \"testuser@example.com\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\": \"user\",\"id\":\"33333\",\"name\": \"Test User\",\"login\":\"testuser@example.com\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync>(It.IsAny())) .Returns(Task.FromResult>>(new BoxResponse>() @@ -88,6 +88,9 @@ public async Task GetUserEventsFile_ValidResponse() Assert.AreEqual(userFileEvents.Entries[0].Source.GetType(), typeof(BoxUserFileCollaborationEventSource)); Assert.AreEqual(userFileEventSource.Id, "283257336425"); Assert.AreEqual(userFileEventSource.Name, "ScreenShot2018-03-12at5.44.00PM.png"); + Assert.AreEqual(userFileEventSource.UserEmail, "testuser@example.com"); + Assert.AreEqual(userFileEventSource.OwnedBy.Id, "33333"); + Assert.AreEqual(userFileEventSource.OwnedBy.Name, "Test User"); } [TestMethod] diff --git a/Box.V2/Models/BoxFileEventSource.cs b/Box.V2/Models/BoxFileEventSource.cs index 7e847dda7..304143e9b 100644 --- a/Box.V2/Models/BoxFileEventSource.cs +++ b/Box.V2/Models/BoxFileEventSource.cs @@ -11,6 +11,7 @@ public class BoxFileEventSource : BoxEntity public const string FieldItemId = "item_id"; public const string FieldItemName = "item_name"; public const string FieldItemParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The type of the event source @@ -35,5 +36,11 @@ public class BoxFileEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldItemParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxFolderEventSource.cs b/Box.V2/Models/BoxFolderEventSource.cs index a8b69ac47..35c5fc739 100644 --- a/Box.V2/Models/BoxFolderEventSource.cs +++ b/Box.V2/Models/BoxFolderEventSource.cs @@ -11,6 +11,7 @@ public class BoxFolderEventSource : BoxEntity public const string FieldItemId = "item_id"; public const string FieldItemName = "item_name"; public const string FieldItemParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The type of the event source @@ -35,5 +36,11 @@ public class BoxFolderEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldItemParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs index 485066090..ffc18e445 100644 --- a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs @@ -9,6 +9,7 @@ public class BoxGroupFileCollaborationEventSource : BoxEntity public const string FieldGroupId = "group_id"; public const string FieldGroupName = "group_name"; public const string FieldParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The unique ID of the file being collaborated on. @@ -44,5 +45,11 @@ public class BoxGroupFileCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs index ce1e1da62..2897211f9 100644 --- a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs @@ -9,6 +9,7 @@ public class BoxGroupFolderCollaborationEventSource : BoxEntity public const string FieldGroupId = "group_id"; public const string FieldGroupName = "group_name"; public const string FieldParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The unique ID of the folder being collaborated on. @@ -44,5 +45,11 @@ public class BoxGroupFolderCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs index b3a961df1..eaa03e9fa 100644 --- a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs @@ -8,7 +8,9 @@ public class BoxUserFileCollaborationEventSource : BoxEntity public const string FieldFileName = "file_name"; public const string FieldUserId = "user_id"; public const string FieldUserName = "user_name"; + public const string FieldUserEmail = "user_email"; public const string FieldParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The unique ID of the file being collaborated on. @@ -39,10 +41,22 @@ public class BoxUserFileCollaborationEventSource : BoxEntity [JsonProperty(PropertyName = FieldUserName)] public string UserName { get; private set; } + /// + /// The email of the user collaborating on the file. + /// + [JsonProperty(PropertyName = FieldUserEmail)] + public string UserEmail { get; private set; } + /// /// The parent folder of the file being collaborated on. /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs index 668285d62..f50a09e4c 100644 --- a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs @@ -11,7 +11,9 @@ public class BoxUserFolderCollaborationEventSource : BoxEntity public const string FieldFolderName = "folder_name"; public const string FieldUserId = "user_id"; public const string FieldUserName = "user_name"; + public const string FieldUserEmail = "user_email"; public const string FieldParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The unique ID of the folder being collaborated on. @@ -42,10 +44,22 @@ public class BoxUserFolderCollaborationEventSource : BoxEntity [JsonProperty(PropertyName = FieldUserName)] public string UserName { get; private set; } + /// + /// The email of the user collaborating on the folder. + /// + [JsonProperty(PropertyName = FieldUserEmail)] + public string UserEmail { get; private set; } + /// /// The parent folder of the folder being collaborated on. /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } diff --git a/Box.V2/Models/BoxWebLinkEventSource.cs b/Box.V2/Models/BoxWebLinkEventSource.cs index 0a3f27621..9a7198586 100644 --- a/Box.V2/Models/BoxWebLinkEventSource.cs +++ b/Box.V2/Models/BoxWebLinkEventSource.cs @@ -11,6 +11,7 @@ public class BoxWebLinkEventSource : BoxEntity public const string FieldItemId = "item_id"; public const string FieldItemName = "item_name"; public const string FieldItemParent = "parent"; + public const string FieldOwnedBy = "owned_by"; /// /// The type of the event source @@ -35,5 +36,11 @@ public class BoxWebLinkEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldItemParent)] public BoxFolder Parent { get; private set; } + + /// + /// The user who owns this item + /// + [JsonProperty(PropertyName = FieldOwnedBy)] + public BoxUser OwnedBy { get; private set; } } } From 4ebaa4f0e4826c5c44e9146be30a24cb1437e4a5 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Wed, 19 Jun 2024 12:59:46 +0200 Subject: [PATCH 2/5] fix linter --- Box.V2/Models/BoxFolderEventSource.cs | 2 +- Box.V2/Models/BoxGroupFileCollaborationEventSource.cs | 2 +- Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs | 2 +- Box.V2/Models/BoxUserFileCollaborationEventSource.cs | 2 +- Box.V2/Models/BoxUserFolderCollaborationEventSource.cs | 2 +- Box.V2/Models/BoxWebLinkEventSource.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Box.V2/Models/BoxFolderEventSource.cs b/Box.V2/Models/BoxFolderEventSource.cs index 35c5fc739..dfa41d12a 100644 --- a/Box.V2/Models/BoxFolderEventSource.cs +++ b/Box.V2/Models/BoxFolderEventSource.cs @@ -36,7 +36,7 @@ public class BoxFolderEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldItemParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// diff --git a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs index ffc18e445..480aab94f 100644 --- a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs @@ -45,7 +45,7 @@ public class BoxGroupFileCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// diff --git a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs index 2897211f9..61e7881b9 100644 --- a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs @@ -45,7 +45,7 @@ public class BoxGroupFolderCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// diff --git a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs index eaa03e9fa..9f12fc922 100644 --- a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs @@ -52,7 +52,7 @@ public class BoxUserFileCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// diff --git a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs index f50a09e4c..568db267a 100644 --- a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs @@ -55,7 +55,7 @@ public class BoxUserFolderCollaborationEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// diff --git a/Box.V2/Models/BoxWebLinkEventSource.cs b/Box.V2/Models/BoxWebLinkEventSource.cs index 9a7198586..0a5017398 100644 --- a/Box.V2/Models/BoxWebLinkEventSource.cs +++ b/Box.V2/Models/BoxWebLinkEventSource.cs @@ -36,7 +36,7 @@ public class BoxWebLinkEventSource : BoxEntity /// [JsonProperty(PropertyName = FieldItemParent)] public BoxFolder Parent { get; private set; } - + /// /// The user who owns this item /// From 59156421d358bb31dca210b2b765b0125fbda2bd Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 20 Jun 2024 15:43:32 +0200 Subject: [PATCH 3/5] Update code --- Box.V2.Test/BoxEventsManagerTest.cs | 50 ++++++++++++++++++++++++++++ Box.V2/Converter/BoxItemConverter.cs | 5 +-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Box.V2.Test/BoxEventsManagerTest.cs b/Box.V2.Test/BoxEventsManagerTest.cs index 5e86542e1..b6add340f 100644 --- a/Box.V2.Test/BoxEventsManagerTest.cs +++ b/Box.V2.Test/BoxEventsManagerTest.cs @@ -93,6 +93,32 @@ public async Task GetUserEventsFile_ValidResponse() Assert.AreEqual(userFileEventSource.OwnedBy.Name, "Test User"); } + [TestMethod] + public async Task GetUserEventsFile_ExternalUser_ValidResponse() + { + var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_email\":\"externaluser@box.com\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\": \"user\",\"id\":\"33333\",\"name\": \"Test User\",\"login\":\"testuser@example.com\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; + IBoxRequest boxRequest = null; + Handler.Setup(h => h.ExecuteAsync>(It.IsAny())) + .Returns(Task.FromResult>>(new BoxResponse>() + { + Status = ResponseStatus.Success, + ContentString = responseString + })).Callback(r => boxRequest = r); + + /*** Act ***/ + var userFileEvents = await _eventsManager.EnterpriseEventsAsync(); + + var userFileEventSource = userFileEvents.Entries[0].Source as BoxUserFileCollaborationEventSource; + + Assert.AreEqual(userFileEvents.Entries[0].EventType, "COLLABORATION_INVITE"); + Assert.AreEqual(userFileEvents.Entries[0].Source.GetType(), typeof(BoxUserFileCollaborationEventSource)); + Assert.AreEqual(userFileEventSource.Id, "283257336425"); + Assert.AreEqual(userFileEventSource.Name, "ScreenShot2018-03-12at5.44.00PM.png"); + Assert.AreEqual(userFileEventSource.UserEmail, "externaluser@box.com"); + Assert.AreEqual(userFileEventSource.OwnedBy.Id, "33333"); + Assert.AreEqual(userFileEventSource.OwnedBy.Name, "Test User"); + } + [TestMethod] public async Task GetUserEventsFolder_ValidResponse() { @@ -116,6 +142,30 @@ public async Task GetUserEventsFolder_ValidResponse() Assert.AreEqual(userFolderEventSource.Name, "SharedWithServiceAccount"); } + [TestMethod] + public async Task GetUserEventsFolder_ExternalUser_ValidResponse() + { + var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"folder_id\":\"47846340014\",\"folder_name\":\"SharedWithServiceAccount\",\"user_email\":\"externaluser@box.com\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; + IBoxRequest boxRequest = null; + Handler.Setup(h => h.ExecuteAsync>(It.IsAny())) + .Returns(Task.FromResult>>(new BoxResponse>() + { + Status = ResponseStatus.Success, + ContentString = responseString + })).Callback(r => boxRequest = r); + + /*** Act ***/ + var userFolderEvents = await _eventsManager.EnterpriseEventsAsync(); + + var userFolderEventSource = userFolderEvents.Entries[0].Source as BoxUserFolderCollaborationEventSource; + + Assert.AreEqual(userFolderEvents.Entries[0].EventType, "COLLABORATION_INVITE"); + Assert.AreEqual(userFolderEvents.Entries[0].Source.GetType(), typeof(BoxUserFolderCollaborationEventSource)); + Assert.AreEqual(userFolderEventSource.Id, "47846340014"); + Assert.AreEqual(userFolderEventSource.Name, "SharedWithServiceAccount"); + Assert.AreEqual(userFolderEventSource.UserEmail, "externaluser@box.com"); + } + [TestMethod] public async Task GetGroupEventsFolder_ValidResponse() { diff --git a/Box.V2/Converter/BoxItemConverter.cs b/Box.V2/Converter/BoxItemConverter.cs index 21bd986cc..bab7f1e7f 100644 --- a/Box.V2/Converter/BoxItemConverter.cs +++ b/Box.V2/Converter/BoxItemConverter.cs @@ -14,6 +14,7 @@ internal class BoxItemConverter : JsonCreationConverter private const string WatermarkType = "watermark"; private const string GroupId = "group_id"; private const string UserId = "user_id"; + private const string UserEmail = "user_email"; private const string FolderId = "folder_id"; private const string FileId = "file_id"; @@ -133,11 +134,11 @@ protected override BoxEntity Create(Type objectType, JObject jObject) return new BoxGroupEventSource(); } } - else if (FieldExists(UserId, jObject) && FieldExists(FileId, jObject)) + else if ((FieldExists(UserId, jObject) || FieldExists(UserEmail, jObject)) && FieldExists(FileId, jObject)) { return new BoxUserFileCollaborationEventSource(); } - else if (FieldExists(UserId, jObject) && FieldExists(FolderId, jObject)) + else if ((FieldExists(UserId, jObject) || FieldExists(UserEmail, jObject)) && FieldExists(FolderId, jObject)) { return new BoxUserFolderCollaborationEventSource(); } From 398856419df13e14299c0e7cf19b3d84297f6819 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Thu, 20 Jun 2024 16:51:08 +0200 Subject: [PATCH 4/5] Ignore Type field --- Box.V2/Models/BoxGroupEventSource.cs | 1 + Box.V2/Models/BoxGroupFileCollaborationEventSource.cs | 1 + Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs | 1 + Box.V2/Models/BoxUserFileCollaborationEventSource.cs | 1 + Box.V2/Models/BoxUserFolderCollaborationEventSource.cs | 1 + 5 files changed, 5 insertions(+) diff --git a/Box.V2/Models/BoxGroupEventSource.cs b/Box.V2/Models/BoxGroupEventSource.cs index 106eb40a4..d0fd9010b 100644 --- a/Box.V2/Models/BoxGroupEventSource.cs +++ b/Box.V2/Models/BoxGroupEventSource.cs @@ -19,6 +19,7 @@ public class BoxGroupEventSource : BoxEntity /// /// The type of the object. /// + [JsonIgnore] public override string Type { get { return "group"; } protected set { return; } } /// diff --git a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs index 480aab94f..08159288f 100644 --- a/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFileCollaborationEventSource.cs @@ -20,6 +20,7 @@ public class BoxGroupFileCollaborationEventSource : BoxEntity /// /// The type of the object. /// + [JsonIgnore] public override string Type { get { return "file"; } protected set { return; } } /// diff --git a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs index 61e7881b9..fbad53383 100644 --- a/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxGroupFolderCollaborationEventSource.cs @@ -20,6 +20,7 @@ public class BoxGroupFolderCollaborationEventSource : BoxEntity /// /// The type of the object. /// + [JsonIgnore] public override string Type { get { return "folder"; } protected set { return; } } /// diff --git a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs index 9f12fc922..6216416cd 100644 --- a/Box.V2/Models/BoxUserFileCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFileCollaborationEventSource.cs @@ -21,6 +21,7 @@ public class BoxUserFileCollaborationEventSource : BoxEntity /// /// The type of the object. /// + [JsonIgnore] public override string Type { get { return "file"; } protected set { return; } } /// diff --git a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs index 568db267a..39fbd8151 100644 --- a/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs +++ b/Box.V2/Models/BoxUserFolderCollaborationEventSource.cs @@ -24,6 +24,7 @@ public class BoxUserFolderCollaborationEventSource : BoxEntity /// /// The type of the object. /// + [JsonIgnore] public override string Type { get { return "folder"; } protected set { return; } } /// From 981f7f3dcf40dc37de16a8c621d6f52354ec8e5b Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Fri, 21 Jun 2024 10:34:32 +0200 Subject: [PATCH 5/5] Update unit test --- Box.V2.Test/BoxEventsManagerTest.cs | 5 +- .../Converters/BoxJsonConverterTest.cs | 107 ++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 Box.V2.Test/Converters/BoxJsonConverterTest.cs diff --git a/Box.V2.Test/BoxEventsManagerTest.cs b/Box.V2.Test/BoxEventsManagerTest.cs index b6add340f..ed248ab61 100644 --- a/Box.V2.Test/BoxEventsManagerTest.cs +++ b/Box.V2.Test/BoxEventsManagerTest.cs @@ -70,7 +70,7 @@ public async Task GetGroupEvents_ValidResponse() [TestMethod] public async Task GetUserEventsFile_ValidResponse() { - var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_id\":\"285663442\",\"user_name\":\"foo\",\"user_email\": \"testuser@example.com\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\": \"user\",\"id\":\"33333\",\"name\": \"Test User\",\"login\":\"testuser@example.com\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; + var responseString = "{\"chunk_size\": 1, \"next_stream_position\": 123, \"entries\": [{\"source\":{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_id\":\"285663442\",\"user_name\":\"foo\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\": \"user\",\"id\":\"33333\",\"name\": \"Test User\",\"login\":\"testuser@example.com\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"},\"created_at\":\"2018-03-16T15:12:52-07:00\",\"event_id\":\"85c57bf3-bc15-4d24-93bc-955c796217c8\",\"event_type\":\"COLLABORATION_INVITE\",\"ip_address\":\"UnknownIP\",\"type\":\"event\",\"session_id\":null,\"additional_details\":null}]}"; IBoxRequest boxRequest = null; Handler.Setup(h => h.ExecuteAsync>(It.IsAny())) .Returns(Task.FromResult>>(new BoxResponse>() @@ -88,7 +88,8 @@ public async Task GetUserEventsFile_ValidResponse() Assert.AreEqual(userFileEvents.Entries[0].Source.GetType(), typeof(BoxUserFileCollaborationEventSource)); Assert.AreEqual(userFileEventSource.Id, "283257336425"); Assert.AreEqual(userFileEventSource.Name, "ScreenShot2018-03-12at5.44.00PM.png"); - Assert.AreEqual(userFileEventSource.UserEmail, "testuser@example.com"); + Assert.AreEqual(userFileEventSource.UserId, "285663442"); + Assert.AreEqual(userFileEventSource.UserName, "foo"); Assert.AreEqual(userFileEventSource.OwnedBy.Id, "33333"); Assert.AreEqual(userFileEventSource.OwnedBy.Name, "Test User"); } diff --git a/Box.V2.Test/Converters/BoxJsonConverterTest.cs b/Box.V2.Test/Converters/BoxJsonConverterTest.cs new file mode 100644 index 000000000..2dffde9ec --- /dev/null +++ b/Box.V2.Test/Converters/BoxJsonConverterTest.cs @@ -0,0 +1,107 @@ +using Box.V2.Converter; +using Box.V2.Models; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Box.V2.Test +{ + [TestClass] + public class BoxJsonConverterTest : BoxResourceManagerTest + { + private readonly IBoxConverter _converter; + + public BoxJsonConverterTest() + { + _converter = new BoxJsonConverter(); + } + + [TestMethod] + public void BoxUserFileCollaborationEventSource_ValidateConversion() + { + var sourceString = "{\"file_id\":\"283257336425\",\"file_name\":\"ScreenShot2018-03-12at5.44.00PM.png\",\"user_id\":\"285663442\",\"user_name\":\"foo\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"}}"; + var sourceObject = _converter.Parse(sourceString); + + var serializedObjectString = _converter.Serialize(sourceObject); + + var boxUserFileCollaborationEventSource = _converter.Parse(serializedObjectString); + + Assert.AreEqual(boxUserFileCollaborationEventSource.GetType(), typeof(BoxUserFileCollaborationEventSource)); + Assert.AreEqual(boxUserFileCollaborationEventSource.Id, "283257336425"); + Assert.AreEqual(boxUserFileCollaborationEventSource.Name, "ScreenShot2018-03-12at5.44.00PM.png"); + Assert.AreEqual(boxUserFileCollaborationEventSource.UserName, "foo"); + Assert.AreEqual(boxUserFileCollaborationEventSource.OwnedBy.Id, "11111"); + Assert.AreEqual(boxUserFileCollaborationEventSource.Parent.Id, "0"); + } + + [TestMethod] + public void BoxUserFolderCollaborationEventSource_ValidateConversion() + { + var sourceString = "{\"folder_id\":\"47846340014\",\"folder_name\":\"SharedWithServiceAccount\",\"user_id\":\"182069272\",\"user_name\":\"MattWiller\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"}}"; + var sourceObject = _converter.Parse(sourceString); + + var serializedObjectString = _converter.Serialize(sourceObject); + + var boxUserFolderCollaborationEventSource = _converter.Parse(serializedObjectString); + + Assert.AreEqual(boxUserFolderCollaborationEventSource.GetType(), typeof(BoxUserFolderCollaborationEventSource)); + Assert.AreEqual(boxUserFolderCollaborationEventSource.Id, "47846340014"); + Assert.AreEqual(boxUserFolderCollaborationEventSource.UserId, "182069272"); + Assert.AreEqual(boxUserFolderCollaborationEventSource.UserName, "MattWiller"); + Assert.AreEqual(boxUserFolderCollaborationEventSource.Name, "SharedWithServiceAccount"); + Assert.AreEqual(boxUserFolderCollaborationEventSource.OwnedBy.Id, "11111"); + Assert.AreEqual(boxUserFolderCollaborationEventSource.Parent.Id, "0"); + } + + [TestMethod] + public void BoxGroupFolderCollaborationEventSource_ValidateConversion() + { + var sourceString = "{\"folder_id\":\"47846340014\",\"folder_name\":\"SharedWithServiceAccount\",\"group_id\":\"182069272\",\"group_name\":\"TestGroup\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\":\"user\",\"id\":\"275035869\",\"name\":\"MattWiller\",\"login\":\"mwiller + appusers@box.com\"}}"; + var sourceObject = _converter.Parse(sourceString); + + var serializedObjectString = _converter.Serialize(sourceObject); + + var boxGroupFolderCollaborationEventSource = _converter.Parse(serializedObjectString); + + Assert.AreEqual(boxGroupFolderCollaborationEventSource.GetType(), typeof(BoxGroupFolderCollaborationEventSource)); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.Id, "47846340014"); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.Name, "SharedWithServiceAccount"); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.GroupId, "182069272"); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.GroupName, "TestGroup"); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.Parent.Id, "0"); + Assert.AreEqual(boxGroupFolderCollaborationEventSource.OwnedBy.Id, "275035869"); + } + + [TestMethod] + public void BoxGroupFileCollaborationEventSource_ValidateConversion() + { + var sourceString = "{\"file_id\":\"47846340014\",\"file_name\":\"test-picture.jpg\",\"group_id\":\"182069272\",\"group_name\":\"TestGroup\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"test@user.com\"}}"; + var sourceObject = _converter.Parse(sourceString); + + var serializedObjectString = _converter.Serialize(sourceObject); + + var boxGroupFileCollaborationEventSource = _converter.Parse(serializedObjectString); + + Assert.AreEqual(boxGroupFileCollaborationEventSource.GetType(), typeof(BoxGroupFileCollaborationEventSource)); + Assert.AreEqual(boxGroupFileCollaborationEventSource.Id, "47846340014"); + Assert.AreEqual(boxGroupFileCollaborationEventSource.Name, "test-picture.jpg"); + Assert.AreEqual(boxGroupFileCollaborationEventSource.GroupId, "182069272"); + Assert.AreEqual(boxGroupFileCollaborationEventSource.GroupName, "TestGroup"); + Assert.AreEqual(boxGroupFileCollaborationEventSource.Parent.Id, "0"); + Assert.AreEqual(boxGroupFileCollaborationEventSource.OwnedBy.Id, "11111"); + } + + [TestMethod] + public void BoxGroupEventSource_ValidateConversion() + { + var sourceString = "{\"group_id\": \"182069272\",\"group_name\": \"TestGroup\"}"; + var sourceObject = _converter.Parse(sourceString); + + var serializedObjectString = _converter.Serialize(sourceObject); + + var boxGroupEventSource = _converter.Parse(serializedObjectString); + + Assert.AreEqual(boxGroupEventSource.GetType(), typeof(BoxGroupEventSource)); + Assert.AreEqual(boxGroupEventSource.Id, "182069272"); + Assert.AreEqual(boxGroupEventSource.Name, "TestGroup"); + } + } +}