Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSerializeAndDeserialize() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSerializeAndDeserialize()
        {
            // Given
            UserSerialization serialization = new UserSerialization();

            IList <User> users = new IList <User> {
                (new User.Builder("Mike", LegacyCredential.ForPassword("1234321"))).withFlag("not_as_nice").build(), (new User.Builder("Steve", LegacyCredential.ForPassword("1234321"))).build(), (new User.Builder("steve.stevesson@WINDOMAIN", LegacyCredential.ForPassword("1234321"))).build(), (new User.Builder("Bob", LegacyCredential.ForPassword("0987654"))).build()
            };

            // When
            sbyte[] serialized = serialization.Serialize(users);

            // Then
            assertThat(serialization.DeserializeRecords(serialized), equalTo(users));
        }
Пример #2
0
        /// <summary>
        /// This is a future-proofing test. If you come here because you've made changes to the serialization format,
        /// this is your reminder to make sure to build this is in a backwards compatible way.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadV1SerializationFormat() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadV1SerializationFormat()
        {
            // Given
            UserSerialization serialization = new UserSerialization();

            sbyte[] salt1 = new sbyte[] { unchecked (( sbyte )0xa5), ( sbyte )0x43 };
            sbyte[] hash1 = new sbyte[] { unchecked (( sbyte )0xfe), ( sbyte )0x00, ( sbyte )0x56, unchecked (( sbyte )0xc3), ( sbyte )0x7e };
            sbyte[] salt2 = new sbyte[] { ( sbyte )0x34, unchecked (( sbyte )0xa4) };
            sbyte[] hash2 = new sbyte[] { ( sbyte )0x0e, ( sbyte )0x1f, unchecked (( sbyte )0xff), unchecked (( sbyte )0xc2), ( sbyte )0x3e };

            // When
            IList <User> deserialized = serialization.DeserializeRecords(UTF8.encode("Mike:SHA-256,FE0056C37E,A543:\n" + "Steve:SHA-256,FE0056C37E,A543:nice_guy,password_change_required\n" + "Bob:SHA-256,0E1FFFC23E,34A4:password_change_required\n"));

            // Then
            assertThat(deserialized, equalTo(asList((new User.Builder("Mike", new LegacyCredential(salt1, hash1))).build(), new User.Builder("Steve", new LegacyCredential(salt1, hash1))
                                                    .withRequiredPasswordChange(true).withFlag("nice_guy").build(), (new User.Builder("Bob", new LegacyCredential(salt2, hash2))).withRequiredPasswordChange(true).build())));
        }