Пример #1
0
            private void ShouldReturnEntityType()
            {
                var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"));

                var type = document.Type;

                type.Should().Be("TestEntity");
            }
Пример #2
0
            private void ShouldReturnEntityTypeAndEntityId()
            {
                var document = EntityDocument <TestEntity> .Create("1", "TestEntity", new TestEntity("1"));

                var id = document.Id;

                id.Should().Be("TestEntity_1");
            }
Пример #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"));
            }
Пример #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);
            }
Пример #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));
        }