Skip to content

Commit

Permalink
Merge pull request #360 from opentween/account-key-record
Browse files Browse the repository at this point in the history
AccountKeyをレコードとして定義
  • Loading branch information
upsilon authored Jun 10, 2024
2 parents e262c25 + 1f8101c commit 0b5c680
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 101 deletions.
33 changes: 17 additions & 16 deletions OpenTween.Tests/MediaSelectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Moq;
using OpenTween.SocialProtocol;
using OpenTween.SocialProtocol.Twitter;
using Xunit;

Expand All @@ -50,7 +51,7 @@ private void MyCommonSetup()
[Fact]
public void SelectedMediaServiceIndex_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);

Expand All @@ -67,7 +68,7 @@ public void SelectedMediaServiceIndex_Test()
[Fact]
public void SelectMediaService_TwitterTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -84,7 +85,7 @@ public void SelectMediaService_TwitterTest()
[Fact]
public void SelectMediaService_ImgurTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Imgur");
Expand All @@ -99,7 +100,7 @@ public void SelectMediaService_ImgurTest()
[Fact]
public void AddMediaItem_FilePath_SingleTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -123,7 +124,7 @@ public void AddMediaItem_FilePath_SingleTest()
[Fact]
public void AddMediaItem_MemoryImageTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -149,7 +150,7 @@ public void AddMediaItem_MemoryImageTest()
[Fact]
public void AddMediaItem_FilePath_MultipleTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -173,7 +174,7 @@ public void AddMediaItem_FilePath_MultipleTest()
[Fact]
public void ClearMediaItems_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -192,7 +193,7 @@ public void ClearMediaItems_Test()
[Fact]
public void DetachMediaItems_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -213,7 +214,7 @@ public void DetachMediaItems_Test()
[Fact]
public void SelectedMediaItemChange_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand Down Expand Up @@ -249,7 +250,7 @@ public void SelectedMediaItemChange_Test()
[Fact]
public void SelectedMediaItemChange_DisposeTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -271,7 +272,7 @@ public void SelectedMediaItemChange_DisposeTest()
[Fact]
public void SetSelectedMediaAltText_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -294,7 +295,7 @@ public void SetSelectedMediaAltText_Test()
[Fact]
public void Validate_PassTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -308,7 +309,7 @@ public void Validate_PassTest()
[Fact]
public void Validate_EmptyErrorTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -323,7 +324,7 @@ public void Validate_EmptyErrorTest()
[Fact]
public void Validate_ServiceNotSelectedErrorTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);

Expand All @@ -339,7 +340,7 @@ public void Validate_ServiceNotSelectedErrorTest()
[Fact]
public void Validate_ExtensionErrorTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand All @@ -360,7 +361,7 @@ public void Validate_ExtensionErrorTest()
[Fact]
public void Validate_FileSizeErrorTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
using var mediaSelector = new MediaSelector();
mediaSelector.InitializeServices(twAccount);
mediaSelector.SelectMediaService("Twitter");
Expand Down
27 changes: 14 additions & 13 deletions OpenTween.Tests/Models/TabInformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using OpenTween.SocialProtocol;
using Xunit;
using Xunit.Extensions;

Expand Down Expand Up @@ -1199,7 +1200,7 @@ public void ClearTabIds_NotAffectToOtherTabs_Test()
[Fact]
public void RefreshOwl_HomeTabTest()
{
var accountId = Guid.NewGuid();
var accountKey = AccountKey.New();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1212,15 +1213,15 @@ public void RefreshOwl_HomeTabTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);
this.tabinfo.RefreshOwl(accountKey, followerIds, isPrimary: true);

Assert.False(post.IsOwl);
}

[Fact]
public void RefreshOwl_InnerStoregeTabTest()
{
var accountId = Guid.NewGuid();
var accountKey = AccountKey.New();
var tab = new PublicSearchTabModel("search");
this.tabinfo.AddTab(tab);

Expand All @@ -1236,15 +1237,15 @@ public void RefreshOwl_InnerStoregeTabTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);
this.tabinfo.RefreshOwl(accountKey, followerIds, isPrimary: true);

Assert.False(post.IsOwl);
}

[Fact]
public void RefreshOwl_UnfollowedTest()
{
var accountId = Guid.NewGuid();
var accountKey = AccountKey.New();
var post = new PostClass
{
StatusId = new TwitterStatusId("100"),
Expand All @@ -1257,16 +1258,16 @@ public void RefreshOwl_UnfollowedTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("456") };
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: true);
this.tabinfo.RefreshOwl(accountKey, followerIds, isPrimary: true);

Assert.True(post.IsOwl);
}

[Fact]
public void RefreshOwl_SecondaryAccountTabTest()
{
var accountId = Guid.NewGuid();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountId);
var accountKey = AccountKey.New();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountKey);
this.tabinfo.AddTab(tab);

var post = new PostClass
Expand All @@ -1281,16 +1282,16 @@ public void RefreshOwl_SecondaryAccountTabTest()
this.tabinfo.SubmitUpdate();

var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(accountId, followerIds, isPrimary: false);
this.tabinfo.RefreshOwl(accountKey, followerIds, isPrimary: false);

Assert.True(post.IsOwl);
}

[Fact]
public void RefreshOwl_SecondaryAccountTab_AccountNotMatchedTest()
{
var accountId = Guid.NewGuid();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountId);
var accountKey = AccountKey.New();
var tab = new HomeSpecifiedAccountTabModel("secondary", accountKey);
this.tabinfo.AddTab(tab);

var post = new PostClass
Expand All @@ -1304,9 +1305,9 @@ public void RefreshOwl_SecondaryAccountTab_AccountNotMatchedTest()
this.tabinfo.DistributePosts();
this.tabinfo.SubmitUpdate();

var otherAccountId = Guid.NewGuid(); // 他アカウントの followerIds なので IsOwl は更新されない
var otherAccountKey = AccountKey.New(); // 他アカウントの followerIds なので IsOwl は更新されない
var followerIds = new HashSet<PersonId> { new TwitterUserId("123") };
this.tabinfo.RefreshOwl(otherAccountId, followerIds, isPrimary: false);
this.tabinfo.RefreshOwl(otherAccountKey, followerIds, isPrimary: false);

Assert.True(post.IsOwl);
}
Expand Down
18 changes: 9 additions & 9 deletions OpenTween.Tests/SocialProtocol/AccountCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public void GetAccountForTab_DefaultTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithoutAccountId = new PublicSearchTabModel("hoge");
var tabWithoutAccountKey = new PublicSearchTabModel("hoge");

// SourceAccountId が null のタブに対しては Primary のアカウントを返す
var actual = accounts.GetAccountForTab(tabWithoutAccountId);
// SourceAccountKey が null のタブに対しては Primary のアカウントを返す
var actual = accounts.GetAccountForTab(tabWithoutAccountKey);
Assert.IsType<TwitterAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-000000000000"), actual.UniqueKey);
}
Expand All @@ -215,10 +215,10 @@ public void GetAccountForTab_SpecifiedAccountTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithAccountId = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-111111111111"), new());
var tabWithAccountKey = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-111111111111"), new());

// SourceAccountId が設定されているタブに対しては対応するアカウントを返す
var actual = accounts.GetAccountForTab(tabWithAccountId);
// SourceAccountKey が設定されているタブに対しては対応するアカウントを返す
var actual = accounts.GetAccountForTab(tabWithAccountKey);
Assert.IsType<TwitterAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-111111111111"), actual.UniqueKey);
}
Expand All @@ -236,10 +236,10 @@ public void GetAccountForTab_NotExistsTest()
SelectedAccountKey = new("00000000-0000-4000-8000-000000000000"),
});

var tabWithAccountId = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-999999999999"), new());
var tabWithAccountKey = new RelatedPostsTabModel("hoge", new("00000000-0000-4000-8000-999999999999"), new());

// SourceAccountId に存在しない ID が設定されていた場合は InvalidAccount を返す
var actual = accounts.GetAccountForTab(tabWithAccountId);
// 存在しない AccountKey が設定されていた場合は InvalidAccount を返す
var actual = accounts.GetAccountForTab(tabWithAccountKey);
Assert.IsType<InvalidAccount>(actual);
Assert.Equal(new("00000000-0000-4000-8000-999999999999"), actual.UniqueKey);
}
Expand Down
5 changes: 2 additions & 3 deletions OpenTween.Tests/SocialProtocol/InvalidAccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using System;
using System.Threading.Tasks;
using OpenTween.Connection;
using Xunit;
Expand All @@ -31,7 +30,7 @@ public class InvalidAccountTest
[Fact]
public async Task Connection_Test()
{
using var account = new InvalidAccount(Guid.NewGuid());
using var account = new InvalidAccount(AccountKey.New());
var requeset = new GetRequest { RequestUri = new("https://example.com/aaa") };

await Assert.ThrowsAsync<WebApiException>(
Expand All @@ -42,7 +41,7 @@ await Assert.ThrowsAsync<WebApiException>(
[Fact]
public async Task Client_Test()
{
using var account = new InvalidAccount(Guid.NewGuid());
using var account = new InvalidAccount(AccountKey.New());

await Assert.ThrowsAsync<WebApiException>(
() => account.Client.VerifyCredentials()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CreateTweetFormatterTest
[InlineData("hoge https://twitter.com/twitterapi/status/22634515958", 276)]
public void GetTextLengthRemain_Test(string text, int expected)
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
var formatter = new CreateTweetFormatter(twAccount);

var postParams = new PostStatusParams(text);
Expand All @@ -45,7 +45,7 @@ public void GetTextLengthRemain_Test(string text, int expected)
[Fact]
public void CreateParams_SimpleTextTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
var formatter = new CreateTweetFormatter(twAccount);

var postParams = new PostStatusParams(Text: "hoge");
Expand All @@ -56,7 +56,7 @@ public void CreateParams_SimpleTextTest()
[Fact]
public void CreateParams_RemoveAutoPopuratedMentions_SingleTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());

var formatter = new CreateTweetFormatter(twAccount);
var inReplyToPost = new PostClass
Expand All @@ -79,7 +79,7 @@ public void CreateParams_RemoveAutoPopuratedMentions_SingleTest()
[Fact]
public void CreateParams_RemoveAutoPopuratedMentions_MultipleTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());

var formatter = new CreateTweetFormatter(twAccount);
var inReplyToPost = new PostClass
Expand All @@ -104,7 +104,7 @@ public void CreateParams_RemoveAutoPopuratedMentions_MultipleTest()
[Fact]
public void CreateParams_RemoveAutoPopuratedMentions_ExcludeTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());

var formatter = new CreateTweetFormatter(twAccount);
var inReplyToPost = new PostClass
Expand All @@ -129,7 +129,7 @@ public void CreateParams_RemoveAutoPopuratedMentions_ExcludeTest()
[Fact]
public void CreateParams_RemoveAttachmentUrl_Test()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
var formatter = new CreateTweetFormatter(twAccount);

// 引用ツイートの URL を Text から除去する
Expand All @@ -144,7 +144,7 @@ public void CreateParams_RemoveAttachmentUrl_Test()
[Fact]
public void CreateParams_RemoveAttachmentUrl_MultipleTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
var formatter = new CreateTweetFormatter(twAccount);

// attachment_url は複数指定できないため末尾の URL のみ Text から除去する
Expand All @@ -159,7 +159,7 @@ public void CreateParams_RemoveAttachmentUrl_MultipleTest()
[Fact]
public void CreateParams_RemoveAttachmentUrl_WithMediaTest()
{
using var twAccount = new TwitterAccount(Guid.NewGuid());
using var twAccount = new TwitterAccount(AccountKey.New());
var formatter = new CreateTweetFormatter(twAccount);

// 引用ツイートと画像添付は併用できないため attachment_url は使用しない(現在は許容されているかも?)
Expand Down
Loading

0 comments on commit 0b5c680

Please sign in to comment.