public async Task <IActionResult> PostActivities([FromBody] Activities activities) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _activitiesRepository.CreateActivity(activities); await _activitiesRepository.Save(); return(CreatedAtAction("GetActivities", new { id = activities.Id }, activities)); }
public async Task <ActionResult> CreateActivity(BL.Models.Activity activity) { var request = await _activitiesRepository.CreateActivity(activity); if (request != null) { return(Created($"{this.Request.Path}/{request.Id}", request)); } else { throw new Exception("Internal server error"); } }
public void CreateActivity_VerifyIfItReturnsNewActivity() { var activity = new Activities() { Id = 1, UserId = "aa", Description = "Hello", DateTime = new DateTime() }; dataRepository.Setup(k => k.Add(It.IsAny <Activities>())).Returns(activity); var x = activitiesRepository.CreateActivity(activity); dataRepository.Verify(k => k.Add(It.IsAny <Activities>()), Times.Once); Assert.Equal(activity.Id, x.Id); Assert.Equal(activity.Description, x.Description); Assert.Equal(activity.UserId, x.UserId); Assert.Equal(activity.DateTime, x.DateTime); }