Beispiel #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);
        }
        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)));
        }