public async Task DeleteAsync_Returns_NotFoundResult_When_EntityNotFoundException_Is_Thrown()
            {
                // Arrange
                const int id = 1;
                WorkoutServiceMock
                    .Setup(x => x.DeleteAsync(id))
                    .ThrowsAsync(new EntityNotFoundException(id));

                // Act
                var result = await ControllerUnderTest.DeleteAsync(id);

                // Assert
                Assert.IsType<NotFoundResult>(result);
            }
            public async Task DeleteAsync_Returns_NoContentResult()
            {
                // Arrange
                const int id = 1;
                var expectedWorkout = new Workout {Name = "Test workout 01", Id = id};
                WorkoutServiceMock
                    .Setup(x => x.DeleteAsync(id))
                    .ReturnsAsync(expectedWorkout);

                // Act
                var result = await ControllerUnderTest.DeleteAsync(id);

                // Assert
                Assert.IsType<NoContentResult>(result);
            }
Example #3
0
            public async void Should_return_NotFoundResult_when_NinjaNotFoundException_is_thrown()
            {
                // Arrange
                var unexistingClanName = "Some clan name";
                var unexistingNinjaKey = "Some ninja key";

                NinjaServiceMock
                .Setup(x => x.DeleteAsync(unexistingClanName, unexistingNinjaKey))
                .ThrowsAsync(new NinjaNotFoundException(unexistingClanName, unexistingNinjaKey));

                // Act
                var result = await ControllerUnderTest.DeleteAsync(unexistingClanName, unexistingNinjaKey);

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
            public async void Should_return_BadRequestResult()
            {
                //Arrange
                var clanName = "Some clan name";
                var ninjaKey = "SomeNinjaKey";

                ControllerUnderTest.ModelState.AddModelError("Key", "Some error");

                //Act
                var result = await ControllerUnderTest.DeleteAsync(clanName, ninjaKey);

                //Assert
                var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

                Assert.IsType <SerializableError>(badRequestResult.Value);
            }
Example #5
0
            public async void Should_return_OkObjectResult_with_the_deleted_Ninja()
            {
                // Arrange
                var clanName      = "My clan";
                var ninjaKey      = "Some key";
                var expectedNinja = new Ninja {
                    Name = "Test Ninja 1"
                };

                NinjaServiceMock
                .Setup(x => x.DeleteAsync(clanName, ninjaKey))
                .ReturnsAsync(expectedNinja);

                // Act
                var result = await ControllerUnderTest.DeleteAsync(clanName, ninjaKey);

                // Assert
                var createdResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(expectedNinja, createdResult.Value);
            }
            public async void ShouldReturnOkObjectResultWithTheDeletedNinja()
            {
                //Arrange
                var clanName      = "Some clan name";
                var ninjaKey      = "SomeNinjaKey";
                var expectedNinja = new Ninja {
                    Name = "Test Ninja 1"
                };

                NinjaServiceMock
                .Setup(x => x.DeleteAsync(clanName, ninjaKey))
                .ReturnsAsync(expectedNinja);

                //Act
                var result = await ControllerUnderTest.DeleteAsync(clanName, ninjaKey);

                //Assert
                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(expectedNinja, okResult.Value);
            }