-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add missing fields of
EventSource
(#956)
Co-authored-by: wmagnuson <[email protected]>
- Loading branch information
1 parent
1f89bb0
commit 138eda5
Showing
11 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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\":\"[email protected]\"},\"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\":\"[email protected]\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"[email protected]\"},\"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<BoxEventCollection<BoxEnterpriseEvent>>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxEventCollection<BoxEnterpriseEvent>>>(new BoxResponse<BoxEventCollection<BoxEnterpriseEvent>>() | ||
|
@@ -88,6 +88,36 @@ 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.UserId, "285663442"); | ||
Assert.AreEqual(userFileEventSource.UserName, "foo"); | ||
Assert.AreEqual(userFileEventSource.OwnedBy.Id, "33333"); | ||
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\":\"[email protected]\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"},\"owned_by\":{\"type\": \"user\",\"id\":\"33333\",\"name\": \"Test User\",\"login\":\"[email protected]\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"[email protected]\"},\"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<BoxEventCollection<BoxEnterpriseEvent>>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxEventCollection<BoxEnterpriseEvent>>>(new BoxResponse<BoxEventCollection<BoxEnterpriseEvent>>() | ||
{ | ||
Status = ResponseStatus.Success, | ||
ContentString = responseString | ||
})).Callback<IBoxRequest>(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, "[email protected]"); | ||
Assert.AreEqual(userFileEventSource.OwnedBy.Id, "33333"); | ||
Assert.AreEqual(userFileEventSource.OwnedBy.Name, "Test User"); | ||
} | ||
|
||
[TestMethod] | ||
|
@@ -113,6 +143,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\":\"[email protected]\",\"parent\":{\"type\":\"folder\",\"name\":\"AllFiles\",\"id\":\"0\"}},\"created_by\":{\"type\":\"user\",\"id\":\"11111\",\"name\":\"Test User\",\"login\":\"[email protected]\"},\"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<BoxEventCollection<BoxEnterpriseEvent>>(It.IsAny<IBoxRequest>())) | ||
.Returns(Task.FromResult<IBoxResponse<BoxEventCollection<BoxEnterpriseEvent>>>(new BoxResponse<BoxEventCollection<BoxEnterpriseEvent>>() | ||
{ | ||
Status = ResponseStatus.Success, | ||
ContentString = responseString | ||
})).Callback<IBoxRequest>(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, "[email protected]"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetGroupEventsFolder_ValidResponse() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\":\"[email protected]\"}}"; | ||
var sourceObject = _converter.Parse<BoxUserFileCollaborationEventSource>(sourceString); | ||
|
||
var serializedObjectString = _converter.Serialize(sourceObject); | ||
|
||
var boxUserFileCollaborationEventSource = _converter.Parse<BoxUserFileCollaborationEventSource>(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\":\"[email protected]\"}}"; | ||
var sourceObject = _converter.Parse<BoxUserFolderCollaborationEventSource>(sourceString); | ||
|
||
var serializedObjectString = _converter.Serialize(sourceObject); | ||
|
||
var boxUserFolderCollaborationEventSource = _converter.Parse<BoxUserFolderCollaborationEventSource>(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 + [email protected]\"}}"; | ||
var sourceObject = _converter.Parse<BoxGroupFolderCollaborationEventSource>(sourceString); | ||
|
||
var serializedObjectString = _converter.Serialize(sourceObject); | ||
|
||
var boxGroupFolderCollaborationEventSource = _converter.Parse<BoxGroupFolderCollaborationEventSource>(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\":\"[email protected]\"}}"; | ||
var sourceObject = _converter.Parse<BoxGroupFileCollaborationEventSource>(sourceString); | ||
|
||
var serializedObjectString = _converter.Serialize(sourceObject); | ||
|
||
var boxGroupFileCollaborationEventSource = _converter.Parse<BoxGroupFileCollaborationEventSource>(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<BoxGroupEventSource>(sourceString); | ||
|
||
var serializedObjectString = _converter.Serialize(sourceObject); | ||
|
||
var boxGroupEventSource = _converter.Parse<BoxGroupEventSource>(serializedObjectString); | ||
|
||
Assert.AreEqual(boxGroupEventSource.GetType(), typeof(BoxGroupEventSource)); | ||
Assert.AreEqual(boxGroupEventSource.Id, "182069272"); | ||
Assert.AreEqual(boxGroupEventSource.Name, "TestGroup"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.