public async void ShouldReturnCreatedAtActionResultWithTheCreatedNinja() { //Arrange var expectedNinjaKey = "SomeNinjaKey"; var expectedClanName = "My Clan"; var expectedCreatedAtActionName = nameof(NinjaController.ReadOneAsync); var expectedNinja = new Ninja { Name = "Test Ninja 1", Clan = new Clan { Name = expectedClanName } }; NinjaServiceMock .Setup(x => x.CreateAsync(expectedNinja)) .ReturnsAsync(() => { expectedNinja.Key = expectedNinjaKey; return(expectedNinja); }); //Act var result = await ControllerUnderTest.CreateAsync(expectedNinja); //Assert var createdResult = Assert.IsType <CreatedAtActionResult>(result); Assert.Same(expectedNinja, createdResult.Value); Assert.Equal(expectedCreatedAtActionName, createdResult.ActionName); Assert.Equal(expectedNinjaKey, createdResult.RouteValues.GetValueOrDefault("key")); Assert.Equal(expectedClanName, createdResult.RouteValues.GetValueOrDefault("clan")); }
public async void Should_return_OkObjectResult_with_pedido_created() { // Arrange // Act var result = await ControllerUnderTest.CreateAsync(); // Assert var okResult = Assert.IsType <OkObjectResult> (result); Assert.IsType <Pedido>(okResult.Value); }
public async Task CreateAsync_Returns_BadRequestObjectResult_When_ModelStateIsInvalid() { // Arrange var expectedWorkout = new Workout {Name = "Test workout 01"}; ControllerUnderTest.ModelState.AddModelError("Id", "Some error"); // Act var result = await ControllerUnderTest.CreateAsync(expectedWorkout); // Assert var badRequestObjectResult = Assert.IsType<BadRequestObjectResult>(result); Assert.IsType<SerializableError>(badRequestObjectResult.Value); }
public async void Should_return_BadRequestResult() { // Arrange var ninja = new Ninja { Name = "Test Ninja 1" }; ControllerUnderTest.ModelState.AddModelError("Key", "Some error"); // Act var result = await ControllerUnderTest.CreateAsync(ninja); // Assert var badRequestResult = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequestResult.Value); }
public async Task CreateAsync_Returns_CreatedAtActionResult_With_Workout() { // Arrange const int id = 1; var expectedWorkout = new Workout {Name = "Test workout 01", Id = id}; const string expectedCreatedAtActionName = nameof(WorkoutsController.ReadOneAsync); WorkoutServiceMock .Setup(x => x.CreateAsync(expectedWorkout)) .ReturnsAsync(() => { expectedWorkout.Id = id; return expectedWorkout; }); // Act var result = await ControllerUnderTest.CreateAsync(expectedWorkout); // Assert var createdAtActionResult = Assert.IsType<CreatedAtActionResult>(result); Assert.Same(expectedWorkout, createdAtActionResult.Value); Assert.Equal(expectedCreatedAtActionName, createdAtActionResult.ActionName); Assert.Equal(id, createdAtActionResult.RouteValues.GetValueOrDefault("id")); }