public void TestPutDifficultyValidationError() { //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 <ChangeDifficultyDto>(_genericServiceConfig); var service = new CrudServices(context, utData.ConfigAndMapper); //ATTEMPT var dto = new ChangeDifficultyDto() { Id = 1, Difficulty = 99, }; var response = controller.Difficulty(dto, service); //VERIFY response.GetStatusCode().ShouldEqual(CreateResponse.ErrorsStatusCode); var rStatus = response.CopyToStatus(); rStatus.IsValid.ShouldBeFalse(); rStatus.GetAllErrors().ShouldEqual("The field Difficulty must be between 1 and 5."); } }
public void TestPutDifficultyOk() { //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 <ChangeDifficultyDto>(_genericServiceConfig); var service = new CrudServices(context, utData.ConfigAndMapper); //ATTEMPT var dto = new ChangeDifficultyDto() { Id = 1, Difficulty = 5, }; var response = controller.Difficulty(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"); } }