public async Task AcquireInitializationLockAsync_Success()
        {
            string prefix = "prefix";
            string etag   = Guid.NewGuid().ToString();

            dynamic lockDocument = new { id = Guid.NewGuid().ToString() };

            ResponseMessage response = new ResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new CosmosJsonDotNetSerializer().ToStream(lockDocument)
            };

            Mock <Container> container = new Mock <Container>();

            container.Setup(c => c.CreateItemStreamAsync(
                                It.IsAny <Stream>(),
                                It.IsAny <PartitionKey>(),
                                It.IsAny <ItemRequestOptions>(),
                                It.IsAny <CancellationToken>())).ReturnsAsync(response);

            Mock <RequestOptionsFactory>    requestOptionsFactory           = new Mock <RequestOptionsFactory>();
            DocumentServiceLeaseStoreCosmos documentServiceLeaseStoreCosmos = new DocumentServiceLeaseStoreCosmos(
                container.Object,
                prefix,
                requestOptionsFactory.Object);

            Assert.IsTrue(await documentServiceLeaseStoreCosmos.AcquireInitializationLockAsync(TimeSpan.FromSeconds(1)));
        }
        public async Task AcquireInitializationLockAsync_OnFailure()
        {
            string           prefix    = "prefix";
            Mock <Container> container = new Mock <Container>();

            container.Setup(c => c.CreateItemStreamAsync(
                                It.IsAny <Stream>(),
                                It.IsAny <PartitionKey>(),
                                It.IsAny <ItemRequestOptions>(),
                                It.IsAny <CancellationToken>())).ReturnsAsync(new ResponseMessage(System.Net.HttpStatusCode.TooManyRequests));
            Mock <RequestOptionsFactory>    requestOptionsFactory           = new Mock <RequestOptionsFactory>();
            DocumentServiceLeaseStoreCosmos documentServiceLeaseStoreCosmos = new DocumentServiceLeaseStoreCosmos(
                container.Object,
                prefix,
                requestOptionsFactory.Object);

            await documentServiceLeaseStoreCosmos.AcquireInitializationLockAsync(TimeSpan.FromSeconds(1));
        }
        public async Task IsInitializedAsync_IfDoesNotExist()
        {
            string           prefix    = "prefix";
            Mock <Container> container = new Mock <Container>();

            container.Setup(c => c.ReadItemStreamAsync(
                                It.IsAny <string>(),
                                It.IsAny <PartitionKey>(),
                                It.IsAny <ItemRequestOptions>(),
                                It.IsAny <CancellationToken>())).ReturnsAsync(new ResponseMessage(System.Net.HttpStatusCode.NotFound));
            Mock <RequestOptionsFactory>    requestOptionsFactory           = new Mock <RequestOptionsFactory>();
            DocumentServiceLeaseStoreCosmos documentServiceLeaseStoreCosmos = new DocumentServiceLeaseStoreCosmos(
                container.Object,
                prefix,
                requestOptionsFactory.Object);

            Assert.IsFalse(await documentServiceLeaseStoreCosmos.IsInitializedAsync());
        }