public void TestPutNameOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabase();

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeNameDto>(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new ChangeNameDto()
                {
                    Id   = 2,
                    Name = "Test",
                };
                var response = controller.Name(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.OkStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Successfully updated the Todo Item");
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> ChangeUsernameAsync([FromBody] ChangeNameDto changeNameDto)
        {
            var user = await _userManager.FindByNameAsync(changeNameDto.OldUserName);

            var result = await _userManager.SetUserNameAsync(user, changeNameDto.NewUserName);

            return(result.Succeeded ? (IActionResult)Ok() : BadRequest(result.Errors));
        }
Esempio n. 3
0
 public ActionResult <WebApiMessageOnly> Name(ChangeNameDto dto, [FromServices] ICrudServices service)
 {
     service.UpdateAndSave(dto);
     return(service.Response());
 }