ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [07/17] ignite git commit: IGNITE-5191 .NET: BinaryEnum.ToString
Date Wed, 17 May 2017 10:32:46 GMT
IGNITE-5191 .NET: BinaryEnum.ToString


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/256a4a3a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/256a4a3a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/256a4a3a

Branch: refs/heads/ignite-5075
Commit: 256a4a3abd4683c86343a6ba9674b4612d7801de
Parents: be012d8
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Tue May 16 15:35:07 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Tue May 16 15:35:07 2017 +0300

----------------------------------------------------------------------
 .../Binary/BinaryBuilderSelfTest.cs             | 21 ++++++++++++++++---
 .../Binary/EnumsTest.cs                         |  2 ++
 .../Impl/Binary/BinaryEnum.cs                   | 22 +++++++++++++-------
 3 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/256a4a3a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
index 951f5d2..a7794c6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
@@ -1645,17 +1645,22 @@ namespace Apache.Ignite.Core.Tests.Binary
             Assert.AreEqual(new[] {"val", "valArr"}, decimalMeta.Fields);
         }
 
+        /// <summary>
+        /// Tests the enum builder.
+        /// </summary>
         [Test]
         public void TestBuildEnum()
         {
             var binary = _grid.GetBinary();
 
-            int val = (int) TestEnumRegistered.Two;
+            int val = (int)TestEnumRegistered.Two;
+            var typeName = GetTypeName(typeof(TestEnumRegistered));
+            var typeId = BinaryUtils.GetStringHashCode(typeName);
 
             var binEnums = new[]
             {
                 binary.BuildEnum(typeof (TestEnumRegistered), val),
-                binary.BuildEnum(GetTypeName(typeof (TestEnumRegistered)), val)
+                binary.BuildEnum(typeName, val)
             };
 
             foreach (var binEnum in binEnums)
@@ -1664,11 +1669,21 @@ namespace Apache.Ignite.Core.Tests.Binary
 
                 Assert.AreEqual(val, binEnum.EnumValue);
 
-                Assert.AreEqual((TestEnumRegistered) val, binEnum.Deserialize<TestEnumRegistered>());
+                Assert.AreEqual(string.Format("{0} [typeId={1}, enumValue={2}, enumValueName={3}]",
+                    typeName, typeId, val, (TestEnumRegistered) val), binEnum.ToString());
+
+                Assert.AreEqual((TestEnumRegistered)val, binEnum.Deserialize<TestEnumRegistered>());
             }
 
             Assert.AreEqual(binEnums[0], binEnums[1]);
             Assert.AreEqual(binEnums[0].GetHashCode(), binEnums[1].GetHashCode());
+            
+            Assert.IsFalse(binEnums[0].Equals(null));
+            Assert.IsFalse(binEnums[0].Equals(new object()));
+            Assert.IsTrue(binEnums[0].Equals(binEnums[1]));
+
+            var ex = Assert.Throws<NotSupportedException>(() => binEnums[1].ToBuilder());
+            Assert.AreEqual("Builder cannot be created for enum.", ex.Message);
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/256a4a3a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/EnumsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/EnumsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/EnumsTest.cs
index f896ef4..ab54f16 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/EnumsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/EnumsTest.cs
@@ -76,6 +76,8 @@ namespace Apache.Ignite.Core.Tests.Binary
             if (isBinaryEnum)
             {
                 Assert.AreEqual(TypeCaster<int>.Cast(val), binRes.EnumValue);
+                Assert.AreEqual(string.Format("BinaryEnum [typeId={0}, enumValue={1}]",
+                    BinaryUtils.GetStringHashCode(typeof(T).FullName), binRes.EnumValue),
binRes.ToString());
             }
             else
             {

http://git-wip-us.apache.org/repos/asf/ignite/blob/256a4a3a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryEnum.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryEnum.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryEnum.cs
index 50b2eb8..710cf17 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryEnum.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryEnum.cs
@@ -20,6 +20,7 @@ namespace Apache.Ignite.Core.Impl.Binary
     using System;
     using System.Diagnostics;
     using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Impl.Binary.Metadata;
 
     /// <summary>
     /// Represents a typed enum in binary form.
@@ -89,7 +90,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /** <inheritdoc /> */
         public IBinaryObjectBuilder ToBuilder()
         {
-            return _marsh.Ignite.GetBinary().GetBuilder(this);
+            throw new NotSupportedException("Builder cannot be created for enum.");
         }
 
         /** <inheritdoc /> */
@@ -126,15 +127,20 @@ namespace Apache.Ignite.Core.Impl.Binary
         }
 
         /** <inheritdoc /> */
-        public static bool operator ==(BinaryEnum left, BinaryEnum right)
+        public override string ToString()
         {
-            return Equals(left, right);
-        }
+            var meta = GetBinaryType();
 
-        /** <inheritdoc /> */
-        public static bool operator !=(BinaryEnum left, BinaryEnum right)
-        {
-            return !Equals(left, right);
+            if (meta == null || meta == BinaryType.Empty)
+            {
+                return string.Format("BinaryEnum [typeId={0}, enumValue={1}]", _typeId, _enumValue);
+            }
+
+            var desc = _marsh.GetDescriptor(true, _typeId);
+            var enumValueName = desc != null && desc.Type != null ? Enum.GetName(desc.Type,
_enumValue) : null;
+
+            return string.Format("{0} [typeId={1}, enumValue={2}, enumValueName={3}]",
+                meta.TypeName, _typeId, _enumValue, enumValueName);
         }
     }
 }


Mime
View raw message