private DocumentDto GetTestDocumentDtoFromContext(int id)
        {
            var dbTestContext = DbTestContext.GenerateContextWithData();
            var document      = dbTestContext.Documents
                                .Single(d => d.Id == id);

            return(_mapper.Map <DocumentDto>(document));
        }
        /// <summary>
        /// Returns AuthorDto with the specified ID from the test database.
        /// </summary>
        /// <param name="id">ID of the author.</param>
        /// <returns>Auhtor Dto.</returns>
        private AuthorDto GetTestAuthorFromDb(int id)
        {
            var dbTestContext = DbTestContext.GenerateContextWithData();
            var author        = dbTestContext.Authors
                                .Single(a => a.Id == id);

            return(_mapper.Map <AuthorDto>(author));
        }
        public async void GetDocumentsByProductVersion1_10_2EmptyPage()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocumentsByProductVersion(1, 10, 2);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void GetDocumentsFromSearch50_3NoDocumentsFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocumentsFromSearch("test", 50, 3);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void DeleteProductVersionWithIncorrectIdReturnsNotFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    var result = await controller.DeleteProductVersion(1, 999);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void GetClientCatalogWithIncorrectIdReturnsNotFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    var result = await controller.GetClientCatalog(99);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void DeleteDocumentTypeWithIncorrectIdReturnsNotFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentTypesController(context, _mapper))
                {
                    var result = await controller.DeleteDocumentType(99);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void GetDocumentWithIncorrectId()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocument(999);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void GetDocumentsFromSearchFuzzySearchNoDocumentsFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocumentsFromSearch("mihailo", 100, 1, false);

                    Assert.IsType <NotFoundResult>(result);
                }
        }
        public async void GetDocumentUpdatesBadModel()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    var result = await controller.GetDocumentUpdates(1);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostDocumentUpdateInexistantDocIdReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsController(context, _mapper))
                {
                    DocumentUpdateDto a101 = GetTestDocumentUpdateDto(999, 101);

                    var result = await controller.PostDocumentUpdate(999, a101);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void GetProductVersionModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");

                    var result = await controller.GetProductVersion(1, 1);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void DeleteDocumentTypeModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentTypesController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");

                    var result = await controller.DeleteDocumentType(1);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostMultipleProductVersionsCorrectDataCreatesProductVersions()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    IEnumerable <ProductVersionDto> ProductVersionList = Enumerable.Range(101, 10).Select(i => GetTestProductVersionDto(i));

                    var result = await controller.PostMultipleProductVersions(1, ProductVersionList);

                    Assert.NotNull(result);
                    Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostDocumentTypeCorrectDataCreatesDocumentType()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentTypesController(context, _mapper))
                {
                    DocumentTypeDto p11 = GetTestDocumentTypeDto(11);

                    var result = await controller.PostDocumentType(p11);

                    Assert.NotNull(result);
                    var resultValue = Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostMultipleClientCatalogsModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    IEnumerable <ClientCatalogDto> ClientCatalogList = Enumerable.Range(11, 10).Select(i => GetTestClientCatalogDto(i));

                    var result = await controller.PostMultipleClientCatalogs(ClientCatalogList);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostMultipleClientCatalogsCorrectDataCreatesClientCatalogs()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    IEnumerable <ClientCatalogDto> ClientCatalogList = Enumerable.Range(11, 10).Select(i => GetTestClientCatalogDto(i));

                    var result = await controller.PostMultipleClientCatalogs(ClientCatalogList);

                    Assert.NotNull(result);
                    Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostMultipleDocumentsCorrectDataCreatesDocuments()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsController(context, _mapper))
                {
                    List <DocumentDto> DocumentList = Enumerable.Range(101, 10).Select(i => GetTestDocumentDto(i)).ToList();

                    var result = await controller.PostDocuments(DocumentList);

                    Assert.NotNull(result);
                    Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostAuthorCorrectDataCreatesAuthor()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new AuthorsController(context, _mapper))
                {
                    AuthorDto a11 = GetTestAuthorDto(11);

                    var result = await controller.PostAuthor(a11);

                    Assert.NotNull(result);
                    var resultValue = Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostMultipleDocumentsModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    List <DocumentDto> DocumentList = Enumerable.Range(101, 10).Select(i => GetTestDocumentDto(i)).ToList();

                    var result = await controller.PostDocuments(DocumentList);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostProductVersionCorrectDataCreatesProductVersion()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    ProductVersionDto p11 = GetTestProductVersionDto(11, 9);

                    var result = await controller.PostProductVersion(1, p11);

                    Assert.NotNull(result);
                    var resultValue = Assert.IsType <CreatedAtActionResult>(result);
                }
        }
        public async void PostDocumentUpdateModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    DocumentUpdateDto a101 = GetTestDocumentUpdateDto(4, 101);

                    var result = await controller.PostDocumentUpdate(4, a101);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostClientCatalogModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    ClientCatalogDto p11 = GetTestClientCatalogDto(11);

                    var result = await controller.PostClientCatalog(p11);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void DeleteDocumentTypeIdDeletesDocumentType()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentTypesController(context, _mapper))
                {
                    var result = await controller.DeleteDocumentType(3);

                    DocumentTypeDto p3 = GetTestDocumentTypeDto(3);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.Equal(p3, resultValue);
                }
        }
        public async void DeleteProductVersionIdDeletesProductVersion()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    var result = await controller.DeleteProductVersion(1, 3);

                    ProductVersionDto p3 = GetTestProductVersionDto(3);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.Equal(p3, resultValue);
                }
        }
        public async void DeleteAuthorIdDeletesAuthor()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new AuthorsController(context, _mapper))
                {
                    var result = await controller.DeleteAuthor(3);

                    AuthorDto a3 = GetTestAuthorDto(3);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.Equal(a3, resultValue);
                }
        }
        public async void GetDocumentsFromSearchFuzzySearchReturnsMatches()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocumentsFromSearch("Document Test", 150, 1, false);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.IsAssignableFrom <IEnumerable <DocumentDtoInternal> >(resultValue);
                    Assert.NotEmpty((IEnumerable <DocumentDtoInternal>)resultValue);

                    IEnumerable <DocumentDtoInternal> resultValueList = (IEnumerable <DocumentDtoInternal>)resultValue;
                    Assert.True(resultValueList.Count().Equals(50));
                }
        }
        public async void GetDocumentUpdatesReturnsListOfUpdates()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsInternalController(context, _mapper))
                {
                    var result = await controller.GetDocumentUpdates(4);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.IsAssignableFrom <IEnumerable <DocumentUpdateDto> >(resultValue);
                    Assert.NotEmpty((IEnumerable <DocumentUpdateDto>)resultValue);

                    IEnumerable <DocumentUpdateDto> resultValueList = (IEnumerable <DocumentUpdateDto>)resultValue;
                    Assert.True(resultValueList.Count().Equals(10));
                }
        }
        public async void DeleteDocumentUpdateIdDeletesDocumentUpdate()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentsController(context, _mapper))
                {
                    DocumentUpdate dup = context.DocumentUpdates.AsNoTracking().Last();

                    var result = await controller.DeleteDocumentUpdate(dup.DocumentId, dup.Id);

                    DocumentUpdateDto a3 = _mapper.Map <DocumentUpdateDto>(dup);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.Equal(a3, resultValue);
                }
        }
        public async void GetDocumentTypeByIdReturnsSingleDocumentType()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new DocumentTypesController(context, _mapper))
                {
                    var result = await controller.GetDocumentType(3);

                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;

                    DocumentTypeDto p3 = GetTestDocumentTypeDto(3);

                    Assert.NotNull(resultValue);
                    Assert.IsType <DocumentTypeDto>(resultValue);
                    DocumentTypeDto p = (DocumentTypeDto)resultValue;
                    Assert.True(p.Equals(p3));
                    Assert.True(p.Equals(p3, true));
                }
        }