private static Scope Version1(BsonDocument doc)
 {
     var scope = new Scope
     {
         Name = doc["_id"].AsString,
         DisplayName = doc.GetValueOrDefault("displayName", Default.DisplayName),
         Claims = new List<ScopeClaim>(
             doc.GetValueOrDefault(
                 "claims",
                 claimDoc =>
                 {
                     var claim = new ScopeClaim();
                     claim.Name = claimDoc.GetValueOrDefault("name", claim.Name);
                     claim.AlwaysIncludeInIdToken = claimDoc.GetValueOrDefault("alwaysIncludeInIdToken",
                         claim.AlwaysIncludeInIdToken);
                     claim.Description = claimDoc.GetValueOrDefault("description", claim.Description);
                     return claim;
                 },
                 new ScopeClaim[] { }
                 )),
     };
     scope.ClaimsRule = doc.GetValueOrDefault("claimsRule", scope.ClaimsRule);
     scope.Description = doc.GetValueOrDefault("description", scope.Description);
     scope.Emphasize = doc.GetValueOrDefault("emphasize", scope.Emphasize);
     scope.Enabled = doc.GetValueOrDefault("enabled", scope.Enabled);
     scope.IncludeAllClaimsForUser = doc.GetValueOrDefault("includeAllClaimsForUser",
         scope.IncludeAllClaimsForUser);
     scope.Required = doc.GetValueOrDefault("required", scope.Required);
     scope.ShowInDiscoveryDocument = doc.GetValueOrDefault("showInDiscoveryDocument",
         scope.ShowInDiscoveryDocument);
     scope.Type = doc.GetValueOrDefault("type", scope.Type);
     return scope;
 }
        public void ToComplexEntity_WhenSimpleEntity_ExpectMapSuccess()
        {
            // Arrange
            var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<Scope>>();

            mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>()))
                .Returns(new Dictionary<string, TypedSetter<Scope>>());

            var scopeMappers = new ScopeMappers<Scope>(mockPropertyMapper.Object);

            var scopeClaim = new ScopeClaim("Name", true) { Description = "Description" };
            var secret = new Secret("Value", "Description", new DateTimeOffset(new DateTime(2016, 1, 1))) { Type = "Type" };

            var simpleScope = new SimpleScope
            {
                Claims = new List<ScopeClaim> { scopeClaim },
                Type = ScopeType.Identity,
                Enabled = true,
                AllowUnrestrictedIntrospection = true,
                ScopeSecrets = new List<Secret> { secret },
                DisplayName = "DisplayName",
                Emphasize = true,
                ClaimsRule = "ClaimsRule",
                IncludeAllClaimsForUser = true,
                Name = "Name",
                Required = true,
                ShowInDiscoveryDocument = true,
                Description = "Description"
            };

            // Act
            var stopwatch = Stopwatch.StartNew();
            var complexEntity = scopeMappers.ToComplexEntity(simpleScope);
            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(complexEntity, Is.Not.Null);

            Assert.That(complexEntity.Claims, Is.Not.Null);
            Assert.That(complexEntity.Claims.Count, Is.EqualTo(1));

            Assert.That(complexEntity.Type, Is.EqualTo(ScopeType.Identity));
            Assert.That(complexEntity.Enabled, Is.True);
            Assert.That(complexEntity.AllowUnrestrictedIntrospection, Is.True);

            Assert.That(complexEntity.ScopeSecrets, Is.Not.Null);
            Assert.That(complexEntity.ScopeSecrets.Count, Is.EqualTo(1));

            Assert.That(complexEntity.DisplayName, Is.EqualTo("DisplayName"));
            Assert.That(complexEntity.Emphasize, Is.True);
            Assert.That(complexEntity.ClaimsRule, Is.EqualTo("ClaimsRule"));
            Assert.That(complexEntity.IncludeAllClaimsForUser, Is.True);
            Assert.That(complexEntity.Name, Is.EqualTo("Name"));
            Assert.That(complexEntity.Required, Is.True);
            Assert.That(complexEntity.ShowInDiscoveryDocument, Is.True);
            Assert.That(complexEntity.Description, Is.EqualTo("Description"));
        }
 internal static StoredScopeClaim ToDbFormat(ScopeClaim scopeClaim)
 {
     return new StoredScopeClaim
     {
         Name = scopeClaim.Name,
         AlwaysIncludeInIdToken = scopeClaim.AlwaysIncludeInIdToken,
         Description = scopeClaim.Description
     };
 }