public void Should_retrieve_document_from_database()
        {
            var document = CreateDocument();
            IDocumentsRepository documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
            documentsRepository.Add(document);

            var documentfromDb = documentsRepository.Get(document.Id);

            documentfromDb.Id.Should().Be(document.Id);
        }
        public void Should_add_document_to_database()
        {
            var document = CreateDocument();
            IDocumentsRepository documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());

            var documentId = documentsRepository.Add(document);

            using (var db = new JsonEditorDb())
            {
                var documentFromDb = db.FirstOrDefault<Document>(new Sql("SELECT * FROM Documents WHERE Id = @documentId", new { documentId }));
                documentFromDb.Id.Should().Be(documentId);
            }
        }
        public void Should_retrieve_all_documents_from_database()
        {
            IDocumentsRepository documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());

            var document = CreateDocument();
            documentsRepository.Add(document);

            var document2 = CreateDocument();
            documentsRepository.Add(document2);

            var documents = documentsRepository.GetAll();

            documents.Count.Should().Be(2);
        }
        public async void Should_add_document_to_database()
        {
            var document = CreateDocument();

            using (var httpClient = GetHttpClient())
            {
                var response = await httpClient.PostAsJsonAsync(Smart.Format("api/documents/"), document);
                var contentString = await response.Content.ReadAsStringAsync();
                var documentId = await response.Content.ReadAsAsync<int>();

                documentId.Should().NotBe(0);

                var documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
                var documentfromDb = documentsRepository.Get(documentId);
                documentfromDb.Should().NotBeNull();
            }
        }
        public async void Should_retrieve_all_documents_from_database()
        {
            var documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());

            var document = CreateDocument();
            documentsRepository.Add(document);

            var document2 = CreateDocument();
            documentsRepository.Add(document2);

            using (var httpClient = GetHttpClient())
            {
                var response = await httpClient.GetAsync("api/documents/");
                var contentString = await response.Content.ReadAsStringAsync();
                var documents = await response.Content.ReadAsAsync<List<Document>>();
                response.StatusCode.Should().Be(HttpStatusCode.OK);

                documents.Count.Should().Be(2);
            }
        }
        public void Should_update_document_in_database()
        {
            var document = CreateDocument();
            IDocumentsRepository documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
            documentsRepository.Add(document);

            documentsRepository.Update(document);

            var documentfromDb = documentsRepository.Get(document.Id);
            documentfromDb.Name.Should().Be(document.Name);
        }
        public async void Should_retrieve_document_from_database()
        {
            var document = CreateDocument();
            var documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
            documentsRepository.Add(document);

            using (var httpClient = GetHttpClient())
            {
                var response = await httpClient.GetAsync(Smart.Format("api/documents/{documentId}", new { documentId = document.Id }));
                var contentString = await response.Content.ReadAsStringAsync();
                var retrievedDocument = await response.Content.ReadAsAsync<Document>();
                response.StatusCode.Should().Be(HttpStatusCode.OK);

                retrievedDocument.Id.Should().Be(document.Id);
            }
        }
        public async void Should_delete_document_from_database()
        {
            var document = CreateDocument();
            var documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
            documentsRepository.Add(document);

            using (var httpClient = GetHttpClient())
            {
                var response = await httpClient.DeleteAsync(Smart.Format("api/documents/{documentId}", new { documentId = document.Id }));
                response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            }

            var documentfromDb = documentsRepository.Get(document.Id);
            documentfromDb.Should().BeNull();
        }
        public async void Should_update_document_in_database()
        {
            var document = CreateDocument();
            document.Data = "test";
            var documentsRepository = new NPocoDocumentsRepository(new JsonEditorDb());
            documentsRepository.Add(document);
            document.Data = "test-data";

            using (var httpClient = GetHttpClient())
            {
                var response = await httpClient.PutAsJsonAsync(Smart.Format("api/documents/{documentId}", new { documentId = document.Id }), document);

                response.StatusCode.Should().Be(HttpStatusCode.NoContent);
            }

            var documentfromDb = documentsRepository.Get(document.Id);
            documentfromDb.Data.Should().Be(document.Data);
        }