public void Setup() { this.entity = new Shoutout(); this.model = new ShoutoutModel(); this.mapper = new ShoutoutMapper(); }
public ActionResult Create(ShoutoutFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Levels = db.Levels.ToList(); return(View("Create", viewModel)); } if (ModelState.IsValid) { // Save data for Create var shoutout = new Shoutout { UserId = User.Identity.GetUserId(), RecipientId = viewModel.Recipient, Recipients = viewModel.Recipients, DateTime = DateTime.Now, LevelId = viewModel.Level, Project = viewModel.Giver, Description = viewModel.Description }; // Save to Shoutout table db.Shoutouts.Add(shoutout); db.SaveChanges(); // Success alert TempData["Success"] = "Added Successfully!"; return(RedirectToAction("Create")); } return(View(viewModel)); }
public ActionResult DeleteConfirmed(int id) { Shoutout shoutout = db.Shoutouts.Find(id); db.Shoutouts.Remove(shoutout); db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddOrUpdateShouldAddNewElement(string id) { Shoutout model = new Shoutout(); this.repository.AddOrUpdate(model); this.entities.Verify(e => e.Insert(model)); this.entities.Verify(e => e.Update(model), Times.Never); }
protected override void HandleInternal(ITwitchClient client, IChatCommand command) { Shoutout model = this.repository.Get(s => s.Command == command.ArgumentsAsList.FirstOrDefault()); if (model != null) { this.SendMessage(client, $@"▬▬☆✼★▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬★✼☆▬▬ {model.Message} ▬▬☆✼★━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━★✼☆▬▬"); } }
public void GetShouldReturnElement(string id) { Shoutout entity = new Shoutout { Id = id }; this.entities.Setup(e => e.FindOne(It.IsAny <Expression <Func <Shoutout, bool> > >())).Returns(entity); Shoutout shoutout = this.repository.Get(s => s.Id == id); Assert.AreEqual(entity, shoutout); }
private void OnShoutoutChanged(object sender, PropertyChangedEventArgs e) { ShoutoutModel model = (ShoutoutModel)sender; if (string.IsNullOrEmpty(model.Command) || string.IsNullOrEmpty(model.Message)) { return; } Shoutout shoutout = new Shoutout(); this.mapper.MapToEntity(model, shoutout); this.repository.AddOrUpdate(shoutout); }
public void AddOrUpdateShouldUpdateElement(string id, string shoutoutText) { Shoutout entity = new Shoutout(); Shoutout model = new Shoutout { Message = shoutoutText }; this.entities.Setup(e => e.FindOne(It.IsAny <Expression <Func <Shoutout, bool> > >())).Returns(entity); this.repository.AddOrUpdate(model); this.entities.Verify(e => e.Insert(model), Times.Never); this.entities.Verify(e => e.Update(entity)); Assert.AreEqual(shoutoutText, entity.Message); }
public void HandleShouldDelegateToRepository(string id, string shoutoutText) { this.command.Setup(c => c.ArgumentsAsList).Returns(new List <string> { id }); this.command.Setup(c => c.CommandText).Returns("so"); Shoutout model = new Shoutout { Message = shoutoutText }; this.repository.Setup(r => r.Get(It.IsAny <Expression <Func <Shoutout, bool> > >())).Returns(model); string callback = null; this.client.Setup(c => c.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false)).Callback <string, string, bool>((a, b, c) => callback = b); this.handler.Handle(this.client.Object, this.command.Object); Assert.AreEqual($@"▬▬☆✼★▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬★✼☆▬▬ {shoutoutText} ▬▬☆✼★━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━★✼☆▬▬", callback); }