コード例 #1
0
    public void Properties_Map()
    {
        var model = new Client()
        {
            Properties =
            {
                { "foo1", "bar1" },
                { "foo2", "bar2" },
            }
        };


        var mappedEntity = model.ToEntity();

        mappedEntity.Properties.Count.Should().Be(2);
        var foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1");

        foo1.Should().NotBeNull();
        foo1.Value.Should().Be("bar1");
        var foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2");

        foo2.Should().NotBeNull();
        foo2.Value.Should().Be("bar2");



        var mappedModel = mappedEntity.ToModel();

        mappedModel.Properties.Count.Should().Be(2);
        mappedModel.Properties.ContainsKey("foo1").Should().BeTrue();
        mappedModel.Properties.ContainsKey("foo2").Should().BeTrue();
        mappedModel.Properties["foo1"].Should().Be("bar1");
        mappedModel.Properties["foo2"].Should().Be("bar2");
    }
コード例 #2
0
    public void Can_Map()
    {
        var model        = new Client();
        var mappedEntity = model.ToEntity();
        var mappedModel  = mappedEntity.ToModel();

        Assert.NotNull(mappedModel);
        Assert.NotNull(mappedEntity);
    }
コード例 #3
0
    public async Task CreateAsync(CreateClientModel model)
    {
        var client = new Duende.IdentityServer.Models.Client();

        client.ClientId   = model.ClientId.Trim();
        client.ClientName = model.Name?.Trim();

        if (model.Flow == Flow.ClientCredentials)
        {
            client.AllowedGrantTypes = GrantTypes.ClientCredentials;
        }
        else
        {
            client.AllowedGrantTypes = GrantTypes.Code;
        }

        _context.Clients.Add(client.ToEntity());
        await _context.SaveChangesAsync();
    }