OSDN Git Service

開発版のバージョン表記を変更
[opentween/open-tween.git] / OpenTween.Tests / MyCommonTest.cs
index 9a9fc5e..f84a724 100644 (file)
@@ -28,8 +28,9 @@ using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
 using System.Text;
 using System.Windows.Forms;
-using NSubstitute;
+using Moq;
 using OpenTween;
+using OpenTween.Models;
 using Xunit;
 using Xunit.Extensions;
 
@@ -121,27 +122,16 @@ namespace OpenTween
             Assert.Equal(expected, MyCommon.IsAnimatedGif(filename));
         }
 
-        public static IEnumerable<object[]> DateTimeParse_TestCase
+        public static TheoryData<string, DateTimeUtc> DateTimeParse_TestCase = new TheoryData<string, DateTimeUtc>
         {
-            get
-            {
-                yield return new object[] {
-                    "Sun Nov 25 06:10:00 +00:00 2012",
-                    new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc),
-                };
-                yield return new object[] {
-                    "Sun, 25 Nov 2012 06:10:00 +00:00",
-                    new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc),
-                };
-            }
-        }
+            { "Sun Nov 25 06:10:00 +00:00 2012", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
+            { "Sun, 25 Nov 2012 06:10:00 +00:00", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
+        };
 
         [Theory]
-        [PropertyData("DateTimeParse_TestCase")]
-        public void DateTimeParseTest(string date, DateTime excepted)
-        {
-            Assert.Equal(excepted, MyCommon.DateTimeParse(date).ToUniversalTime());
-        }
+        [MemberData(nameof(DateTimeParse_TestCase))]
+        public void DateTimeParseTest(string date, DateTimeUtc excepted)
+            => Assert.Equal(excepted, MyCommon.DateTimeParse(date));
 
         [DataContract]
         public struct JsonData
@@ -161,7 +151,7 @@ namespace OpenTween
         }
 
         [Theory]
-        [PropertyData("CreateDataFromJson_TestCase")]
+        [MemberData(nameof(CreateDataFromJson_TestCase))]
         public void CreateDataFromJsonTest<T>(string json, T expected)
         {
             Assert.Equal(expected, MyCommon.CreateDataFromJson<T>(json));
@@ -194,9 +184,9 @@ namespace OpenTween
         [Fact]
         public void GetAssemblyNameTest()
         {
-            var mockAssembly = Substitute.For<_Assembly>();
-            mockAssembly.GetName().Returns(new AssemblyName("OpenTween"));
-            MyCommon.EntryAssembly = mockAssembly;
+            var mockAssembly = new Mock<_Assembly>();
+            mockAssembly.Setup(m => m.GetName()).Returns(new AssemblyName("OpenTween"));
+            MyCommon.EntryAssembly = mockAssembly.Object;
 
             Assert.Equal("OpenTween", MyCommon.GetAssemblyName());
         }
@@ -212,12 +202,12 @@ namespace OpenTween
 
         [Theory]
         [InlineData("1.0.0.0", "1.0.0")]
-        [InlineData("1.0.0.1", "1.0.1-beta1")]
-        [InlineData("1.0.0.9", "1.0.1-beta9")]
+        [InlineData("1.0.0.1", "1.0.1-dev")]
+        [InlineData("1.0.0.12", "1.0.1-dev+build.12")]
         [InlineData("1.0.1.0", "1.0.1")]
-        [InlineData("1.0.9.1", "1.1.0-beta1")]
+        [InlineData("1.0.9.1", "1.0.10-dev")]
         [InlineData("1.1.0.0", "1.1.0")]
-        [InlineData("1.9.9.1", "2.0.0-beta1")]
+        [InlineData("1.9.9.1", "1.9.10-dev")]
         public void GetReadableVersionTest(string fileVersion, string expected)
         {
             Assert.Equal(expected, MyCommon.GetReadableVersion(fileVersion));
@@ -239,7 +229,7 @@ namespace OpenTween
         }
 
         [Theory]
-        [PropertyData("GetStatusUrlTest1_TestCase")]
+        [MemberData(nameof(GetStatusUrlTest1_TestCase))]
         public void GetStatusUrlTest1(PostClass post, string expected)
         {
             Assert.Equal(expected, MyCommon.GetStatusUrl(post));
@@ -258,20 +248,100 @@ namespace OpenTween
         {
             if (Environment.OSVersion.Platform == PlatformID.Win32NT)
             {
-                var mockAssembly = Substitute.For<_Assembly>();
-                mockAssembly.Location.Returns(@"C:\hogehoge\OpenTween\OpenTween.exe");
-                MyCommon.EntryAssembly = mockAssembly;
+                var mockAssembly = new Mock<_Assembly>();
+                mockAssembly.Setup(m => m.Location).Returns(@"C:\hogehoge\OpenTween\OpenTween.exe");
+                MyCommon.EntryAssembly = mockAssembly.Object;
 
                 Assert.Equal(@"C:\hogehoge\OpenTween\ErrorLogs", MyCommon.GetErrorLogPath());
             }
             else
             {
-                var mockAssembly = Substitute.For<_Assembly>();
-                mockAssembly.Location.Returns(@"/hogehoge/OpenTween/OpenTween.exe");
-                MyCommon.EntryAssembly = mockAssembly;
+                var mockAssembly = new Mock<_Assembly>();
+                mockAssembly.Setup(m => m.Location).Returns(@"/hogehoge/OpenTween/OpenTween.exe");
+                MyCommon.EntryAssembly = mockAssembly.Object;
 
                 Assert.Equal(@"/hogehoge/OpenTween/ErrorLogs", MyCommon.GetErrorLogPath());
             }
         }
+
+        [Fact]
+        public void CountUp_Test()
+        {
+            var actual = MyCommon.CountUp(from: 1, to: 5);
+
+            Assert.Equal(new[] { 1, 2, 3, 4, 5 }, actual);
+        }
+
+        [Fact]
+        public void CountUp_FromAndToAreEqualTest()
+        {
+            var actual = MyCommon.CountUp(from: 1, to: 1);
+
+            Assert.Equal(new[] { 1 }, actual);
+        }
+
+        [Fact]
+        public void CountUp_ToIsLessThanFromTest()
+        {
+            var actual = MyCommon.CountUp(from: 1, to: 0);
+
+            Assert.Empty(actual);
+        }
+
+        [Fact]
+        public void CountDown_Test()
+        {
+            var actual = MyCommon.CountDown(from: 5, to: 1);
+
+            Assert.Equal(new[] { 5, 4, 3, 2, 1 }, actual);
+        }
+
+        [Fact]
+        public void CountDown_FromAndToAreEqualTest()
+        {
+            var actual = MyCommon.CountDown(from: 5, to: 5);
+
+            Assert.Equal(new[] { 5 }, actual);
+        }
+
+        [Fact]
+        public void CountDown_ToIsGreaterThanFromTest()
+        {
+            var actual = MyCommon.CountDown(from: 5, to: 6);
+
+            Assert.Empty(actual);
+        }
+
+        [Fact]
+        public void CircularCountUp_Test()
+        {
+            var actual = MyCommon.CircularCountUp(length: 6, startIndex: 3);
+
+            Assert.Equal(new[] { 3, 4, 5, 0, 1, 2 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountUp_StartFromZeroTest()
+        {
+            var actual = MyCommon.CircularCountUp(length: 6, startIndex: 0);
+
+            Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountDown_Test()
+        {
+            var actual = MyCommon.CircularCountDown(length: 6, startIndex: 3);
+
+            Assert.Equal(new[] { 3, 2, 1, 0, 5, 4 }, actual);
+        }
+
+        [Fact]
+        public void CircularCountDown_StartFromLastIndexTest()
+        {
+            var actual = MyCommon.CircularCountDown(length: 6, startIndex: 5);
+
+            Assert.Equal(new[] { 5, 4, 3, 2, 1, 0 }, actual);
+        }
     }
 }