public async Task TestGetValuesAsync() { /* * The AAA (Arrange, Act, Assert) pattern is a common way of writing unit tests for a method under test. * * The Arrange section of a unit test method initializes objects and sets the value of the data that is passed to the method under test. * * The Act section invokes the method under test with the arranged parameters. * * The Assert section verifies that the action of the method under test behaves as expected. */ //Arange var dbContext = ContextMocker.GetContext(); var controller = new ValuesController(dbContext); //Act var response = await controller.GetValuesAsync(); var value = response.Value; //Assert foreach (var item in value) { output.WriteLine($"{item.Id} {item.Name}"); } }
public async Task TestGetValueAsync() { //Arange var dbContext = ContextMocker.GetContext(); var controller = new ValuesController(dbContext); int id = 3; //Act var response = await controller.GetValueAsync(id); var value = response.Value; dbContext.Dispose(); //Assert Assert.True(value != null); }
public async Task TestPutValueAsync() { //Arrange var dbContext = ContextMocker.GetContext(); var controller = new ValuesController(dbContext); int id = 4; var request = new Value { Id = 4, Name = "New Item" }; //Act var response = await controller.PutValueAsync(id, request); //var typeExpected = new NoContentResult(); var v = (NoContentResult)response; //Assert //return status code 402. Respond from server was successfull and no action as result. Assert.Equal(StatusCodes.Status204NoContent, v.StatusCode); }