public void TestSizesCompress() { var code = new SimpleAuthorizationCode { Client = new SimpleClient { ClientId = "cid" }, RequestedScopes = new List<SimpleScope> { new SimpleScope { Description = "this is description", Enabled = true, Name = "Scope", DisplayName = "Display Name" } }, Subject = new SimpleClaimsPrincipal { Identities = new List<SimpleClaimsIdentity> { new SimpleClaimsIdentity { Claims = new List<SimpleClaim>() } } }, CodeChallenge = "CodeChallenge", CodeChallengeMethod = "CodeChallengeMethod", CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)), IsOpenId = true, Nonce = "Nonce", RedirectUri = "RedirectUri", SessionId = "SessionId", WasConsentShown = true }; var jsonSettingsFactory = new JsonSettingsFactory(new CustomMappersConfiguration()).Create(); var serializeObject = JsonConvert.SerializeObject(code, jsonSettingsFactory); Console.WriteLine($"{Encoding.UTF8.GetByteCount(serializeObject.Compress())} bytes"); }
public void ToComplexEntity_WhenSimpleEntity_ExpectCorrectMap() { // Arrange var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<AuthorizationCode>>(); var mockClaimsPrincipalMapper = new Mock<IMapper<SimpleClaimsPrincipal, ClaimsPrincipal>>(); var mockClientMapper = new Mock<IMapper<SimpleClient, Client>>(); var mockScopeMapper = new Mock<IMapper<SimpleScope, Scope>>(); mockClaimsPrincipalMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleClaimsPrincipal>())) .Returns(new ClaimsPrincipal()); mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>())).Returns(new Dictionary<string, TypedSetter<AuthorizationCode>>()); mockClientMapper.Setup(r => r.ToComplexEntity(It.IsAny<SimpleClient>())).Returns(new Client()); mockScopeMapper.Setup(r => r.ToComplexEntity(It.IsAny<IEnumerable<SimpleScope>>())).Returns(new List<Scope> { new Scope() }); var authorizationCodeMappers = new AuthorizationCodeMappers<AuthorizationCode>( mockPropertyMapper.Object, mockClaimsPrincipalMapper.Object, mockClientMapper.Object, mockScopeMapper.Object); var simpleEntity = new SimpleAuthorizationCode { Client = new SimpleClient(), Subject = new SimpleClaimsPrincipal(), CreationTime = new DateTimeOffset(new DateTime(2016, 1, 1)), RedirectUri = "RedirectUri", Nonce = "Nonce", WasConsentShown = true, CodeChallengeMethod = "CodeChallengeMethod", IsOpenId = true, SessionId = "SessionId", CodeChallenge = "CodeChallenge", RequestedScopes = new List<SimpleScope>() }; // Act var stopwatch = Stopwatch.StartNew(); var complexEntity = authorizationCodeMappers.ToComplexEntity(simpleEntity); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(complexEntity, Is.Not.Null); Assert.That(complexEntity.Client, Is.Not.Null); Assert.That(complexEntity.Subject, Is.Not.Null); Assert.That(complexEntity.CreationTime, Is.EqualTo(new DateTimeOffset(new DateTime(2016, 1, 1)))); Assert.That(complexEntity.RedirectUri, Is.EqualTo("RedirectUri")); Assert.That(complexEntity.Nonce, Is.EqualTo("Nonce")); Assert.That(complexEntity.WasConsentShown, Is.True); Assert.That(complexEntity.CodeChallengeMethod, Is.EqualTo("CodeChallengeMethod")); Assert.That(complexEntity.IsOpenId, Is.True); Assert.That(complexEntity.SessionId, Is.EqualTo("SessionId")); Assert.That(complexEntity.CodeChallenge, Is.EqualTo("CodeChallenge")); Assert.That(complexEntity.RequestedScopes, Is.Not.Null); Assert.That(complexEntity.RequestedScopes.Any(), Is.True); }