Beispiel #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);
        }
Beispiel #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();
        }