public async Task TestMethod_SimpleItemDbContext_Insert() { var store = _fixture.GetService <ISimpleItemDbContext <ShortUrlCosmosDocument> >(); store.Should().NotBeNull(); var shortUrl = new ShortUrl { Expiration = DateTime.UtcNow.AddSeconds(2), Id = "1234", LongUrl = "https://www.google.com" }; var document = new ShortUrlCosmosDocument(shortUrl.ToShortUrlCosmosDocument()); var response = await store.UpsertItemAsync(document); response.StatusCode.Should().Be(HttpStatusCode.OK); var read = await store.GetItemAsync(document.Id); read.Should().NotBeNull(); read.Id.Should().Be(document.Id); // wait 2 seconds. Thread.Sleep(2000); read = await store.GetItemAsync(document.Id); read.Should().BeNull(); }
public async Task <(HttpStatusCode, ShortUrl)> UpsertShortUrlAsync(ShortUrl shortUrl) { Guard.ArgumentNotNull(nameof(shortUrl), shortUrl); Guard.ArgumentNotNullOrEmpty(nameof(shortUrl.LongUrl), shortUrl.LongUrl); Guard.ArgumentNotNull(nameof(shortUrl.Expiration), shortUrl.Expiration); if (string.IsNullOrWhiteSpace(shortUrl.Id)) { shortUrl.Id = _urlShortenerAlgorithm.GenerateUniqueId(); } var document = CreateDocument(shortUrl.ToShortUrlCosmosDocument()); // var document = new ShortUrlCosmosDocument(shortUrl.ToShortUrlCosmosDocument()); var response = await _simpleItemDbContext.UpsertItemAsync(document); return(response.StatusCode, shortUrl); }