/// <inheritdoc /> public override async Task ExecuteAsync( HandleRecordOp <ExecuteOpRequestedEvent <long, SendEmailOp> > operation) { new { operation }.AsArg().Must().NotBeNull(); // Pull some info out of the operation. var emailTrackingCodeId = operation.RecordToHandle.Payload.Id; var sendEmailOp = operation.RecordToHandle.Payload.Operation; var inheritableTags = operation.RecordToHandle.Metadata.Tags; // Write the request to the event stream var sendEmailRequestedEvent = new SendEmailRequestedEvent <long>(emailTrackingCodeId, DateTime.UtcNow, sendEmailOp.SendEmailRequest); var tags = this.buildSendEmailRequestedEventTagsProtocol.ExecuteBuildTags(emailTrackingCodeId, sendEmailRequestedEvent, inheritableTags); await this.emailEventStream.PutWithIdAsync(emailTrackingCodeId, sendEmailRequestedEvent, tags, ExistingRecordStrategy.DoNotWriteIfFoundById); // Execute the operation var emailResponse = await this.sendEmailProtocol.ExecuteAsync(sendEmailOp); // Put response to event stream based on success/failure SendEmailResponseEventBase <long> emailResponseEventBase; if (emailResponse.SendEmailResult == SendEmailResult.Success) { emailResponseEventBase = new SucceededInSendingEmailEvent <long>(emailTrackingCodeId, DateTime.UtcNow, emailResponse); } else { emailResponseEventBase = new FailedToSendEmailEvent <long>(emailTrackingCodeId, DateTime.UtcNow, emailResponse); } tags = this.buildSendEmailResponseEventTagsProtocol.ExecuteBuildTags(emailTrackingCodeId, emailResponseEventBase, inheritableTags); await this.emailEventStream.PutWithIdAsync(emailTrackingCodeId, emailResponseEventBase, tags, ExistingRecordStrategy.DoNotWriteIfFoundByIdAndType); }
static SendEmailRequestedEventTIdTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <SendEmailRequestedEvent <Version> > { Name = "constructor should throw ArgumentNullException when parameter 'sendEmailRequest' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SendEmailRequestedEvent <Version> >(); var result = new SendEmailRequestedEvent <Version>( referenceObject.Id, referenceObject.TimestampUtc, null); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "sendEmailRequest", }, }); }
public EmailDummyFactory() { AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(SecureConnectionMethod.Unknown); AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(SendEmailResult.Unknown); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { // DeliveryNotificationOptions.Never cannot be used in combination with any other flag // otherwise adding options to the MailMessage will throw. var validValues = EnumExtensions.GetAllPossibleEnumValues <DeliveryNotificationOptions>().Where(_ => !_.HasFlag(DeliveryNotificationOptions.Never)).ToList(); var indexToUse = ThreadSafeRandom.Next(0, validValues.Count); var result = validValues[indexToUse]; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var result = new SmtpServerConnectionDefinition(A.Dummy <string>(), A.Dummy <PositiveInteger>().ThatIs(_ => _ < 65000), A.Dummy <SecureConnectionMethod>(), A.Dummy <string>(), A.Dummy <string>()); return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var address = Invariant($"{A.Dummy<Guid>()}@example.com"); var firstNames = new[] { "Bob", "Sara", "Jane", "Joe", "Tommy", "Nora" }; var lastNames = new[] { "Jones", "Smith", "Tailor", "Wright", "Glass", "Willis" }; var firstNameIndex = ThreadSafeRandom.Next(0, firstNames.Length); var lastNameIndex = ThreadSafeRandom.Next(0, lastNames.Length); var name = firstNames[firstNameIndex] + " " + lastNames[lastNameIndex]; var result = new EmailMailbox(address, name); return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var result = new SendEmailRequestedEvent <Version>(A.Dummy <Version>(), A.Dummy <DateTime>().ToUniversalTime(), A.Dummy <SendEmailRequest>()); return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var emailResponse = new SendEmailResponse(A.Dummy <SendEmailResult>().ThatIsNot(SendEmailResult.Success), A.Dummy <string>()); var result = new FailedToSendEmailEvent <Version>(A.Dummy <Version>(), A.Dummy <DateTime>().ToUniversalTime(), emailResponse); return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var emailResponse = new SendEmailResponse(SendEmailResult.Success, null, A.Dummy <string>()); var result = new SucceededInSendingEmailEvent <Version>(A.Dummy <Version>(), A.Dummy <DateTime>().ToUniversalTime(), emailResponse); return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator(() => { var sendEmailResult = A.Dummy <SendEmailResult>(); var exceptionToString = sendEmailResult == SendEmailResult.Success ? null : A.Dummy <string>(); var communicationLog = A.Dummy <string>(); var result = new SendEmailResponse(sendEmailResult, exceptionToString, communicationLog); return(result); }); }