public async Task <IActionResult> Add(StrategyCreationBindingModel model) { var strategy = await this.strategiesService.AddStrategyAsync(model); SetSuccesfullMessage(AddedSuccessfully, StrategyConst); return(this.RedirectToAction("Details", new { id = strategy.Id, slug = strategy.Slug })); }
public async Task <Strategy> AddStrategyAsync(StrategyCreationBindingModel model) { Validator.EnsureNotNull(model, ValidationConstants.StrategyDefinedMessage); Validator.EnsureStringNotNullOrEmpty(model.Title, ValidationConstants.StrategyTitleMessage); Validator.EnsureStringNotNullOrEmpty(model.Slug, ValidationConstants.StrategySlugMessage); Validator.EnsureStringNotNullOrEmpty(model.Content, ValidationConstants.StrategyContentMessage); Validator.EnsureStringNotNullOrEmpty(model.Priority.ToString(), ValidationConstants.StrategyPriorityMessage); var strategy = this.Mapper.Map <Strategy>(model); await this.DbContext.Strategies.AddAsync(strategy); await this.DbContext.SaveChangesAsync(); return(strategy); }
public void Add_WithValidStrategy_ShouldCallService() { // Arrange var model = new StrategyCreationBindingModel(); bool serviceCalled = false; var mockRepository = new Mock <IAdminStrategiesService>(); mockRepository.Setup(repo => repo.AddStrategyAsync(model)) .Callback(() => serviceCalled = true); var controller = new StrategiesController(mockRepository.Object); // Act var result = controller.Add(model); // Assert Assert.IsTrue(serviceCalled); }