1 // OpenTween - Client of Twitter
2 // Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
23 using System.Collections.Generic;
27 using System.Xml.Serialization;
29 using Xunit.Extensions;
31 namespace OpenTween.Models
34 /// FiltersClass -> PostFilterRule クラスへの変更で v1.1.2 までの
35 /// 設定ファイルと互換性が保たれているかどうかを確認するテスト
37 public class PostFilterRuleVersion113DeserializeTest
39 // OpenTween v1.1.2 時点の FiltersClass クラス
40 public sealed class FiltersClass
42 public string? NameFilter { get; set; }
43 public string? ExNameFilter { get; set; }
44 public string[] BodyFilterArray { get; set; } = Array.Empty<string>();
45 public string[] ExBodyFilterArray { get; set; } = Array.Empty<string>();
46 public bool SearchBoth { get; set; }
47 public bool ExSearchBoth { get; set; }
48 public bool MoveFrom { get; set; }
49 public bool SetMark { get; set; }
50 public bool SearchUrl { get; set; }
51 public bool ExSearchUrl { get; set; }
52 public bool CaseSensitive { get; set; }
53 public bool ExCaseSensitive { get; set; }
54 public bool UseLambda { get; set; }
55 public bool ExUseLambda { get; set; }
56 public bool UseRegex { get; set; }
57 public bool ExUseRegex { get; set; }
58 public bool IsRt { get; set; }
59 public bool IsExRt { get; set; }
60 public string? Source { get; set; }
61 public string? ExSource { get; set; }
65 public void DeserializeTest()
67 var oldVersion = new FiltersClass
70 ExNameFilter = "exname",
71 BodyFilterArray = new[] { "body1", "body2" },
72 ExBodyFilterArray = new[] { "exbody1", "exbody2" },
80 ExCaseSensitive = true,
88 ExSource = "exsource",
91 PostFilterRule newVersion;
93 using (var stream = new MemoryStream())
95 var oldSerializer = new XmlSerializer(typeof(FiltersClass));
96 oldSerializer.Serialize(stream, oldVersion);
98 stream.Seek(0, SeekOrigin.Begin);
100 var newSerializer = new XmlSerializer(typeof(PostFilterRule));
101 newVersion = (PostFilterRule)newSerializer.Deserialize(stream);
104 Assert.Equal(oldVersion.NameFilter, newVersion.FilterName);
105 Assert.Equal(oldVersion.ExNameFilter, newVersion.ExFilterName);
106 Assert.Equal(oldVersion.BodyFilterArray, newVersion.FilterBody);
107 Assert.Equal(oldVersion.ExBodyFilterArray, newVersion.ExFilterBody);
108 Assert.Equal(oldVersion.SearchBoth, newVersion.UseNameField);
109 Assert.Equal(oldVersion.ExSearchBoth, newVersion.ExUseNameField);
110 Assert.Equal(oldVersion.MoveFrom, newVersion.MoveMatches);
111 Assert.Equal(oldVersion.SetMark, newVersion.MarkMatches);
112 Assert.Equal(oldVersion.SearchUrl, newVersion.FilterByUrl);
113 Assert.Equal(oldVersion.ExSearchUrl, newVersion.ExFilterByUrl);
114 Assert.Equal(oldVersion.CaseSensitive, newVersion.CaseSensitive);
115 Assert.Equal(oldVersion.ExCaseSensitive, newVersion.ExCaseSensitive);
116 Assert.Equal(oldVersion.UseLambda, newVersion.UseLambda);
117 Assert.Equal(oldVersion.ExUseLambda, newVersion.ExUseLambda);
118 Assert.Equal(oldVersion.UseRegex, newVersion.UseRegex);
119 Assert.Equal(oldVersion.ExUseRegex, newVersion.ExUseRegex);
120 Assert.Equal(oldVersion.IsRt, newVersion.FilterRt);
121 Assert.Equal(oldVersion.IsExRt, newVersion.ExFilterRt);
122 Assert.Equal(oldVersion.Source, newVersion.FilterSource);
123 Assert.Equal(oldVersion.ExSource, newVersion.ExFilterSource);