public void MessageShown() { var app2 = new StoryApplication("asdf", "content", StoryType.Joke); var result2 = new StoryCreator().CreateOrEditStory(app2); Assert.Contains("exists", result2.StoryApplication.Message); }
// Part 1 public StoryCreatorResult CreateOrEditStory(StoryApplication app) { bool isEdit = app.StoryID != 0; var result = new StoryCreatorResult(); CurrentApplication = app; result.StoryApplication = app; if (isEdit) { result.StoryApplication.Message = "Successfully edited story!"; } else { result.StoryApplication.Message = "Successfully created a new story!"; } if (TitleNotPresent()) { return(InvalidApplication("Title is missing")); } if (TitleIsInvalid()) { return(InvalidApplication("Title is invalid - needs to be 4 or more characters")); } if (TitleAlreadyExists()) { return(InvalidApplication("Title exists already in database")); } // Accept the StoryApplication result.NewStory = AcceptApplication(); return(result); }
public VoteForAStoryTwice() { var sc = new StoryCreator(); var app = new StoryApplication("Stick", "Whats brown and sticky? A stick", StoryType.Joke); var result = sc.CreateOrEditStory(app); _story = result.NewStory; }
public ValidStoryApplicationReceived() { var storyCreator = new StoryCreator(); var application = new StoryApplication("Stick", "Whats brown and sticky? A stick", StoryType.Joke); _result = storyCreator.CreateOrEditStory(application); _story = _result.NewStory; }
static void Main(string[] args) { Console.WriteLine("Hello world"); // Connect to (localdb)\projects.HumourAzure and get all Stories var connectionString = @"server=(localdb)\projects;database=HumourAzure;Trusted_Connection=True;"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new SqlCommand("SELECT StoryTypeID, Title, Content, VideoURL, ImageURL, AddedDate, Rating FROM Stories", connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var storyTypeID = reader["StoryTypeID"].ToString(); var title = reader["Title"].ToString(); var content = reader["Content"].ToString(); var videoURL = reader["VideoURL"].ToString(); var imageURL = reader["ImageURL"].ToString(); var addedDate = Convert.ToDateTime(reader["AddedDate"]); var rating = Convert.ToInt32(reader["Rating"].ToString()); var storyType = StoryType.Joke; if (storyTypeID == "1") { storyType = StoryType.Joke; } if (storyTypeID == "2") { storyType = StoryType.Video; } // Use API to insert into our system checking business rules var sc = new StoryCreator(); var sa = new StoryApplication { Content = content, ImageURL = imageURL, Rating = rating, StoryType = storyType, Title = title, VideoURL = videoURL, CreatedAt = addedDate }; var result = sc.CreateOrEditStory(sa); if (result.StoryApplication.IsInvalid()) { Console.WriteLine(result.StoryApplication.Title + ": " + result.StoryApplication.Message); } } } } } Console.WriteLine("Finished"); Console.ReadLine(); }
public ActionResult Edit(StoryApplication app) { if (ModelState.IsValid) { // Call our StoryCreator service var sc = new StoryCreator(); StoryCreatorResult result = sc.CreateOrEditStory(app); if (result.StoryApplication.IsValid()) { return(RedirectToAction("Index")); } } return(View(app)); }
public EditStoryReceived() { // Create a story _sc = new StoryCreator(); var app = new StoryApplication("Stick", "Whats brown and sticky? A stick", StoryType.Joke); _result = _sc.CreateOrEditStory(app); // Edit that story using the id created above var _sc2 = new StoryCreator(); var app2 = new StoryApplication("Stick", "Whats brown and sticky? A stick", StoryType.Joke, "", "", storyID: _result.NewStory.ID, rating: 5); var _result2 = _sc2.CreateOrEditStory(app2); _story2 = _result2.NewStory; }
// GET: /Story/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Story story = db.Stories.Find(id); if (story == null) { return(HttpNotFound()); } // Map to a StoryApplication var app = new StoryApplication(); app.StoryID = story.ID; app.Title = story.Title; app.Content = story.Content; app.Rating = story.Rating; app.StoryType = story.StoryType; return(View(app)); }
public ShortTitle() { var app = new StoryApplication("asd", "content", StoryType.Joke); _result = new StoryCreator().CreateOrEditStory(app); }
public ExistingTitle() { var app1 = new StoryApplication("asdf", "content", StoryType.Joke); _result = new StoryCreator().CreateOrEditStory(app1); }
public void DoesNotThrow() { var app2 = new StoryApplication("asdf", "content", StoryType.Joke); Assert.DoesNotThrow(() => new StoryCreator().CreateOrEditStory(app2)); }