Пример #1
0
        public IActionResult Post([FromBody] SovaUserModel model)
        {
            var sovaUser = ModelFactory.Map(model);

            DataService.Add(sovaUser);
            return(Ok(ModelFactory.Map(sovaUser, Url)));
        }
Пример #2
0
        public IActionResult Put(int id, [FromBody] SovaUserModel model)
        {
            var sovaUser = ModelFactory.Map(model);

            sovaUser.SovaUserId = id;
            if (!DataService.Update(sovaUser))
            {
                return(NotFound());
            }
            return(Ok());
        }
Пример #3
0
        public void PutShouldUpdateObjectAndReturnOk()
        {
            //arrange
            DateTime currentDateTime = DateTime.Now;
            var      sovaUserPut     = new SovaUserModel {
                SovaUserCreationDate = currentDateTime
            };
            var dataServiceMock = new Mock <IDataService <SovaUser> >();

            dataServiceMock.Setup(su => su.Update(It.IsAny <SovaUser>())).Returns(true);
            var controller = new SovaUserController(dataServiceMock.Object);

            controller.Url = Mock.Of <IUrlHelper>(x => x.IsLocalUrl(It.IsAny <string>()) == false);

            //act
            var putSovaUser = controller.Put(666, sovaUserPut);

            //assert
            var returnsRightObject = Assert.IsType <OkResult>(putSovaUser);

            dataServiceMock.Verify(su => su.Update(It.IsAny <SovaUser>()), Times.Once);
        }
Пример #4
0
        public void PostShouldDoAddNewObjectAndReturnOk()
        {
            //arrange
            DateTime currentDateTime = DateTime.Now;
            var      sovaUserPost    = new SovaUserModel {
                SovaUserCreationDate = currentDateTime
            };

            var dataServiceMock = new Mock <IDataService <SovaUser> >();

            dataServiceMock.Setup(su => su.Add(It.IsAny <SovaUser>()));

            var controller = new SovaUserController(dataServiceMock.Object);

            controller.Url = Mock.Of <IUrlHelper>(x => x.IsLocalUrl(It.IsAny <string>()) == false);

            //act
            var postSovaUser = controller.Post(sovaUserPost);

            //assert
            var returnsRightObject = Assert.IsType <OkObjectResult>(postSovaUser);

            dataServiceMock.Verify(su => su.Add(It.IsAny <SovaUser>()));
        }