public void ThrowsForNullOAuthRefreshToken() { Assert.Throws <ArgumentNullException>( () => TransactClient.CreateOAuthOnly( 1, "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000", null)); }
public void ThrowsForNullOAuthClientSecret() { Assert.Throws <ArgumentNullException>( () => TransactClient.CreateOAuthOnly( 1, "00000000-0000-0000-0000-000000000000", null, "00000000-0000-0000-0000-000000000000")); }
public void SetsPodNumber() { var client = TransactClient.CreateOAuthOnly( 1, "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003"); Assert.Equal(1, client.Configuration.PodNumber); }
public void ThrowsWhenNoConfigurationAvailable() { var exception = Assert.Throws <InvalidOperationException>( () => TransactClient.CreateUsingConfiguration(_configProvider)); Assert.Equal( "Unable to create TransactClient using configuration. " + "No configuration was provided.", exception.Message); }
public void ThrowsForNullPassword() { Assert.Throws <ArgumentNullException>( () => TransactClient.CreateIncludingOAuth( 1, "some_username", null, "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000")); }
public void ThrowsForNullOAuthRefreshToken() { Assert.Throws <ArgumentNullException>( () => TransactClient.CreateIncludingOAuth( 1, "some_username", "some_username", "00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000", null)); }
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer) { var builder = new ContainerBuilder(); builder .Register <TransactClient>(x => TransactClient.CreateUsingConfiguration()) .SingleInstance(); builder.Update(existingContainer.ComponentRegistry); base.ConfigureApplicationContainer(existingContainer); }
public void SetsOAuthRefreshToken() { var client = TransactClient.CreateOAuthOnly( 1, "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003"); Assert.Equal( "00000000-0000-0000-0000-000000000003", client.Configuration.OAuthRefreshToken); }
public void SetsOAuthClientSecret() { var client = TransactClient.CreateOAuthOnly( 1, "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003"); Assert.Equal( "00000000-0000-0000-0000-000000000002", client.Configuration.OAuthClientSecret); }
public void SetsUsername() { var client = TransactClient.CreateIncludingOAuth( 1, "some_username", "some_password", "00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002", "00000000-0000-0000-0000-000000000003"); Assert.Equal("some_username", client.Configuration.Username); }
public void UsesConfigSection() { Mock.Get(_configProvider) .Setup(x => x.GetFromConfigurationSection()) .Returns(new TransactClientConfiguration { Username = "******" }); var client = TransactClient.CreateUsingConfiguration(_configProvider); Assert.Equal("username-from-config-section", client.Configuration.Username); }
public HomeModule(TransactClient client) { Get["/"] = _ => View["Index", new IndexModel(client.Configuration)]; Post["/send"] = _ => { var model = this.Bind <SendModel>(); // Validate request var validationResult = this.Validate <SendModel>(model); if (!validationResult.IsValid) { return(new TextResponse( HttpStatusCode.BadRequest, string.Join(" ", validationResult.Errors.SelectMany(x => x.Value)))); } // Create message var recipient = TransactMessageRecipient.Create(model.ToAddress); recipient.PersonalizationTags = model.PersonalizationTags; var message = TransactMessage.Create(model.CampaignId, recipient); // Send message TransactMessageResponse response = null; try { response = client.SendMessage(message); } catch (TransactClientException ex) { return(new TextResponse( HttpStatusCode.InternalServerError, ex.Message)); } return(Response.AsJson(response)); }; }
public HomeModule(TransactClient client) { Get["/"] = _ => View["Index", new IndexModel(client.Configuration)]; Post["/send"] = _ => { var model = this.Bind<SendModel>(); // Validate request var validationResult = this.Validate<SendModel>(model); if (!validationResult.IsValid) return new TextResponse( HttpStatusCode.BadRequest, string.Join(" ", validationResult.Errors.SelectMany(x => x.Value))); // Create message var recipient = TransactMessageRecipient.Create(model.ToAddress); recipient.PersonalizationTags = model.PersonalizationTags; var message = TransactMessage.Create(model.CampaignId, recipient); // Send message TransactMessageResponse response = null; try { response = client.SendMessage(message); } catch (TransactClientException ex) { return new TextResponse( HttpStatusCode.InternalServerError, ex.Message); } return Response.AsJson(response); }; }
private async static Task MainAsync(string[] args) { var client = TransactClient.Create( -1, // Change this to the correct pod number "username", "password"); var oAuthClient = TransactClient.CreateOAuthOnly( -1, // Change this to the correct pod number oAuthClientId: "00000000-0000-0000-0000-000000000000", oAuthClientSecret: "00000000-0000-0000-0000-000000000000", oAuthRefreshToken: "00000000-0000-0000-0000-000000000000"); var sendMessageResponse = client.SendMessage(GetTestMessage("SendMessage")); Console.WriteLine("sendMessageResponse:"); Console.WriteLine(sendMessageResponse.RawResponse); Console.WriteLine(); var sendMessageAsyncResponse = await client.SendMessageAsync(GetTestMessage("SendMessageAsync")); Console.WriteLine("sendMessageAsyncResponse:"); Console.WriteLine(sendMessageAsyncResponse.RawResponse); Console.WriteLine(); var sendMessageOAuthResponse = oAuthClient.SendMessage(GetTestMessage("SendMessage-UsingOAuth")); Console.WriteLine("sendMessageOAuthResponse:"); Console.WriteLine(sendMessageOAuthResponse.RawResponse); Console.WriteLine(); var sendMessageAsyncOAuthResponse = await oAuthClient.SendMessageAsync(GetTestMessage("SendMessageAsync-UsingOAuth")); Console.WriteLine("sendMessageAsyncOAuthResponse:"); Console.WriteLine(sendMessageAsyncOAuthResponse.RawResponse); Console.WriteLine(); var sendMessageBatchResponse = client.SendMessageBatch(GetTestMessage("SendMessageBatch")); Console.WriteLine("sendMessageBatchResponse:"); Console.WriteLine(sendMessageBatchResponse.Single()); Console.WriteLine(); var getStatusOfMessageBatchStart = DateTime.Now; while (true) { try { var getStatusOfMessageBatchResponse = client.GetStatusOfMessageBatch(sendMessageBatchResponse.Single()); Console.WriteLine("getStatusOfMessageBatchResponse:"); Console.WriteLine(getStatusOfMessageBatchResponse.RawResponse); Console.WriteLine(); break; } catch (TransactClientException ex) { if (ex.Message != string.Format( "Requested file transact/status/{0} does not currently exist.", sendMessageBatchResponse.Single())) { throw; } Console.WriteLine("getStatusOfMessageBatchResponse:"); Console.WriteLine(ex.Message); Console.WriteLine(); Console.WriteLine(string.Format("Sleeping for {0}...", SleepDuration.ToString())); Thread.Sleep(SleepDuration); Console.WriteLine(); } if (getStatusOfMessageBatchStart.Add(Timeout) < DateTime.Now) { Console.WriteLine(string.Format( "getStatusOfMessageBatchResponse: Response timed out after {0}.", Timeout.ToString())); break; } } var sendMessageBatchAsyncResponse = await client.SendMessageBatchAsync(GetTestMessage("SendMessageBatchAsync")); Console.WriteLine("sendMessageBatchAsyncResponse:"); Console.WriteLine(sendMessageBatchAsyncResponse.Single()); Console.WriteLine(); var getStatusOfMessageBatchAsyncStart = DateTime.Now; while (true) { try { var getStatusOfMessageBatchAsyncResponse = await client.GetStatusOfMessageBatchAsync(sendMessageBatchAsyncResponse.Single()); Console.WriteLine("getStatusOfMessageBatchAsyncResponse:"); Console.WriteLine(getStatusOfMessageBatchAsyncResponse.RawResponse); Console.WriteLine(); break; } catch (TransactClientException ex) { if (ex.Message != string.Format( "Requested file transact/status/{0} does not currently exist.", sendMessageBatchAsyncResponse.Single())) { throw; } Console.WriteLine("getStatusOfMessageBatchAsyncResponse:"); Console.WriteLine(ex.Message); Console.WriteLine(); Console.WriteLine(string.Format("Sleeping for {0}...", SleepDuration.ToString())); Thread.Sleep(SleepDuration); Console.WriteLine(); } if (getStatusOfMessageBatchAsyncStart.Add(Timeout) < DateTime.Now) { Console.WriteLine(string.Format( "getStatusOfMessageBatchAsyncResponse: Response timed out after {0}.", Timeout.ToString())); break; } } Console.WriteLine(); Console.WriteLine("Operation completed."); Console.ReadLine(); }
public void SetsPassword() { var client = TransactClient.Create(1, "some_username", "some_password"); Assert.Equal("some_password", client.Configuration.Password); }
public void SetsPodNumber() { var client = TransactClient.Create(1, "some_username", "some_password"); Assert.Equal(1, client.Configuration.PodNumber); }
public void ThrowsForNullPassword() { Assert.Throws <ArgumentNullException>( () => TransactClient.Create(1, "some_username", null)); }
public void ThrowsForNullUsername() { Assert.Throws <ArgumentNullException>( () => TransactClient.Create(1, null, "some_password")); }