private async Task PutPrepareToSendNotificationEventAsync( PrepareToSendNotificationOutcome prepareToSendNotificationOutcome, GetAudienceResult getAudienceResult, GetDeliveryChannelConfigsResult getDeliveryChannelConfigsResult, PrepareToSendNotificationResult prepareToSendNotificationResult, long trackingCodeId, IReadOnlyCollection <NamedValue <string> > inheritableTags) { PrepareToSendNotificationEventBase @event; switch (prepareToSendNotificationOutcome) { case PrepareToSendNotificationOutcome.AudienceOptedOutOfAllChannels: @event = new AudienceOptedOutOfAllChannelsEvent(trackingCodeId, DateTime.UtcNow, getAudienceResult, getDeliveryChannelConfigsResult, prepareToSendNotificationResult); break; case PrepareToSendNotificationOutcome.PreparedToSendOnAllChannels: @event = new PreparedToSendOnAllChannelsEvent(trackingCodeId, DateTime.UtcNow, getAudienceResult, getDeliveryChannelConfigsResult, prepareToSendNotificationResult); break; case PrepareToSendNotificationOutcome.PreparedToSendOnSomeChannels: @event = new PreparedToSendOnSomeChannelsEvent(trackingCodeId, DateTime.UtcNow, getAudienceResult, getDeliveryChannelConfigsResult, prepareToSendNotificationResult); break; case PrepareToSendNotificationOutcome.CouldNotPrepareToSendOnAnyChannelDespiteAttemptingAll: case PrepareToSendNotificationOutcome.CouldNotPrepareToSendOnAnyChannelBecauseOneForcedAllToBeDiscarded: @event = new CouldNotPrepareToSendOnAnyChannelEvent(trackingCodeId, DateTime.UtcNow, getAudienceResult, getDeliveryChannelConfigsResult, prepareToSendNotificationResult); break; default: throw new NotSupportedException(Invariant($"This {nameof(PrepareToSendNotificationOutcome)} is not supported: {prepareToSendNotificationOutcome}")); } var tags = this.buildPrepareToSendNotificationEventTagsProtocol.ExecuteBuildTags(trackingCodeId, @event, inheritableTags); await this.eventStream.PutWithIdAsync(trackingCodeId, @event, tags, ExistingRecordStrategy.DoNotWriteIfFoundByIdAndType); }
static AudienceOptedOutOfAllChannelsEventTest() { ConstructorArgumentValidationTestScenarios .AddScenario(() => new ConstructorArgumentValidationTestScenario <AudienceOptedOutOfAllChannelsEvent> { Name = "constructor should throw ArgumentOutOfRangeException when parameter 'getAudienceResult' GetOutcome() is not any of GetAudienceOutcome.[GotAudienceWithNoFailuresReported|GetAudienceOutcome.GotAudienceWithReportedFailuresIgnored]", ConstructionFunc = () => { var referenceObject = A.Dummy <AudienceOptedOutOfAllChannelsEvent>(); var result = new AudienceOptedOutOfAllChannelsEvent( referenceObject.Id, referenceObject.TimestampUtc, A.Dummy <GetAudienceResult>().Whose(_ => (_.GetOutcome() != GetAudienceOutcome.GotAudienceWithNoFailuresReported) && (_.GetOutcome() != GetAudienceOutcome.GotAudienceWithReportedFailuresIgnored)), referenceObject.GetDeliveryChannelConfigsResult, referenceObject.PrepareToSendNotificationResult); return(result); }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), ExpectedExceptionMessageContains = new[] { "getAudienceOutcome", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <AudienceOptedOutOfAllChannelsEvent> { Name = "constructor should throw ArgumentOutOfRangeException when parameter 'getDeliveryChannelConfigsResult' GetOutcome() is not any of GetDeliveryChannelConfigsOutcome.[GotDeliveryChannelConfigsWithNoFailuresReported|GetAudienceOutcome.GotDeliveryChannelConfigsWithReportedFailuresIgnored]", ConstructionFunc = () => { var referenceObject = A.Dummy <AudienceOptedOutOfAllChannelsEvent>(); var result = new AudienceOptedOutOfAllChannelsEvent( referenceObject.Id, referenceObject.TimestampUtc, referenceObject.GetAudienceResult, A.Dummy <GetDeliveryChannelConfigsResult>().Whose(_ => (_.GetOutcome() != GetDeliveryChannelConfigsOutcome.GotDeliveryChannelConfigsWithNoFailuresReported) && (_.GetOutcome() != GetDeliveryChannelConfigsOutcome.GotDeliveryChannelConfigsWithReportedFailuresIgnored)), referenceObject.PrepareToSendNotificationResult); return(result); }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), ExpectedExceptionMessageContains = new[] { "getDeliveryChannelConfigsOutcome", }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <AudienceOptedOutOfAllChannelsEvent> { Name = "constructor should throw ArgumentOutOfRangeException when parameter 'prepareToSendNotificationResult' GetOutcome() is is not PrepareToSendNotificationOutcome.AudienceOptedOutOfAllChannels", ConstructionFunc = () => { var referenceObject = A.Dummy <AudienceOptedOutOfAllChannelsEvent>(); var result = new AudienceOptedOutOfAllChannelsEvent( referenceObject.Id, referenceObject.TimestampUtc, referenceObject.GetAudienceResult, referenceObject.GetDeliveryChannelConfigsResult, A.Dummy <PrepareToSendNotificationResult>().Whose(_ => _.GetOutcome() != PrepareToSendNotificationOutcome.AudienceOptedOutOfAllChannels)); return(result); }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), ExpectedExceptionMessageContains = new[] { "prepareToSendNotificationOutcome" }, }); }