Beispiel #1
0
        public void InsertDocuments()
        {
            //Arrange
            var                 documentScanEngine = new DocumentScanEngine();
            const int           ID_ArchiveBooking1 = 84;
            const string        DocumentPath1      = "novo";
            const int           ID_ArchiveBooking2 = 70;
            const string        DocumentPath2      = "novo";
            const int           ID_ArchiveBooking3 = 98;
            const string        DocumentPath3      = "novo";
            List <DocumentScan> documents          = new List <DocumentScan>();
            List <DocumentScan> result             = new List <DocumentScan>();

            //Act
            DocumentScan document1 = new DocumentScan(100, ID_ArchiveBooking1, DocumentPath1);
            DocumentScan document2 = new DocumentScan(101, ID_ArchiveBooking2, DocumentPath2);
            DocumentScan document3 = new DocumentScan(102, ID_ArchiveBooking3, DocumentPath3);

            documents.Add(document1);
            documents.Add(document2);
            documents.Add(document3);

            documentScanEngine.InsertDocuments(documents);

            result = documentScanEngine.GetDocumentsByArchiveBooking(70);

            //Assert
            foreach (DocumentScan document in result)
            {
                Assert.Equal("novo", document.DocumentPath);
            }
        }
        public List <DocumentScan> GetDocumentsByArchiveBooking(int id)
        {
            if (id == 0)
            {
                throw new IndexOutOfRangeException("No such document.");
            }

            List <DocumentScan> result = new List <DocumentScan>();

            using (connection = new SqlConnection(connectionString))
            {
                connection.Open();

                string sql = "SELECT * FROM DocumentScan WHERE ID_ArchiveBooking = @id";
                command = new SqlCommand(sql, connection);
                command.Parameters.AddWithValue("@id", id);

                using (reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        DocumentScan document = new DocumentScan(reader.GetInt32("ID_DocumentScan"), reader.GetInt32("ID_ArchiveBooking"), reader.GetString("DocumentPath"));

                        result.Add(document);
                    }
                }
                reader.Close();
                command.Dispose();
                connection.Close();
            }

            return(result);
        }
        public void UpdateDocumentScanByID(int id, DocumentScan document)
        {
            if (id == 0)
            {
                throw new IndexOutOfRangeException("No such document.");
            }

            if (document == null)
            {
                throw new IndexOutOfRangeException("Empty document.");
            }

            using (connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (adapter = new SqlDataAdapter())
                {
                    string sql = "UPDATE DocumentScan SET ID_ArchiveBooking = @archiveId, DocumentPath = @path WHERE ID_DocumentScan = @id";

                    command = new SqlCommand(sql, connection);
                    command.Parameters.AddWithValue("@archiveId", document.ID_ArchiveBooking);
                    command.Parameters.AddWithValue("@path", document.DocumentPath);
                    command.Parameters.AddWithValue("@id", id);
                    adapter.UpdateCommand = command;
                    adapter.UpdateCommand.ExecuteNonQuery();
                }
                command.Dispose();
                connection.Close();
            }
        }
        public List <DocumentScan> GetDocuments()
        {
            List <DocumentScan> result = new List <DocumentScan>();

            using (connection = new SqlConnection(connectionString))
            {
                connection.Open();

                string sql = "SELECT * FROM DocumentScan";
                command = new SqlCommand(sql, connection);

                using (reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        DocumentScan document = new DocumentScan(reader.GetInt32("ID_DocumentScan"), reader.GetInt32("ID_ArchiveBooking"), reader.GetString("DocumentPath"));

                        result.Add(document);
                    }
                }
                reader.Close();
                command.Dispose();
                connection.Close();
            }

            return(result);
        }
Beispiel #5
0
        public void DeleteDocumentById()
        {
            //Arrange
            var documentScanEngine = new DocumentScanEngine();

            //Act
            documentScanEngine.DeleteDocumentById(12);
            DocumentScan document = documentScanEngine.GetDocumentByID(12);

            //Assert
            Assert.Null(document.DocumentPath);
        }
Beispiel #6
0
        public void GetDocumentByID()
        {
            //Arrange
            var documentScanEngine = new DocumentScanEngine();

            //Act
            DocumentScan document = documentScanEngine.GetDocumentByID(28);

            //Assert
            Assert.Equal(70, document.ID_ArchiveBooking);
            Assert.Equal("novo", document.DocumentPath);
        }
Beispiel #7
0
        public async Task IndexScannedDocument(string fileName, string content)
        {
            DocumentScan scan = new DocumentScan
            {
                Id       = Guid.NewGuid().ToString(),
                FileName = fileName,
                Content  = content,
                ScanDate = DateTime.Now,
            };

            await _client.IndexAsync(scan, idx => idx.Index(_indexName));
        }
Beispiel #8
0
        public void DeleteDocumentByArchiveBooking()
        {
            //Arrange
            var documentScanEngine = new DocumentScanEngine();

            //Act
            documentScanEngine.DeleteDocumentByArchiveBooking(69);
            DocumentScan document = documentScanEngine.GetDocumentByID(11);

            //Assert
            Assert.Null(document.DocumentPath);
        }
        public void InsertDocument(DocumentScan document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("Empty document.");
            }

            document.ID_DocumentScan = null;

            context.DocumentScans.Add(document);
            context.SaveChanges();
        }
Beispiel #10
0
        public void UpdateDocumentByID()
        {
            //Arrange
            var          documentScanEngine = new DocumentScanEngine();
            const int    ID_ArchiveBooking  = 70;
            const string DocumentPath       = "updated";

            //Act
            DocumentScan document = new DocumentScan(100, ID_ArchiveBooking, DocumentPath);

            documentScanEngine.UpdateDocumentScanByID(36, document);
            document = documentScanEngine.GetDocumentByID(36);

            //Assert
            Assert.Equal(DocumentPath, document.DocumentPath);
        }
        public void DeleteDocumentByArchiveBooking(int id)
        {
            if (id == 0)
            {
                throw new ArgumentNullException("Invalid id.");
            }

            DocumentScan docScan = context.DocumentScans.Where(d => d.ID_ArchiveBooking == id).FirstOrDefault();

            if (docScan == null)
            {
                //throw new ArgumentNullException("No document from that archive booking in db.");
                return;
            }
            context.DocumentScans.Remove(docScan);
            context.SaveChanges();
        }
Beispiel #12
0
        public void InsertDocument()
        {
            //Arrange
            var          documentScanEngine = new DocumentScanEngine();
            const int    ID_ArchiveBooking  = 70;
            const string DocumentPath       = "novo";

            //Act
            DocumentScan document = new DocumentScan(100, ID_ArchiveBooking, DocumentPath);

            documentScanEngine.InsertDocument(document);
            List <DocumentScan> documents = documentScanEngine.GetDocumentsByArchiveBooking(70);

            //Assert
            foreach (DocumentScan doc in documents)
            {
                Assert.Equal(DocumentPath, doc.DocumentPath);
            }
        }
        public void UpdateDocumentScanByID(int id, DocumentScan document)
        {
            if (id == 0)
            {
                throw new ArgumentNullException("Invalid id.");
            }

            if (document == null)
            {
                throw new ArgumentNullException("Empty document.");
            }

            DocumentScan docScan = context.DocumentScans.Where(d => d.ID_DocumentScan == id).FirstOrDefault();

            if (docScan == null)
            {
                //throw new NullReferenceException("No document with that id in the db.");
                return;
            }
            docScan.ID_ArchiveBooking = document.ID_ArchiveBooking;
            docScan.DocumentPath      = document.DocumentPath;
            context.DocumentScans.Update(docScan);
            context.SaveChanges();
        }
        public void InsertDocument(DocumentScan document)
        {
            if (document == null)
            {
                throw new IndexOutOfRangeException("Empty document.");
            }

            using (connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (adapter = new SqlDataAdapter())
                {
                    string sql = "INSERT INTO DocumentScan(ID_ArchiveBooking, DocumentPath) VALUES(@id, @path)";
                    command = new SqlCommand(sql, connection);
                    command.Parameters.AddWithValue("@id", document.ID_ArchiveBooking);
                    command.Parameters.AddWithValue("@path", document.DocumentPath);
                    adapter.InsertCommand = command;
                    adapter.InsertCommand.ExecuteNonQuery();
                }
                command.Dispose();
                connection.Close();
            }
        }