private void btFeedAdd_Click(object sender, EventArgs e) { string feedUrl = tbURL.Text; try { FeedsController.AddFeed(new Uri(feedUrl), (Category)cbFeedCategory.SelectedItem); } catch (Exception ex) { var message = ""; if (ex is ValidationExeption) { message = ex.Message; } if (ex is UriFormatException) { message = "Ogiltig URL"; } if (ex is XmlException) { message = "Ogiltig RRS data"; } if (ex is ArgumentException) { message = "Måste ange Kategori"; } var result = MessageBox.Show(message); } tbURL.Clear(); UpdateFeedList(); }
public void PostFeed_WithValidFeed_ReturnsCreatedAtActionResultResponse(Feed postedFeed) { string inMemoryDatabaseName = $"PostFeed_WithValidFeed_ReturnsCreatedAtActionResult{Guid.NewGuid()}"; using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PostFeed(postedFeed).Result; Assert.IsType <CreatedAtActionResult>(actionResultFromController); } }
public void DeleteFeed_WithUnusedFeedId_ReturnsNotFound(int unusedFeedId) { string inMemoryDatabaseName = $"DeleteFeed_WithUnusedFeedId_ReturnsNotFound{unusedFeedId}"; using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.DeleteFeed(unusedFeedId).Result; Assert.IsType <NotFoundResult>(actionResultFromController); } }
public void PutFeed_WithValidUpdate_ReturnsNoContent(int feedIdOfUpdatedFeed, Feed updatedFeed) { string inMemoryDatabaseName = $"PutFeed_WithValidUpdate_ReturnsNoContent{feedIdOfUpdatedFeed}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PutFeed(feedIdOfUpdatedFeed, updatedFeed).Result; Assert.IsType <NoContentResult>(actionResultFromController); } }
public void DeleteFeed_WithValidFeedId_ReturnsOkResponse(int feedIdOfFeedToDelete) { string inMemoryDatabaseName = $"DeleteFeed_WithValidFeedId_ReturnsOkResponse{feedIdOfFeedToDelete}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.DeleteFeed(feedIdOfFeedToDelete).Result; Assert.IsType <OkObjectResult>(actionResultFromController); } }
public void GetFeed_WithUnusedFeedId_Returns404(int nonExistantFeedId) { string inMemoryDatabaseName = $"GetFeed_WithUnusedFeedId_Returns404_{nonExistantFeedId}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.GetFeed(nonExistantFeedId).Result; Assert.IsType <NotFoundResult>(actionResultFromController); } }
public void PutFeed_WithIncorrectFeedId_ReturnsBadRequest(int feedId, Feed updatedFeed) { string inMemoryDatabaseName = $"PutFeed_WithIncorrectFeedId_ReturnsBadRequest{feedId}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); int incorrectFeedId = feedId + 1; using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PutFeed(incorrectFeedId, updatedFeed).Result; Assert.IsType <BadRequestResult>(actionResultFromController); } }
public void GetFeed_WithNoArguments_ReturnsAllFeedItems() { string inMemoryDatabaseName = "GetFeed_WithNoArguments_ReturnsAllFeedItems"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IEnumerable <Feed> feeds = feedsController.GetFeed(); int NumberOfTotalFeeds = myInMemoryTechResourcesContext.Feed.Count(); int NumberOfFeedsReturned = feeds.Count(); Assert.Equal(NumberOfTotalFeeds, NumberOfFeedsReturned); } }
public void GetFeed_WithExistingIntId_ReturnsCorrespondingFeed(int existingFeedId) { string inMemoryDatabaseName = $"GetFeed_WithExistingIntId_ReturnsCorrespondingFeed{existingFeedId}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); OkObjectResult actionResultFromController = (OkObjectResult)feedsController.GetFeed(existingFeedId).Result; Feed feedReturnedAsActionResultValue = (Feed)actionResultFromController.Value; Feed feedExpected = myInMemoryTechResourcesContext.Feed.Find(existingFeedId); Assert.Equal(feedExpected, feedReturnedAsActionResultValue); } }
public void PutFeed_WithValidUpdateButDeletedFeedConccurencyIssue_ReturnsNotFound(int recentlyDeletedFeedId, Feed updatedVersionOfDeletedFeed) { string inMemoryDatabaseName = $"PutFeed_WithValidUpdateButDeletedFeedConccurencyIssue_ReturnsNotFound({recentlyDeletedFeedId}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { Feed feedToDeleteToCauseConcurrencyIssue = myInMemoryTechResourcesContext.Feed.Find(recentlyDeletedFeedId); myInMemoryTechResourcesContext.Remove(feedToDeleteToCauseConcurrencyIssue); FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PutFeed(recentlyDeletedFeedId, updatedVersionOfDeletedFeed).Result; Assert.IsType <NotFoundResult>(actionResultFromController); } }
public void DeleteFeed_WithValidFeedId_ReturnsDeletedFeed(int feedIdOfFeedToDelete) { string inMemoryDatabaseName = $"DeleteFeed_WithValidFeedId_ReturnsDeletedFeed{feedIdOfFeedToDelete}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { Feed feedToBeDeleted = myInMemoryTechResourcesContext.Feed.Find(feedIdOfFeedToDelete); FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); OkObjectResult actionResultFromController = (OkObjectResult)feedsController.DeleteFeed(feedIdOfFeedToDelete).Result; string expectedSerializedFeedToBeDeleted = JsonConvert.SerializeObject(feedToBeDeleted); string serializedDeletedFeedBeingReturned = JsonConvert.SerializeObject(actionResultFromController.Value); Assert.Equal(expectedSerializedFeedToBeDeleted, serializedDeletedFeedBeingReturned); } }
public void PostFeed_WithValidFeed_SavesFeedToDatabase(Feed postedFeed) { string inMemoryDatabaseName = $"PostFeed_WithValidFeed_SavesFeedToDatabase{Guid.NewGuid()}"; using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PostFeed(postedFeed).Result; } using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { Feed insertedFeed = myInMemoryTechResourcesContext.Feed.FirstOrDefault(); Assert.NotNull(insertedFeed); } }
private void btFeedAdd_Click(object sender, EventArgs e) { string feedUrl = tbURL.Text; try { if (int.TryParse((String)tbTimer.Text, out int value)) { try { Validation.ValidateRefresh(value); } catch (TimeSpanToShortExeption) { MessageBox.Show("Intervall för kort"); return; } } else { MessageBox.Show("Intervall måste vara en siffra"); return; } FeedsController.AddFeed(new Uri(feedUrl), (Category)cbFeedCategory.SelectedItem, value); } catch (Exception ex) { var message = ""; if (ex is ValidationExeption) { message = ex.Message; } if (ex is UriFormatException) { message = "Ogiltig URL"; } if (ex is XmlException) { message = "Ogiltig RRS data"; } if (ex is ArgumentException) { message = "Måste ange Kategori"; } var result = MessageBox.Show(message); } tbURL.Clear(); tbTimer.Clear(); UpdateFeedList(); }
private FeedsController BuildFeedsController() { var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[HeaderNames.Accept] = MediaTypeNames.Application.Json; var controller = new FeedsController(FakeLogger, FakeIAVCurrentOpportunitiesRefresh) { ControllerContext = new ControllerContext() { HttpContext = httpContext, }, }; return(controller); }
public void DeleteFeed_WithValidFeedId_DeletesFeedFromDatabase(int feedIdOfFeedToDelete) { string inMemoryDatabaseName = $"DeleteFeed_WithValidFeedId_DeletesFeedFromDatabase{feedIdOfFeedToDelete}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.DeleteFeed(feedIdOfFeedToDelete).Result; } using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { Feed attemptToFindDeletedFeed = myInMemoryTechResourcesContext.Feed.Where(x => x.Id == feedIdOfFeedToDelete).FirstOrDefault(); Assert.Null(attemptToFindDeletedFeed); } }
private void UpdateFeedList() { gvFeeds.Rows.Clear(); var filterdList = new List <RSSFeed>(); if (getFilter() == null) { filterdList = FeedsController.GetFeeds(); } else { var Query = from feed in FeedsController.GetFeeds() where feed.Category.Name == getFilter() select feed; foreach (var feed in Query) { filterdList.Add(feed); } } foreach (var Feed in filterdList) { int row = gvFeeds.Rows.Add(); gvFeeds.Rows[row].Cells["ColName"].Value = Feed.Title; gvFeeds.Rows[row].Cells["ColTimer"].Value = Feed.getUpdateInterval().ToString(); if (Feed.Podcasts != null) { gvFeeds.Rows[row].Cells["ColNumEpisodes"].Value = Feed.Podcasts.Count; } else { gvFeeds.Rows[row].Cells["ColNumEpisodes"].Value = 0; } gvFeeds.Rows[row].Cells["ColCategory"].Value = Feed.Category; //gvFeeds.Rows[row].Cells["ColCategory"].Value = Feed.Category; gvFeeds.Rows[row].Tag = Feed; } }
public void PutFeed_WithValidUpdate_UpdatesDatabase(int feedIdOfUpdatedFeed, Feed updatedFeed) { string inMemoryDatabaseName = $"PutFeed_WithValidUpdate_UpdatesDatabase{feedIdOfUpdatedFeed}"; InsertMockFeedDataIntoInMemoryDatabase(inMemoryDatabaseName); using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { FeedsController feedsController = GetNewFeedsController(myInMemoryTechResourcesContext); IActionResult actionResultFromController = feedsController.PutFeed(feedIdOfUpdatedFeed, updatedFeed).Result; } using (var myInMemoryTechResourcesContext = InMemoryTechResourcesContext(inMemoryDatabaseName)) { Feed updatedFeedFromInMemoryDatabase = myInMemoryTechResourcesContext.Feed.Find(feedIdOfUpdatedFeed); string serializedUpdatedFeedFromInMemoryDatabase = JsonConvert.SerializeObject(updatedFeedFromInMemoryDatabase); string expectedSerializedUpdatedFeed = JsonConvert.SerializeObject(updatedFeed); Assert.Equal(expectedSerializedUpdatedFeed, serializedUpdatedFeedFromInMemoryDatabase); } }
private void loadPersistance() { PersitanceController controller = new PersitanceController(); var file = controller.Read(); foreach (var category in file.Categories) { CategoriesController.AddCategory(category); } foreach (var feed in file.feeds) { feed.InitializeCategory(); FeedsController.AddFeed(feed); } UpdateCategories(); UpdateFeedList(); }
private void btFeedRemove_Click(object sender, EventArgs e) { var dgv = gvFeeds; if (dgv.SelectedRows.Count < 1) { return; } if (dgv.SelectedRows[0] == null) { return; } var rowIndex = dgv.SelectedRows[0].Index; var feed = (RSSFeed)gvFeeds.Rows[rowIndex].Tag; FeedsController.RemoveFeed(feed); UpdateFeedList(); lbEpisodes.Items.Clear(); }
private void UpdateFeedList() { gvFeeds.Rows.Clear(); foreach (var Feed in FeedsController.GetFeeds()) { int row = gvFeeds.Rows.Add(); gvFeeds.Rows[row].Cells["ColName"].Value = Feed.Title; gvFeeds.Rows[row].Cells["ColTimer"].Value = Feed.getUpdateInterval().ToString(); if (Feed.Podcasts != null) { gvFeeds.Rows[row].Cells["ColNumEpisodes"].Value = Feed.Podcasts.Count; } else { gvFeeds.Rows[row].Cells["ColNumEpisodes"].Value = 0; } gvFeeds.Rows[row].Cells["ColCategory"].Value = Feed.Category; //gvFeeds.Rows[row].Cells["ColCategory"].Value = Feed.Category; gvFeeds.Rows[row].Tag = Feed; } }
public override void OnSelected(DialogViewController sender, MonoTouch.Foundation.NSIndexPath indexPath) { var c = new FeedsController (Service, Value); c.FeedSelected += f => { Value = f; c.NavigationController.PopViewControllerAnimated (true); sender.TableView.ReloadData (); }; sender.NavigationController.PushViewController (c, true); }
private void PodcastPlayerMainForm_FormClosing(object sender, FormClosingEventArgs e) { var persitanceController = new PersitanceController(); persitanceController.Write(new PersistantFile(FeedsController.GetFeeds(), CategoriesController.GetCategories())); }