private void ShouldReturnEntityType() { var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1")); var type = document.Type; type.Should().Be("TestEntity"); }
private void ShouldReturnEntityTypeAndEntityId() { var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1")); var id = document.Id; id.Should().Be("TestEntity_1"); }
private void ShouldReturnEntity() { var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1")); var entity = document.Entity; entity.Should().BeEquivalentTo(new TestEntity("1")); }
private void ShouldSerialiseAsJson() { var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1")); var serialised = JsonConvert.SerializeObject(document); JsonConvert.DeserializeObject <EntityDocument <TestEntity> >(serialised) .Should() .BeEquivalentTo(document); }
private void ShouldDeserialiseFromJson() { const string json = @"{""Entity"":{""Id"":""1""},""id"":""TestEntity_1"",""Type"":""TestEntity""}"; var document = JsonConvert.DeserializeObject <EntityDocument <TestEntity> >(json); document .Should() .BeEquivalentTo(EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"))); }
public async Task Put(T entity) { var id = _idSelector(entity); if (string.IsNullOrWhiteSpace(id)) { throw new NotSupportedException("An id must be specified to put."); } await _documentClient.UpsertDocumentAsync(GetUri(), EntityDocument <T> .Create(id, _entityType, entity)); }
public async Task <T> Read(string id) { try { var response = await _documentClient.ReadDocumentAsync(GetUri(id)); EntityDocument <T> responseDocument = (dynamic)response.Resource; return(responseDocument.Entity); } catch (DocumentClientException dce) when(dce.StatusCode == HttpStatusCode.NotFound) { return(default !);
private void ShouldReturnEntityTypeAndEntityId() { var id = EntityDocument <TestEntity> .CreateId("1", "TestEntity"); id.Should().Be("TestEntity_1"); }