예제 #1
0
        public void GetTagsTest()
        {
            IDatabaseDAO db = App.DatabaseInstance;

            Tag tag = new Tag {
                Title = "TestTag", Type = TagType.TAG_WITHOUT_TYPE
            };

            SnippetCode snippetCode = new SnippetCode();
            List <Tag>  tags        = new List <Tag> {
                tag
            };

            SnippetInfo snippetInfo = new SnippetInfo {
                SnippetCode = snippetCode
            };

            snippetInfo.Tags.AddRange(tags, true);

            db.saveSnippet(snippetInfo);

            Tag dbTag = db.GetTags("TestTag", TagType.TAG_WITHOUT_TYPE).First();

            Assert.IsNotNull(dbTag);
            Assert.AreEqual(tag.Title, dbTag.Title);
            Assert.AreEqual(tag.Type, dbTag.Type);
            Assert.IsNotNull(dbTag.Id);
        }
예제 #2
0
        private SnippetCode saveSnippetCode(SnippetCode infoToSave)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>
            {
                { "id", infoToSave.Id },
                { "imports", infoToSave.Imports },
                { "code", infoToSave.Code }
            };

            if (infoToSave.Id.HasValue)
            {// Update
                execute("update snippetCode set" +
                        " imports = :imports" +
                        ", code = :code" +
                        " where id = :id", dict);

                return(infoToSave);
            }
            else
            {// Insert
                execute("insert into snippetCode" +
                        " (imports, code)" +
                        " values" +
                        " (:imports, :code)", dict);

                infoToSave.Id = (int)m_dbConnection.LastInsertRowId;
                return(infoToSave);
            }
        }
예제 #3
0
        public void WithEmptyLinesCopySnippetTest()
        {
            SnippetCode sc = new SnippetCode(null, "import" + Environment.NewLine, "code");

            sc.copy();

            Assert.AreEqual("import" + Environment.NewLine + Environment.NewLine + "code", System.Windows.Clipboard.GetText());
        }
예제 #4
0
        public void deleteSnippet(SnippetInfo infoToDelete)
        {
            SnippetCode dbSnippetCodeToDelete = GetSnippetCode(infoToDelete);

            if (dbSnippetCodeToDelete != null)
            {
                execute("DELETE FROM snippetCode where snippetCode.id = :snippetCodeId", new Dictionary <string, object> {
                    { "snippetCodeId", dbSnippetCodeToDelete.Id }
                });
            }

            foreach (Tag tag in infoToDelete.Tags)
            {
                if (!existsSnippetToTag(tag))
                {
                    execute("DELETE FROM tag WHERE id = :tagId", new Dictionary <string, object> {
                        { "tagId", tag.Id }
                    });
                }
            }
        }
예제 #5
0
        public void SaveCompleteSnippetTest()
        {
            SQLiteDAO db = new SQLiteDAO();

            db.OpenConnection();

            Tag progTag = new Tag
            {
                Title = "Progsprache",
                Type  = TagType.TAG_PROGRAMMING_LANGUAGE
            };

            Tag tag = new Tag
            {
                Title = "Tag",
                Type  = TagType.TAG_WITHOUT_TYPE
            };

            List <Tag> tags = new List <Tag> {
                progTag, tag
            };

            SnippetCode snippetCode = new SnippetCode(null, "Oh schau, ein Import!", "Ein Stück Code\nSogar mit Absatz!!");

            SnippetInfo snippetInfo = new SnippetInfo()
            {
                Titel        = "Test Snippet",
                Beschreibung = "Na ein Test Snippet halt,\nwie immer ohne viel Inhalt!",
                SnippetCode  = snippetCode
            };

            snippetInfo.Tags.AddRange(tags, true);

            db.saveSnippet(snippetInfo);

            db.CloseConnection();

            Assert.Fail("Manueller Check! Schon verknüpfte Tags werden nochmal verknüpft");
        }
예제 #6
0
        private List <SnippetCode> selectSnippetCode(string sql, Dictionary <string, object> parameters)
        {
            SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);

            foreach (KeyValuePair <string, object> kvp in parameters)
            {
                command.Parameters.Add(new SQLiteParameter(kvp.Key, kvp.Value));
            }

            SQLiteDataReader dr = command.ExecuteReader();

            List <SnippetCode> snippetCodeList = new List <SnippetCode>();

            while (dr.Read())
            {
                SnippetCode snippetCode = new SnippetCode((int)dr.GetInt64(0), dr.GetString(1), dr.GetString(2));

                snippetCodeList.Add(snippetCode);
            }

            return(snippetCodeList);
        }