public void SearchKeyPhrase_KeyPhraseNotPresent_ReturnNull() { var testList = new List <JournalEntry>(); var jrn1 = new JournalEntry { Title = "Some Title1", EntryBody = "some other entry1", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn2 = new JournalEntry { Title = "Some Title2", EntryBody = "some other entry2", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn3 = new JournalEntry { Title = "Some Title3", EntryBody = "some other entry3", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn4 = new JournalEntry { Title = "Some Title4", EntryBody = "some other entry4", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn5 = new JournalEntry { Title = "Some Title5", EntryBody = "some other entry5", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; testList.Add(jrn1); testList.Add(jrn2); testList.Add(jrn3); testList.Add(jrn4); testList.Add(jrn5); var targetList = new List <JournalEntry>(); targetList.Add(jrn1); JournalEntryController controller = new JournalEntryController(); var resultsList = controller.FilterByString(testList, "SearchString"); Assert.AreEqual(0, resultsList.Count); }
public void SearchByJournalId_JournalHasNoEntries_NoEntriesAreReturned() { var testList = new List <JournalEntry>(); var jrn1 = new JournalEntry { JournalId = 2, Title = "Some Title1", EntryBody = "some other entry1", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn2 = new JournalEntry { JournalId = 2, Title = "Some Title2", EntryBody = "some other entry2", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn3 = new JournalEntry { JournalId = 3, Title = "Some Title3", EntryBody = "some other entry3", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn4 = new JournalEntry { JournalId = 4, Title = "Some Title4", EntryBody = "some other entry4", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn5 = new JournalEntry { JournalId = 4, Title = "Some Title5", EntryBody = "some other entry5", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; testList.Add(jrn1); testList.Add(jrn2); testList.Add(jrn3); testList.Add(jrn4); testList.Add(jrn5); var targetList = new List <JournalEntry>(); JournalEntryController controller = new JournalEntryController(); var resultsList = controller.FilterByJournal(testList, 1); CollectionAssert.AreEqual(targetList, resultsList); }
public void SearchByDate_JournalOnDateExists_ReturnsJournalOnDate() { var testList = new List <JournalEntry>(); var jrn1 = new JournalEntry { Title = "Some Title1", EntryBody = "some other entry1", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn2 = new JournalEntry { Title = "Some Title2", EntryBody = "some other entry2", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn3 = new JournalEntry { Title = "Some Title3", EntryBody = "some other entry3", CreatedOn = new DateTime(2015, 10, 21), Flag = JournalEntry.EntryFlag.N }; var jrn4 = new JournalEntry { Title = "Some Title4", EntryBody = "some other entry4", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn5 = new JournalEntry { Title = "Some Title5", EntryBody = "some other entry5", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; testList.Add(jrn1); testList.Add(jrn2); testList.Add(jrn3); testList.Add(jrn4); testList.Add(jrn5); var targetList = new List <JournalEntry>(); targetList.Add(jrn3); JournalEntryController controller = new JournalEntryController(); var resultsList = controller.FilterByDate(testList, new DateTime(2015, 10, 21)); CollectionAssert.AreEqual(targetList, resultsList); }
public void SearchByDateRange_JournalsOutOfRange_ReturnNoJournals() { var testList = new List <JournalEntry>(); var jrn1 = new JournalEntry { Title = "Some Title1", EntryBody = "some other entry1", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn2 = new JournalEntry { Title = "Some Title2", EntryBody = "some other entry2", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn3 = new JournalEntry { Title = "Some Title3", EntryBody = "some other entry3", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn4 = new JournalEntry { Title = "Some Title4", EntryBody = "some other entry4", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn5 = new JournalEntry { Title = "Some Title5", EntryBody = "some other entry5", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; testList.Add(jrn1); testList.Add(jrn2); testList.Add(jrn3); testList.Add(jrn4); testList.Add(jrn5); var targetList = new List <JournalEntry>(); targetList.Add(jrn3); JournalEntryController controller = new JournalEntryController(); var resultsList = controller.FilterByDateRange(testList, new DateTime(2015, 10, 5), new DateTime(2015, 11, 21)); Assert.AreEqual(0, resultsList.Count); }
public void SearchKeyPhrase_KeyPhraseInBody_ReturnCorrectJournal() { var testList = new List <JournalEntry>(); var jrn1 = new JournalEntry { Title = "Some Title", EntryBody = "SearchString", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn2 = new JournalEntry { Title = "Some Title2", EntryBody = "some other entry", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn3 = new JournalEntry { Title = "Some Title3", EntryBody = "some other entry", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn4 = new JournalEntry { Title = "Some Title4", EntryBody = "some other entry", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; var jrn5 = new JournalEntry { Title = "Some Title5", EntryBody = "some other entry", CreatedOn = DateTime.Now, Flag = JournalEntry.EntryFlag.N }; testList.Add(jrn1); testList.Add(jrn2); testList.Add(jrn3); testList.Add(jrn4); testList.Add(jrn5); var targetList = new List <JournalEntry>(); targetList.Add(jrn1); JournalEntryController controller = new JournalEntryController(); var resultsList = controller.FilterByString(testList, "SearchString"); CollectionAssert.AreEqual(targetList, resultsList); }
public void CreatePostShouldCreate() { //Arrange var journalEntry = new JournalEntry { Latitude = "12", Longitude = "-12", LocationOverride = "Geneva", WeatherSummary = "Sunny", Date = new DateTime(), Notes = "caught lots of fish" }; var contextOptions = new DbContextOptions <DefaultContext>(); var mockContext = new Mock <DefaultContext>(contextOptions); mockContext.Setup(x => x.Add(It.IsAny <JournalEntry>())); mockContext.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())); var controller = new JournalEntryController(mockContext.Object); //Act var response = controller.Create(journalEntry).Result; //Assert Assert.NotNull(response); var viewResult = Assert.IsType <RedirectToActionResult>(response); Assert.Equal("Index", viewResult.ActionName); mockContext.Verify(x => x.Add(journalEntry)); mockContext.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())); }
public void CreatePageShouldRender() { //Arrange var controller = new JournalEntryController(null, null, null); //Act var response = controller.Create(); //Assert Assert.NotNull(response); }
public void CreatePostShouldCreate() { //Arrange var journalEntry = new JournalEntry { Latitude = "12", Longitude = "-12", LocationOverride = "Geneva", Temperature = "Sunny", Precipitation = "18", BarometricPressure = "21", Humidity = "19", WindSpeed = "32", WindDirection = "15", Date = new DateTime(), Notes = "caught lots of fish" }; var user = new User { Email = "*****@*****.**" }; var contextOptions = new DbContextOptions <DefaultContext>(); var mockContext = new Mock <DefaultContext>(contextOptions); var mockIdentityContext = new Mock <IdentityContext>(new DbContextOptions <IdentityContext>()); var mockUserStore = new Mock <UserStore <User> >(mockIdentityContext.Object, null); var mockUserManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null, null); mockUserManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(user); mockContext.Setup(x => x.Add(It.IsAny <JournalEntry>())); mockContext.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())); var controller = new JournalEntryController(mockContext.Object, mockUserManager.Object, null); //Act var response = controller.Create(journalEntry).Result; //Assert Assert.NotNull(response); var viewResult = Assert.IsType <RedirectToActionResult>(response); mockUserManager.Verify(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); mockContext.Verify(x => x.Add(journalEntry), Times.Once); mockContext.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once); Assert.Equal("Index", viewResult.ActionName); }