Esempio n. 1
0
            private void ShouldReturnEntityType()
            {
                var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"));

                var type = document.Type;

                type.Should().Be("TestEntity");
            }
Esempio n. 2
0
            private void ShouldReturnEntityTypeAndEntityId()
            {
                var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"));

                var id = document.Id;

                id.Should().Be("TestEntity_1");
            }
Esempio n. 3
0
            private void ShouldReturnEntity()
            {
                var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"));

                var entity = document.Entity;

                entity.Should().BeEquivalentTo(new TestEntity("1"));
            }
Esempio n. 4
0
            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);
            }
Esempio n. 5
0
            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 !);
Esempio n. 8
0
            private void ShouldReturnEntityTypeAndEntityId()
            {
                var id = EntityDocument <TestEntity> .CreateId("1", "TestEntity");

                id.Should().Be("TestEntity_1");
            }