public void Find_FindsSnippetInDatabase_True() { //Arrange Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet.Save(); //Act Snippet foundSnippet = Snippet.Find(testSnippet.Id); //Assert Assert.Equal(testSnippet, foundSnippet); }
public void Save_SnippetToDatabase_True() { //Arrange Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); //Act testSnippet.Save(); List <Snippet> result = Snippet.GetAll(); List <Snippet> testList = new List <Snippet> { testSnippet }; //Assert Assert.Equal(testList, result); }
public void Update_UpdatesSnippetInDatabase_True() { //Arrange Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet.Save(); string newTest = "y = 'Mii'"; DateTime SnippetDateTime = DateTime.Now; //Act testSnippet.Update(newTest, SnippetDateTime); string result = testSnippet.Text; //Assert Assert.Equal(newTest, result); }
public void GetSnippets_RetrievesUserSnippets_List() { EndUser testUser = new EndUser("Jerry", "password"); testUser.Save(); Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet.Save(); Snippet anotherSnippet = new Snippet("More Code", "y = 'Bar'", new DateTime(2017, 1, 01, 11, 55, 00)); anotherSnippet.Save(); testUser.AddSnippet(testSnippet); List <Snippet> allUserSnippets = testUser.GetSnippets(); List <Snippet> result = new List <Snippet> { testSnippet }; Assert.Equal(result, allUserSnippets); }
public void Delete_DeletesSnippetFromDatabase_True() { //Arrange Snippet testSnippet1 = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet1.Save(); Snippet testSnippet2 = new Snippet("Other Code", "x = 'Zoo'", new DateTime(2017, 7, 19, 12, 55, 00)); testSnippet2.Save(); //Act testSnippet1.Delete(); List <Snippet> resultSnippetList = Snippet.GetAll(); List <Snippet> testSnippetList = new List <Snippet> { testSnippet2 }; //Assert Assert.Equal(testSnippetList, resultSnippetList); }
public void GetSnippets_ReturnsAllSnippetsFromOneTag_True() { //Arrange Tag testTag = new Tag("loop"); testTag.Save(); Snippet firstSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); firstSnippet.Save(); Snippet secondSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); secondSnippet.Save(); //Act testTag.AddSnippet(firstSnippet); testTag.AddSnippet(secondSnippet); List <Snippet> testSnippets = testTag.GetSnippets(); List <Snippet> contolSnippets = new List <Snippet> { firstSnippet, secondSnippet }; //Assert Assert.Equal(contolSnippets, testSnippets); }
public void GetTags_ReturnsAllTagsFromOneSnippet_True() { //Arrange Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet.Save(); Tag firstTag = new Tag("loop"); firstTag.Save(); Tag secondTag = new Tag("loop"); secondTag.Save(); //Act testSnippet.AddTag(firstTag); testSnippet.AddTag(secondTag); List <Tag> testTags = testSnippet.GetTags(); List <Tag> controlTags = new List <Tag> { firstTag, secondTag }; //Assert Assert.Equal(controlTags, testTags); }
public void AddSnippet_AddSnippetToOneTag_True() { //Arrange Tag testTag = new Tag("loop"); testTag.Save(); Snippet firstSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); firstSnippet.Save(); Snippet secondSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); secondSnippet.Save(); //Act testTag.AddSnippet(firstSnippet); testTag.AddSnippet(secondSnippet); List <Snippet> result = testTag.GetSnippets(); List <Snippet> testList = new List <Snippet> { firstSnippet, secondSnippet }; //Assert Assert.Equal(testList, result); }
public void AddTag_AddTagToOneSnippet_True() { //Arrange Snippet testSnippet = new Snippet("Some Code", "x = 'Foo'", new DateTime(2017, 6, 19, 12, 55, 00)); testSnippet.Save(); Tag firstTag = new Tag("loop"); firstTag.Save(); Tag secondTag = new Tag("dowd"); secondTag.Save(); //Act testSnippet.AddTag(firstTag); testSnippet.AddTag(secondTag); List <Tag> result = testSnippet.GetTags(); List <Tag> testList = new List <Tag> { firstTag, secondTag }; //Assert Assert.Equal(testList, result); }
public void Search_SearchSnippetText_True() { Snippet testSnippet = new Snippet("desc1", "x = 'Foo'", new DateTime(2000, 01, 01)); testSnippet.Save(); Snippet controlSnippet = new Snippet("desc2", "y = 'Foo'", new DateTime(1999, 01, 01)); controlSnippet.Save(); Snippet testCaseSensSnippet = new Snippet("desc3", "x = 'foo'", new DateTime(1950, 01, 01)); testCaseSensSnippet.Save(); List <Snippet> testList = Snippet.SearchSnippetText("Foo"); List <Snippet> expectedList = new List <Snippet> { testSnippet, controlSnippet }; bool testTrue = (testList.Contains(testSnippet) && testList.Contains(controlSnippet)); bool controlTrue = (expectedList.Contains(testSnippet) && expectedList.Contains(controlSnippet)); Assert.Equal(testTrue, controlTrue); }
public HomeModule() { //CREATE USER Get["/user_create"] = _ => { return(View["user_create.cshtml"]); }; Post["/user_create"] = _ => { EndUser newUser = new EndUser(Request.Form["user-name"], Request.Form["user-password"]); byte[] tmp = new byte[0]; string hash = EndUser.PasswordHash(newUser.Password, tmp); newUser.Password = hash; newUser.Save(); return(View["user_login.cshtml"]); }; //USER LOGIN Get["/"] = _ => { return(View["user_login.cshtml"]); }; Post["/user_login"] = _ => { string unhashed = Request.Form["user-password"]; byte[] tmp = new byte[0]; string hash = EndUser.PasswordHash(unhashed, tmp); bool loginResult = EndUser.LoginAttempt(Request.Form["user-name"], hash); return(View["loginsuccess.cshtml", loginResult]); }; //ALL SNIPPETS Get["/snippet/view"] = _ => { List <Snippet> allSnippets = Snippet.GetAll(); return(View["snippet_view.cshtml", allSnippets]); }; //SPECIFIC SNIPPET //---VIEW SNIPPET Get["/snippet/{id}"] = param => { Dictionary <string, object> model = new Dictionary <string, object> { }; Snippet SelectedSnippet = Snippet.Find(param.id); List <Tag> SnippetTags = SelectedSnippet.GetTags(); model.Add("snippet", SelectedSnippet); model.Add("tag", SnippetTags); return(View["this_snippet.cshtml", model]); }; //----UPDATE SNUPPET Get["/snippet/{id}/update"] = param => { Dictionary <string, object> model = new Dictionary <string, object> { }; Snippet SelectedSnippet = Snippet.Find(param.id); model.Add("snippet", SelectedSnippet); return(View["snippet_update.cshtml", model]); }; Patch["/snippet/{id}/update"] = param => { Dictionary <string, object> model = new Dictionary <string, object> { }; Snippet SelectedSnippet = Snippet.Find(param.id); DateTime SnippetDateTime = DateTime.Now; List <Tag> SnippetTags = SelectedSnippet.GetTags(); SelectedSnippet.Update(Request.Form["snippet-text"], SnippetDateTime); model.Add("tag", SnippetTags); model.Add("snippet", SelectedSnippet); return(View["this_snippet.cshtml", model]); }; //----DELETE SNIPPET Get["/snippet/{id}/delete"] = param => { Dictionary <string, object> model = new Dictionary <string, object> { }; Snippet SelectedSnippet = Snippet.Find(param.id); List <Tag> SnippetTags = SelectedSnippet.GetTags(); model.Add("tag", SnippetTags); model.Add("snippet", SelectedSnippet); return(View["delete_confirm.cshtml", model]); }; Delete["/snippet/{id}/delete/"] = param => { Snippet selectedSnippet = Snippet.Find(param.id); selectedSnippet.Delete(); return(View["action_success.cshtml"]); }; //----DOWNLOAD SNIPPET Get["/snippet/{id}/download"] = param => { Snippet selectedSnippet = Snippet.Find(param.id); string snippetContent = selectedSnippet.Text; using (StreamWriter objWriter = new StreamWriter("snippetText" + param.id + ".txt")) { objWriter.Write(snippetContent); } return(View["action_success.cshtml"]); }; //ADD TAG TO SNIPPET Post["/snippet/{id}/add_tag"] = param => { Dictionary <string, object> model = new Dictionary <string, object> { }; Snippet SelectedSnippet = Snippet.Find(param.id); Tag newTag = new Tag(Request.Form["tag-text"]); newTag.Save(); SelectedSnippet.AddTag(newTag); List <Tag> SnippetTags = SelectedSnippet.GetTags(); model.Add("snippet", SelectedSnippet); model.Add("tag", SnippetTags); return(View["this_snippet.cshtml", model]); }; //CREATE SNIPPET Get["/snippet/create"] = _ => { return(View["snippet_create.cshtml"]); }; Post["/snippet/create"] = _ => { DateTime snippetDateTime = DateTime.Now; Snippet newSnippet = new Snippet(Request.Form["snippet-description"], Request.Form["snippet-text"], snippetDateTime); newSnippet.Save(); List <Snippet> allSnippets = Snippet.GetAll(); return(View["snippet_view.cshtml", allSnippets]); }; //SearchSnippet Get["/search/snippets"] = _ => { List <Snippet> allSnippets = new List <Snippet> { }; return(View["search_snippet.cshtml", allSnippets]); }; Post["/search/snippets"] = _ => { List <Snippet> allSnippets = Snippet.SearchSnippetText(Request.Form["search-string"]); return(View["search_snippet.cshtml", allSnippets]); }; //SearchTag Get["/search/tags"] = _ => { Dictionary <string, object> model = new Dictionary <string, object> { }; List <Tag> allTags = Tag.GetAll(); List <Snippet> searchedSnippets = new List <Snippet> { }; model.Add("searched", searchedSnippets); model.Add("Tags", allTags); return(View["search_tag.cshtml", model]); }; Post["/search/tags"] = _ => { Dictionary <string, object> model = new Dictionary <string, object> { }; List <Tag> allTags = Tag.GetAll(); List <Snippet> searchedSnippets = Tag.SearchSnippetsByTag(Request.Form["tag-id"]); model.Add("searched", searchedSnippets); model.Add("Tags", allTags); return(View["search_tag.cshtml", model]); }; }