コード例 #1
0
        public async Task FindOneAndDeleteAsync_WithExistingNonceDerivate_ShouldRetrieveAndDeleteNonce()
        {
            //Arrange
            IMongoDatabase           database       = _mongoResource.CreateDatabase();
            var                      repository     = new MongoNonceRepository(database, new MongoNonceOptions());
            var                      token          = "myToken";
            DateTime                 expirationDate = DateTime.UtcNow;
            var                      nonce          = new Bewit <Bar>(token, expirationDate, new Bar(), "hash");
            IMongoCollection <Token> collection     = database.GetCollection <Token>(nameof(Token));
            await collection.InsertOneAsync(
                nonce, new InsertOneOptions(), CancellationToken.None);

            //Act
            Token returnedNonce =
                await repository.TakeOneAsync(token,
                                              CancellationToken.None);

            //Assert
            var items = (
                await collection.FindAsync(
                    Builders <Token> .Filter.Empty,
                    cancellationToken: CancellationToken.None)
                ).ToList();

            items.Should().BeEmpty();
            returnedNonce.Nonce.Should().Be(token);
            returnedNonce.ExpirationDate.Date.Should().Be(expirationDate.Date);
        }
コード例 #2
0
        public async Task FindOneAndDeleteAsync_WithNonExistingNonceDerivate_ShouldRetrieveAndDeleteNonce()
        {
            //Arrange
            IMongoDatabase database   = _mongoResource.CreateDatabase();
            var            repository = new MongoNonceRepository(database, new MongoNonceOptions());
            var            token      = "myToken";

            //Act
            Token returnedNonce =
                await repository.TakeOneAsync(token,
                                              CancellationToken.None);

            //Assert
            IMongoCollection <Token> collection = database.GetCollection <Token>(nameof(Token));
            var items = (
                await collection.FindAsync(
                    Builders <Token> .Filter.Empty,
                    cancellationToken: CancellationToken.None)
                ).ToList();

            items.Should().BeEmpty();
            returnedNonce.Should().BeNull();
        }
コード例 #3
0
        public async Task InsertOneAsync_WithNonceDerivate_ShouldStoreNonce()
        {
            //Arrange
            IMongoDatabase database       = _mongoResource.CreateDatabase();
            var            repository     = new MongoNonceRepository(database, new MongoNonceOptions());
            var            token          = "myToken";
            DateTime       expirationDate = DateTime.UtcNow;
            var            nonce          = new Bewit <Bar2 <int, string> >(token, expirationDate, new Bar2 <int, string>(), "hash");

            //Act
            await repository.InsertOneAsync(nonce, CancellationToken.None);

            //Assert
            IMongoCollection <Bewit <Bar2 <int, string> > > collection = database.GetCollection <Bewit <Bar2 <int, string> > >(nameof(Token));
            var items = (
                await collection.FindAsync(
                    Builders <Bewit <Bar2 <int, string> > > .Filter.Empty,
                    cancellationToken: CancellationToken.None)
                ).ToList();

            items.Should().ContainSingle();
            items.First().Nonce.Should().Be(token);
            items.First().ExpirationDate.Date.Should().Be(expirationDate.Date);
        }
コード例 #4
0
 static NonceRepositoryTests()
 {
     MongoNonceRepository.Initialize();
 }