Ejemplo n.º 1
0
        public void Should_Create_PersistedGrant()
        {
            const string key          = "key";
            const string type         = "type";
            var          subjectId    = Guid.NewGuid();
            var          clientId     = Guid.NewGuid();
            var          creationTime = DateTime.UtcNow;
            const string data         = "data";
            var          expiration   = DateTime.UtcNow.AddDays(1);

            var result = PersistedGrant.Builder()
                         .SetKey(key)
                         .SetType(type)
                         .SetSubjectId(subjectId)
                         .SetClientId(clientId)
                         .SetCreationTime(creationTime)
                         .SetData(data)
                         .SetExpiration(expiration)
                         .Build();

            result.Should().NotBeNull();
            result.Key.Should().Be(key);
            result.Type.Should().Be(type);
            result.SubjectId.Should().Be(subjectId);
            result.ClientId.Should().Be(clientId);
            result.CreationTime.Should().Be(creationTime);
            result.Data.Should().Be(data);
            result.Expiration.Should().Be(expiration);
        }
Ejemplo n.º 2
0
        public void Should_Throw_PersistedGrantSubjectIdNullException_When_SubjectId_Is_Empty_Guid()
        {
            Action result = () =>
            {
                var unused = PersistedGrant.Builder()
                             .SetKey("key")
                             .SetType("type")
                             .SetSubjectId(Guid.Empty)
                             .SetClientId(Guid.NewGuid())
                             .SetCreationTime(DateTime.UtcNow)
                             .SetData("data")
                             .SetExpiration(DateTime.UtcNow.AddDays(1))
                             .Build();
            };

            result.Should().ThrowExactly <PersistedGrantSubjectIdNullException>()
            .WithMessage("SubjectId argument is required.");
        }
Ejemplo n.º 3
0
        public void Should_Throw_PersistedGrantExpirationMinValueException_When_Expiration_Is_Earlier_Than_CreationTime()
        {
            Action result = () =>
            {
                var unused = PersistedGrant.Builder()
                             .SetKey("key")
                             .SetType("type")
                             .SetSubjectId(Guid.NewGuid())
                             .SetClientId(Guid.NewGuid())
                             .SetCreationTime(DateTime.UtcNow)
                             .SetData("data")
                             .SetExpiration(DateTime.UtcNow.AddDays(-1))
                             .Build();
            };

            result.Should().ThrowExactly <PersistedGrantExpirationMinValueException>()
            .WithMessage("Expiration argument cannot be earlier than CreationTime.");
        }