예제 #1
0
        public void SerializeDeserializeInputChecks()
        {
            var record = new AuthenticationRecord(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            Assert.Throws <ArgumentNullException>(() => record.Serialize(null));
            Assert.ThrowsAsync <ArgumentNullException>(async() => await record.SerializeAsync(null));
            Assert.Throws <ArgumentNullException>(() => AuthenticationRecord.Deserialize(null));
            Assert.ThrowsAsync <ArgumentNullException>(async() => await AuthenticationRecord.DeserializeAsync(null));
        }
        public void DeserializeThrowsWithNonCurrentVersion()
        {
            var version         = "2.0";
            var jsonWithVersion = $"{{\"username\":\"2012c4ff-e82f-40de-ab6e-0afa51a1700d\",\"authority\":\"f5313742-e9ea-49fe-8864-910911375241\",\"homeAccountId\":\"309958ce-97c3-4c0e-8047-ba3931aef15f\",\"tenantId\":\"5d083b4e-4d2e-431c-adb7-fec97397a359\",\"clientId\":\"387f4ada-ea9b-4773-b5c3-ea5f54991738\",\"version\":\"{version}\"}}";

            var buff   = Encoding.UTF8.GetBytes(jsonWithVersion);
            var stream = new MemoryStream(buff, 0, buff.Length);

            Assert.Throws <InvalidOperationException>(() => AuthenticationRecord.Deserialize(stream));
        }
        public void DeserializesWithoutVersion()
        {
            var jsonWithoutVersion = "{\"username\":\"2012c4ff-e82f-40de-ab6e-0afa51a1700d\",\"authority\":\"f5313742-e9ea-49fe-8864-910911375241\",\"homeAccountId\":\"309958ce-97c3-4c0e-8047-ba3931aef15f\",\"tenantId\":\"5d083b4e-4d2e-431c-adb7-fec97397a359\",\"clientId\":\"387f4ada-ea9b-4773-b5c3-ea5f54991738\"}";

            var buff   = Encoding.UTF8.GetBytes(jsonWithoutVersion);
            var stream = new MemoryStream(buff, 0, buff.Length);

            var actRecord = AuthenticationRecord.Deserialize(stream);

            Assert.AreEqual(actRecord.Version, AuthenticationRecord.CurrentVersion);
        }
        public void SerializeDeserialize()
        {
            var expRecord = new AuthenticationRecord(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            byte[] buff = new byte[TestBufferSize];

            var stream = new MemoryStream(buff);

            expRecord.Serialize(stream);

            stream = new MemoryStream(buff, 0, (int)stream.Position);

            var actRecord = AuthenticationRecord.Deserialize(stream);

            Assert.AreEqual(expRecord.Username, actRecord.Username);
            Assert.AreEqual(expRecord.Authority, actRecord.Authority);
            Assert.AreEqual(expRecord.HomeAccountId, actRecord.HomeAccountId);
            Assert.AreEqual(expRecord.TenantId, actRecord.TenantId);
        }