示例#1
0
        public async Task AcceptAsync_WhenCalled_ShouldVerifyThatLoggerIsCalledWithSuccesfulMessage(
            [Frozen] Mock <ILogger <ChangeOfChargesCommandHandler> > logger,
            ChangeOfChargesMessage message,
            ChangeOfChargesCommandHandlerTestable sut)
        {
            await sut.CallAcceptAsync(message).ConfigureAwait(false);

            logger.VerifyLoggerWasCalled($"{nameof(ChangeOfChargesMessage)} have parsed validation", LogLevel.Information);
        }
示例#2
0
        public async Task RejectAsync_WhenCalled_ShouldSendEventToReportQueue(
            [Frozen] Mock <IValidationReportQueueDispatcher> validationReportQueueDispatcher,
            ChangeOfChargesMessage message,
            [NotNull] ChangeOfChargesCommandHandlerTestable sut)
        {
            await sut.CallRejectAsync(message);

            validationReportQueueDispatcher
            .Verify(mock => mock.DispatchAsync(It.IsAny <IHubMessage>()), Times.Once);
        }
示例#3
0
        public async Task ValidateAsync_WhenInputValidationResultsContainsErrors_ShouldReturnFalse(
            [Frozen] HubRequestValidationResult validationResult,
            [Frozen] Mock <IChangeOfChargesInputValidator> inputValidator,
            [NotNull] ChangeOfChargesCommandHandlerTestable sut)
        {
            validationResult.Add(new ValidationError("some error code", "some error message"));
            inputValidator.Setup(iv => iv.ValidateAsync(It.IsAny <ChangeOfChargesMessage>()))
            .ReturnsAsync(validationResult);

            var result = await sut.CallValidateAsync(new ChangeOfChargesMessage()).ConfigureAwait(false);

            result.Should().Be(false);
        }
示例#4
0
        public async Task ValidateAsync_WhenValidationResultsContainsNoErrors_ShouldReturnTrue(
            [Frozen] Mock <IChangeOfChargesDomainValidator> changeOfChargesValidationRules,
            [Frozen] Mock <IChangeOfChargesInputValidator> inputValidator,
            [NotNull] ChangeOfChargesCommandHandlerTestable sut)
        {
            inputValidator.Setup(iv => iv.ValidateAsync(It.IsAny <ChangeOfChargesMessage>()))
            .ReturnsAsync(new HubRequestValidationResult("some mRID"));

            changeOfChargesValidationRules.Setup(x =>
                                                 x.ValidateAsync(It.IsAny <ChangeOfChargesMessage>()))
            .ReturnsAsync(new HubRequestValidationResult("some mRID"));

            var result = await sut.CallValidateAsync(new ChangeOfChargesMessage()).ConfigureAwait(false);

            result.Should().Be(true);
        }
        public async Task AcceptAsync_WhenAddingDuration_ShouldInvokeStorageProviderWithCalculatedTimeProperty(int numberOfDurations, [Frozen] Mock <IIso8601Durations> iso8601Durations, [Frozen] Mock <IChargeRepository> storageProvider, ChangeOfChargesCommandHandlerTestable sut)
        {
            // Arrange
            var startTime = SystemClock.Instance.GetCurrentInstant();
            var message   = new ChangeOfChargesMessage
            {
                MktActivityRecord = new MktActivityRecord
                {
                    ValidityStartDate = startTime
                },
                Period = new ChargeTypePeriod
                {
                    Resolution = "PT1H",
                    Points     = new List <Point>
                    {
                        new Point {
                            Position = numberOfDurations, PriceAmount = 1
                        },
                    },
                },
            };

            var calculatedInstant =
                message.MktActivityRecord.ValidityStartDate.Plus(Duration.FromHours(numberOfDurations));

            iso8601Durations.Setup(i => i.AddDuration(It.IsAny <Instant>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(calculatedInstant);

            // Act
            await sut.CallAcceptAsync(message).ConfigureAwait(false);

            // Assert
            storageProvider.Verify(s => s.StoreChargeAsync(It.Is <ChangeOfChargesMessage>(msg =>
                                                                                          msg.Period != null && msg.Period.Points != null &&
                                                                                          msg.Period.Points.First().Time == calculatedInstant)));
        }