public async Task StoreChargeAsync_WhenChargeIsSaved_ThenSuccessReturnedAsync()
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

            SeedDatabaseContext();
            var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions));

            // Act
            var result = await sut.StoreChargeAsync(message).ConfigureAwait(false);

            // Assert
            Assert.True(result.Success);
        }
        public async Task StoreChargeAsync_WhenPointsIsNull_ThenExceptionThrownAsync()
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

#pragma warning disable CS8602 // Dereference of a possibly null reference.
            message.Period.Points = null;
#pragma warning restore CS8602 // Dereference of a possibly null reference.

            SeedDatabaseContext();
            var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions));

            // Act
            var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false));

            // Assert
            Assert.IsType <ArgumentException>(exception);
            Assert.Contains($"{nameof(message.Period.Points)} can't be null", exception.Message);
        }
Ejemplo n.º 3
0
        public async Task StoreChargeAsync_WhenValueNotFoundInDbContext_ThenFailureStatusReturnedAsync(string chargeType, string resolutionType, string vatPayerType, string chargeOwner, string failureReason)
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

            message.Type = chargeType;
            message.ChargeTypeOwnerMRid = chargeOwner;
            message !.MktActivityRecord !.ChargeType !.VatPayer = vatPayerType;
            message !.Period !.Resolution = resolutionType;

            SeedDatabase();
            await using var chargesDatabaseContext = new ChargesDatabaseContext(_dbContextOptions);
            var sut = new ChargeRepository(chargesDatabaseContext);

            // Act
            var result = await sut.StoreChargeAsync(message).ConfigureAwait(false);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(failureReason, result.Reason);
        }
        public async Task StoreChargeAsync_WhenValuesInMessageUsedForDbContextLookupsAreInvalid_ThenExceptionThrownAsync(string chargeType, string resolutionType, string vatPayerType, string chargeOwner, string exceptionMessage)
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

            message.Type = chargeType;
            message.ChargeTypeOwnerMRid = chargeOwner;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
            message.MktActivityRecord.ChargeType.VATPayer = vatPayerType;
            message.Period.Resolution = resolutionType;
#pragma warning restore CS8602 // Dereference of a possibly null reference.

            SeedDatabaseContext();
            var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions));

            // Act
            var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false));

            // Assert
            Assert.IsType <ArgumentException>(exception);
            Assert.Contains(exceptionMessage, exception.Message);
        }
        public async Task StoreChargeAsync_WhenValueNotFoundInDbContext_ThenFailureStatusReturnedAsync(string chargeType, string resolutionType, string vatPayerType, string chargeOwner, string failureReason)
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

            message.Type = chargeType;
            message.ChargeTypeOwnerMRid = chargeOwner;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
            message.MktActivityRecord.ChargeType.VATPayer = vatPayerType;
            message.Period.Resolution = resolutionType;
#pragma warning restore CS8602 // Dereference of a possibly null reference.

            SeedDatabaseContext();
            var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions));

            // Act
            var result = await sut.StoreChargeAsync(message).ConfigureAwait(false);

            // Assert
            Assert.False(result.Success);
            Assert.Equal(failureReason, result.Reason);
        }
        public async Task StoreChargeAsync_WhenValuesInMessageAreInvalid_ThenExceptionThrownAsync(string chargeTypeMRid, string correlationId, string lastUpdatedBy, string shortDescription, string longDescription, string argumentThatFails)
        {
            // Arrange
            var message = GetValidChangeOfChargesMessage();

            message.ChargeTypeMRid = chargeTypeMRid;
            message.CorrelationId  = correlationId;
            message.LastUpdatedBy  = lastUpdatedBy;
#pragma warning disable CS8602 // Dereference of a possibly null reference.
            message.MktActivityRecord.ChargeType.Name        = shortDescription;
            message.MktActivityRecord.ChargeType.Description = longDescription;
#pragma warning restore CS8602 // Dereference of a possibly null reference.

            SeedDatabaseContext();
            var sut = new ChargeRepository(new ChargesDatabaseContext(_dbContextOptions));

            // Act
            var exception = await Record.ExceptionAsync(async() => await sut.StoreChargeAsync(message).ConfigureAwait(false));

            // Assert
            Assert.IsType <ArgumentException>(exception);
            Assert.Contains($"{argumentThatFails} must have value", exception.Message);
        }