コード例 #1
0
        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));
        }
コード例 #2
0
        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");
            }
        }
コード例 #3
0
        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);
        }