public async Task AndTheIdIsIncorrect_ThenReturnBadRequest() { var nonGuidId = "testtesttest"; var sut = new PaymentController(null, _loggerMock.Object); var result = await sut.Delete(nonGuidId); result.Should().BeOfType <BadRequestObjectResult>(); }
public async Task AndThereIsPayment_ThenReturn200() { var existingPaymentId = Guid.NewGuid(); var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.DeletePayment(existingPaymentId)).ReturnsAsync(true); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Delete(existingPaymentId.ToString()); result.Should().BeOfType <OkResult>(); }
public async Task AndThereIsNoPayment_ThenReturn404() { var nonExistingPaymentId = Guid.NewGuid(); var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.DeletePayment(nonExistingPaymentId)).ReturnsAsync(false); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Delete(nonExistingPaymentId.ToString()); result.Should().BeOfType <NotFoundResult>(); }
public async Task AndThereIsExeption_ThenReturn500() { var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.DeletePayment(It.IsAny <Guid>())).ThrowsAsync(new Exception()); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Delete(Guid.NewGuid().ToString()); result.Should().BeOfType <StatusCodeResult>(); var castedResult = (StatusCodeResult)result; castedResult.StatusCode.Should().Be(500); }
public void Delete_NotNull_ResultIsNotNull() { //Arrange var payment = new PaymentViewModel(); var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.DeletePayment(payment.Id)); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); //Act ViewResult result = controller.Delete(payment.Id) as ViewResult; //Assert Assert.IsNotNull(result); }
public void Delete_Success_ReturnsViewResult() { // Arrange var paymentId = 1; var testPayment = new PaymentViewModel() { Id = paymentId }; var paymentsRepo = new Mock <IPaymentService>(); var guestsRepo = new Mock <IGuestService>(); var reservationsRepo = new Mock <IReservationService>(); paymentsRepo.Setup(g => g.ReadSingle(paymentId)).Returns(It.IsAny <PaymentViewModel>()); var controller = new PaymentController(paymentsRepo.Object, guestsRepo.Object, reservationsRepo.Object); // Act var result = controller.Delete(paymentId); // Assert Assert.That(result, Is.InstanceOf <ViewResult>()); }