示例#1
0
        public async Task GenerateBewitAsync_WithDifferentPayload_ShouldGenerateDifferentBewit()
        {
            //Arrange
            var variableProvider = new MockHelper.MockedVariablesProvider();
            var tokenTuration    = TimeSpan.FromMinutes(1);
            var provider         =
                new BewitTokenGeneratorAccessor <Foo>(
                    tokenTuration,
                    MockHelper.GetMockedCrpytoService <Foo>(),
                    variableProvider);
            var payload = new Foo
            {
                Bar = 5
            };

            //Act
            Bewit <Foo> bewit =
                await provider.InvokeGenerateBewitAsync(payload,
                                                        CancellationToken.None);

            //Assert
            bewit.Nonce.Should().Be(variableProvider.NextToken.ToString());
            bewit.ExpirationDate.Should()
            .Be(variableProvider.UtcNow.AddTicks(tokenTuration.Ticks));
            bewit.Payload.Should().BeEquivalentTo(payload);
            bewit.Hash.Should()
            .Be("724e7acc-be57-49a1-8195-46a03c6271c6__2017-01-01T01:02:01.0010000Z__{\"Bar\":5}");
        }
示例#2
0
        public void GenerateBewitAsync_WithNullPayload_ShouldThrow()
        {
            //Arrange
            var variableProvider = new MockHelper.MockedVariablesProvider();
            ICryptographyService cryptoService =
                MockHelper.GetMockedCrpytoService <Foo>();
            var tokenTuration = TimeSpan.FromMinutes(1);
            var provider      = new BewitTokenGeneratorAccessor <Foo>(
                tokenTuration,
                cryptoService,
                variableProvider);

            //Act
            Func <Task> generateBewit = async() =>
                                        await provider.InvokeGenerateBewitAsync(null,
                                                                                CancellationToken.None);

            //Assert
            generateBewit.Should().Throw <ArgumentNullException>();
        }