示例#1
0
        public void Post(MailchimpConfigurationRequest request)
        {
            try
            {
                MailchimpConnectorConfig mailchimpConnectorConfig = new MailchimpConnectorConfig();
                mailchimpConnectorConfig.MailchimpApiKey = request.ApiKey;

                using (var testConnectionClient = new MailchimpListClient(mailchimpConnectorConfig, new HttpClient()))
                {
                    testConnectionClient.GetLists();
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, TraceEventType.Error);

                throw new Exception(Res.Get <Labels>().UnableToConnectCheckYourCredentials);
            }

            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <MailchimpConnectorConfig>();

            config.Enabled         = true;
            config.MailchimpApiKey = request.ApiKey;

            configManager.SaveSection(config, true);
        }
示例#2
0
        public void ThrowException_WhenServiceReturnsBadRequest()
        {
            // Arrange
            HttpMessageHandlerMock httpMessageHandlerMock = new HttpMessageHandlerMock();

            httpMessageHandlerMock.SendAsyncFunc = (httpRequestMessage) =>
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            };

            // Act
            MailchimpListClient client = new MailchimpListClient(new MailchimpConnectorConfig()
            {
                MailchimpApiKey = "someApiKey-dc"
            }, new HttpClient(httpMessageHandlerMock));

            client.GetLists();
        }