public async Task CreateAsync_Maps_Posts_And_Completes_When_ApiCall_Succeeds() { // Arrange var expectedWorkoutViewModel = new WorkoutViewModel { Name = "Test workout 01" }; var expectedWorkout = new Workout { Name = "Test workout 01" }; MapperMock .Setup(x => x.Map <WorkoutViewModel, Workout>(expectedWorkoutViewModel)) .Returns(expectedWorkout) .Verifiable(); HttpClientMock .Setup(x => x.PostEntityAsync(It.IsAny <string>(), expectedWorkout)) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("Content as string") }) .Verifiable(); // Act await ServiceUnderTest.CreateAsync(expectedWorkoutViewModel); // Assert MapperMock.Verify(x => x.Map <WorkoutViewModel, Workout>(expectedWorkoutViewModel), Times.Once); HttpClientMock.Verify(x => x.PostEntityAsync(It.IsAny <string>(), expectedWorkout), Times.Once); }
public async Task CreateAsync_Maps_Posts_And_Throws_HttpRequestException_When_ApiCall_Fails() { // Arrange var expectedWorkoutViewModel = new WorkoutViewModel { Name = "Test workout 01" }; var expectedWorkout = new Workout { Name = "Test workout 01" }; MapperMock .Setup(x => x.Map <WorkoutViewModel, Workout>(expectedWorkoutViewModel)) .Returns(expectedWorkout) .Verifiable(); HttpClientMock .Setup(x => x.PostEntityAsync(It.IsAny <string>(), expectedWorkout)) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent("Content as string") }) .Verifiable(); // Act, Assert await Assert.ThrowsAsync <HttpRequestException>(() => ServiceUnderTest.CreateAsync(expectedWorkoutViewModel)); MapperMock.Verify(x => x.Map <WorkoutViewModel, Workout>(expectedWorkoutViewModel), Times.Once); HttpClientMock.Verify(x => x.PostEntityAsync(It.IsAny <string>(), expectedWorkout), Times.Once); }
public async void ShouldCreateAndReturnTheCreatedNinja() { //Arrange var clanName = "Some clan name"; var expectedNinja = new Ninja { Name = "Test Ninja 1", Clan = new Clan { Name = clanName } }; ClanServiceMock .Setup(x => x.IsClanExistsAsync(expectedNinja.Clan.Name)) .ReturnsAsync(true) .Verifiable(); NinjaRepositoryMock .Setup(x => x.CreateAsync(expectedNinja)) .ReturnsAsync(expectedNinja) .Verifiable(); //Act var result = await ServiceUnderTest.CreateAsync(expectedNinja); //Assert Assert.Same(expectedNinja, result); ClanServiceMock.Verify(x => x.IsClanExistsAsync(clanName), Times.Once); NinjaRepositoryMock.Verify(x => x.CreateAsync(expectedNinja), Times.Once); }
public async void Should_create_and_return_the_created_Ninja() { // Arrange const string clanName = "Some clan name"; var expectedNinja = new Ninja { Clan = new Clan { Name = clanName } }; NinjaRepositoryMock .Setup(x => x.CreateAsync(expectedNinja)) .ReturnsAsync(expectedNinja) .Verifiable(); ClanServiceMock .Setup(x => x.IsClanExistsAsync(clanName)) .ReturnsAsync(true); // Act var result = await ServiceUnderTest.CreateAsync(expectedNinja); // Assert Assert.Same(expectedNinja, result); NinjaRepositoryMock.Verify(x => x.CreateAsync(expectedNinja), Times.Once); }
public async Task CreateAsync_Creates_And_Returns_Created_Workout() { // Arrange var expectedWorkout = new Workout { Name = "Test workout 01" }; WorkoutRepositoryMock .Setup(x => x.CreateAsync(expectedWorkout)) .ReturnsAsync(expectedWorkout) .Verifiable(); // Act var result = await ServiceUnderTest.CreateAsync(expectedWorkout); // Assert Assert.Same(expectedWorkout, result); WorkoutRepositoryMock.Verify(x => x.CreateAsync(expectedWorkout), Times.Once); }
public async void Should_throw_a_ClanNotFoundException_when_clan_does_not_exist() { const string clanName = "Some clan name"; var expectedNinja = new Ninja { Clan = new Clan { Name = clanName } }; NinjaRepositoryMock .Setup(x => x.CreateAsync(expectedNinja)) .ReturnsAsync(expectedNinja) .Verifiable(); ClanServiceMock .Setup(x => x.IsClanExistsAsync(clanName)) .ReturnsAsync(false); // Act & Assert await Assert.ThrowsAsync <ClanNotFoundException>(() => ServiceUnderTest.CreateAsync(expectedNinja)); // Make sure CreateAsync is never called NinjaRepositoryMock.Verify(x => x.CreateAsync(expectedNinja), Times.Never); }
public async void ShouldThrowClanNotFoundExceptionWhenClanDoesNotExist() { //Arrange var clanName = "Some clan name"; var expectedNinja = new Ninja { Name = "Test Ninja 1", Clan = new Clan { Name = clanName } }; ClanServiceMock .Setup(x => x.IsClanExistsAsync(expectedNinja.Clan.Name)) .ReturnsAsync(false) .Verifiable(); NinjaRepositoryMock .Setup(x => x.CreateAsync(expectedNinja)) .Verifiable(); //Act & Assert await Assert.ThrowsAsync <ClanNotFoundException>(() => ServiceUnderTest.CreateAsync(expectedNinja)); ClanServiceMock.Verify(x => x.IsClanExistsAsync(clanName), Times.Once); NinjaRepositoryMock.Verify(x => x.CreateAsync(expectedNinja), Times.Never); }
public async Task ShouldCreateAndReturnTheSpecifiedClan() { // Arrange, Act, Assert var exception = await Assert.ThrowsAsync <NotSupportedException>(() => ServiceUnderTest.CreateAsync(null)); }
public async Task Should_throw_a_NotSupportedException() { // Arrange, Act, Assert var exception = await Assert.ThrowsAsync <NotSupportedException>(() => ServiceUnderTest.CreateAsync(null)); }
public async Task Should_create_and_return_the_specified_clan() { // Arrange, Act, Assert var exception = await Assert.ThrowsAsync <NotSupportedException>(() => ServiceUnderTest.CreateAsync(null)); }
public async Task Deve_criar_e_retornar_o_usuario_especificado() { // Arrange, Act, Assert var exception = await Assert.ThrowsAsync <NotSupportedException>(() => ServiceUnderTest.CreateAsync(null)); }