Skip to content
Merged
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
49 changes: 49 additions & 0 deletions SlackNet.Tests/Objects/FileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using EasyAssertions;
using Newtonsoft.Json;
using NUnit.Framework;

namespace SlackNet.Tests.Objects;

public class FileTests
{
private JsonSerializerSettings _sut;

[SetUp]
public void SetUp()
{
_sut = Default.JsonSettings(Default.SlackTypeResolver(Default.AssembliesContainingSlackTypes)).SerializerSettings;
}

[Test]
public void File_FromSharedChannel_HasUserTeamAndSourceTeam()
{
var result = Deserialize<File>(@"{ ""id"": ""F12345678"", ""user"": ""U12345678"", ""user_team"": ""T111"", ""source_team"": ""T222"" }");

result.UserTeam.ShouldBe("T111");
result.SourceTeam.ShouldBe("T222");
}

[Test]
public void File_WithShareAndMediaFields_HasThem()
{
var result = Deserialize<File>(@"{ ""id"": ""F12345678"", ""media_display_type"": ""unknown"", ""display_as_bot"": true, ""has_more_shares"": true }");

result.MediaDisplayType.ShouldBe("unknown");
result.DisplayAsBot.ShouldBe(true);
result.HasMoreShares.ShouldBe(true);
}

[Test]
public void File_WithoutThoseFields_HasDefaults()
{
var result = Deserialize<File>(@"{ ""id"": ""F12345678"" }");

result.UserTeam.ShouldBeNull();
result.SourceTeam.ShouldBeNull();
result.MediaDisplayType.ShouldBeNull();
result.DisplayAsBot.ShouldBe(false);
result.HasMoreShares.ShouldBe(false);
}

private T Deserialize<T>(string json) => JsonConvert.DeserializeObject<T>(json, _sut);
}
9 changes: 9 additions & 0 deletions SlackNet/Objects/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ public class File
public string Mimetype { get; set; }
public string Filetype { get; set; }
public string PrettyType { get; set; }
/// <summary>How the media should be displayed.</summary>
public string MediaDisplayType { get; set; }
public string User { get; set; }
/// <summary>Team of the user who created the file.</summary>
public string UserTeam { get; set; }
/// <summary>Team where the file originated.</summary>
public string SourceTeam { get; set; }
public string Mode { get; set; }
public bool Editable { get; set; }
public bool IsExternal { get; set; }
public string ExternalType { get; set; }
public string Username { get; set; }
public bool DisplayAsBot { get; set; }
public int Size { get; set; }
public string UrlPrivate { get; set; }
public string UrlPrivateDownload { get; set; }
Expand Down Expand Up @@ -50,6 +57,8 @@ public class File
public bool IsStarred { get; set; }
public string[] PinnedTo { get; set; }
public bool SkippedShares { get; set; }
/// <summary>Whether there are additional shares not returned.</summary>
public bool HasMoreShares { get; set; }
public FileShares Shares { get; set; }
public IList<string> TeamsSharedWith { get; set; }
public bool IsRestrictedSharingEnabled { get; set; }
Expand Down
Loading