Пример #1
0
        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));
        }
Пример #2
0
        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>()));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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)));
        }
Пример #5
0
        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);
        }
Пример #6
0
        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));
        }
Пример #7
0
        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)));
        }
Пример #8
0
        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>()));
        }
Пример #9
0
        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);
        }