public void ToModel_WhenModelHasClaimsMappings_ExpectClaimsMappingsMappedCorrectly()
        {
            var mappings = new List <WsFedClaimMap>
            {
                new WsFedClaimMap {
                    OriginalClaimType = "sub", NewClaimType = ClaimTypes.NameIdentifier
                },
                new WsFedClaimMap {
                    OriginalClaimType = "name", NewClaimType = ClaimTypes.Name
                }
            };

            var entity = new global::IdentityServer4.WsFederation.EntityFramework.Entities.RelyingParty {
                ClaimMapping = mappings
            };

            var model = entity.ToModel();

            model.ClaimMapping.Should().NotBeNull();
            model.ClaimMapping.Should().NotBeEmpty();
            model.ClaimMapping.Should().HaveCount(mappings.Count);

            foreach (var mappedMapping in model.ClaimMapping)
            {
                var matchingMapping = mappings.FirstOrDefault(x => x.OriginalClaimType == mappedMapping.Key);
                matchingMapping.Should().NotBeNull();
                mappedMapping.Value.Should().Be(matchingMapping.NewClaimType);
            }
        }
        public void ToModel_WhenModelHasEncryptionCertificate_ExpectCertificateMappedCorrectly()
        {
            var certToStore = new X509Certificate2("Resources/idsrv3test.cer");
            var entity      = new global::IdentityServer4.WsFederation.EntityFramework.Entities.RelyingParty
            {
                EncryptionCertificate = certToStore.GetRawCertData()
            };

            var model = entity.ToModel();

            model.EncryptionCertificate.Should().NotBeNull();

            model.EncryptionCertificate.Should().NotBeNull();
            model.EncryptionCertificate.Thumbprint.Should().Be(certToStore.Thumbprint);
            model.EncryptionCertificate.SubjectName.Name.Should().Be(certToStore.SubjectName.Name);
            model.EncryptionCertificate.HasPrivateKey.Should().Be(certToStore.HasPrivateKey);
        }
        public void ToModel_WhenPropertiesSet_ExpectValuesMapped()
        {
            var entity = new global::IdentityServer4.WsFederation.EntityFramework.Entities.RelyingParty
            {
                Realm                    = Guid.NewGuid().ToString(),
                TokenType                = Guid.NewGuid().ToString(),
                DigestAlgorithm          = Guid.NewGuid().ToString(),
                SignatureAlgorithm       = Guid.NewGuid().ToString(),
                SamlNameIdentifierFormat = Guid.NewGuid().ToString(),
            };

            var model = entity.ToModel();

            model.Should().NotBeNull();
            model.Realm.Should().Be(entity.Realm);
            model.TokenType.Should().Be(entity.TokenType);
            model.DigestAlgorithm.Should().Be(entity.DigestAlgorithm);
            model.SignatureAlgorithm.Should().Be(entity.SignatureAlgorithm);
            model.SamlNameIdentifierFormat.Should().Be(entity.SamlNameIdentifierFormat);

            model.EncryptionCertificate.Should().BeNull();
            model.ClaimMapping.Should().BeEmpty();
        }