public async Task <OpenApiResult> CreateTemplateAsync( IOpenApiContext context, ICommunicationTemplate body, [OpenApiParameter("If-None-Match")] string etag) { if (string.IsNullOrWhiteSpace(body.NotificationType)) { throw new OpenApiNotFoundException("The NotificationType was not found in the object"); } if (string.IsNullOrWhiteSpace(body.ContentType)) { throw new OpenApiNotFoundException("The ContentType was not found in the object"); } // We can guarantee tenant Id is available because it's part of the Uri. ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false); // Gets the AzureBlobTemplateStore INotificationTemplateStore store = await this.tenantedTemplateStoreFactory.GetTemplateStoreForTenantAsync(tenant).ConfigureAwait(false); try { if (body is EmailTemplate emailTemplate) { emailTemplate.ETag = etag; await store.CreateOrUpdate(body.NotificationType, CommunicationType.Email, emailTemplate.ETag, emailTemplate).ConfigureAwait(false); } else if (body is SmsTemplate smsTemplate) { smsTemplate.ETag = etag; await store.CreateOrUpdate(body.NotificationType, CommunicationType.Sms, smsTemplate.ETag, smsTemplate).ConfigureAwait(false); } else if (body is WebPushTemplate webPushTemplate) { webPushTemplate.ETag = etag; await store.CreateOrUpdate(body.NotificationType, CommunicationType.WebPush, webPushTemplate.ETag, webPushTemplate).ConfigureAwait(false); } else { // this should be removed in future updates throw new OpenApiNotFoundException($"The template for ContentType: {body.ContentType} is not a valid content type"); } } catch (StorageException e) { if (e?.RequestInformation?.HttpStatusCode == (int)System.Net.HttpStatusCode.PreconditionFailed) { throw new OpenApiBadRequestException("Precondition failure. Blob's ETag does not match ETag provided."); } throw; } return(this.OkResult()); }
public async Task GivenIHaveCreatedAndStoredANotificationTemplate(Table table) { ITenantedNotificationTemplateStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedNotificationTemplateStoreFactory>(); IJsonSerializerSettingsProvider serializerSettingsProvider = this.serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>(); NotificationTemplate notificationTemplate = BuildNotificationTemplateFrom(table.Rows[0], serializerSettingsProvider.Instance); INotificationTemplateStore store = await storeFactory.GetTemplateStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false); EmailTemplate?result = await store.CreateOrUpdate("testshouldbreak", CommunicationType.Email, null, notificationTemplate.EmailTemplate !).ConfigureAwait(false); this.scenarioContext.Set(result); }