public async Task Get_ManagerError_ShouldThrow() { // arrange var id = Guid.NewGuid(); PaymentManagerMock .Setup(m => m.GetByIdAsync(id)) .ThrowsAsync(new InvalidOperationException()); // act // assert await Assert.ThrowsAsync <InvalidOperationException>(() => SUT.Get(id)); }
public async Task Get_HappyPath_ReportsToTelemetry() { // arrange var expected = Fixture.Create <GetPayment>(); PaymentManagerMock .Setup(m => m.GetByIdAsync(expected.Id)) .ReturnsAsync(expected); // act await SUT.Get(expected.Id); // assert TelemetrySubmitterMock.Verify(m => m.SubmitAsync(It.IsAny <ServiceOperation>())); }
public async Task Get_HappyPath_ReturnsPayment() { // arrange var expected = Fixture.Create <GetPayment>(); PaymentManagerMock .Setup(m => m.GetByIdAsync(expected.Id)) .ReturnsAsync(expected); // act var actual = await SUT.Get(expected.Id); // assert actual.GetObject <GetPayment>().Should().Be(expected); }
public async Task Get_ManagerError_ReportsToTelemetry() { // arrange var id = Guid.NewGuid(); var invalidOperationException = new InvalidOperationException(); PaymentManagerMock .Setup(m => m.GetByIdAsync(id)) .ThrowsAsync(invalidOperationException); // act await Assert.ThrowsAsync <InvalidOperationException>(() => SUT.Get(id)); // assert TelemetrySubmitterMock.Verify(m => m.SubmitAsync(It.Is <ServiceOperation>(o => o.IsFaulted == 1))); }
public async Task Get_NotExist_ReturnsNotFound() { // arrange var id = Guid.NewGuid(); const HttpStatusCode expected = HttpStatusCode.NotFound; PaymentManagerMock .Setup(m => m.GetByIdAsync(id)) .ReturnsAsync((GetPayment)null); // act var actual = await SUT.Get(id); // assert actual.AssertStatusCode(expected); }
public async Task Get_ManagerError_Throws() { // arrange var createPayment = Fixture.Create <CreatePayment>(); CreatePaymentValidatorMock .Setup(m => m.ValidateAsync(It.IsAny <CreatePayment>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidationResult()); PaymentManagerMock .Setup(m => m.CreateAsync(createPayment)) .ThrowsAsync(new InvalidOperationException()); // act // assert await Assert.ThrowsAsync <InvalidOperationException>(() => SUT.Create(createPayment)); }
public async Task Get_ManagerError_ReportsToTelemetry() { // arrange var createPayment = Fixture.Create <CreatePayment>(); CreatePaymentValidatorMock .Setup(m => m.ValidateAsync(It.IsAny <CreatePayment>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidationResult()); PaymentManagerMock .Setup(m => m.CreateAsync(createPayment)) .ThrowsAsync(new InvalidOperationException()); // act await Assert.ThrowsAsync <InvalidOperationException>(() => SUT.Create(createPayment)); // assert TelemetrySubmitterMock.Verify(m => m.SubmitAsync(It.Is <ServiceOperation>(o => o.IsFaulted == 1))); }
public async Task Get_HappyPath_ReportsToTelemetry() { // arrange var createPayment = Fixture.Create <CreatePayment>(); var expected = Fixture.Create <GetPayment>(); CreatePaymentValidatorMock .Setup(m => m.ValidateAsync(It.IsAny <CreatePayment>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidationResult()); PaymentManagerMock .Setup(m => m.CreateAsync(createPayment)) .ReturnsAsync(expected); // act await SUT.Create(createPayment); // assert TelemetrySubmitterMock.Verify(m => m.SubmitAsync(It.IsAny <ServiceOperation>())); }
public async Task Get_HappyPath_ReturnsPayment() { // arrange var createPayment = Fixture.Create <CreatePayment>(); var expected = Fixture.Create <GetPayment>(); CreatePaymentValidatorMock .Setup(m => m.ValidateAsync(It.IsAny <CreatePayment>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidationResult()); PaymentManagerMock .Setup(m => m.CreateAsync(createPayment)) .ReturnsAsync(expected); // act IActionResult actual = await SUT.Create(createPayment); // assert actual.GetObject <GetPayment>().Should().Be(expected); }