コード例 #1
0
        public async Task GetHtmlCampaignPreviewAsync_ShouldReturnErrorString_WhenConnectionFailed()
        {
            // Arrange
            var localSettingsMock     = new Mock <ILocalSettings>();
            var configurationSettings = new ConfigurationSettingsDouble
            {
                ApiBaseUrl = "https://yahoo.com"
            };

            using (var httpTest = new HttpTest())
            {
                var errorMsg = "Call failed with status code 500 (Internal Server Error)";
                httpTest.RespondWith(errorMsg, 500);

                IDopplerAPI dopplerAPI = new DopplerAPI(configurationSettings, localSettingsMock.Object);

                // Act
                var getHtmlCampaignPreviewResult = await dopplerAPI.GetCampaignHtmlPreviewAsync("*****@*****.**", 12323);

                // Assert
                Assert.False(getHtmlCampaignPreviewResult.IsSuccessResult);
                Assert.NotNull(getHtmlCampaignPreviewResult.ErrorValue);
                Assert.Null(getHtmlCampaignPreviewResult.SuccessValue);
                Assert.StartsWith(errorMsg, getHtmlCampaignPreviewResult.ErrorValue);
            }
        }
コード例 #2
0
        public async Task GetHtmlCampaignPreviewAsync_ShouldReturnHtmlString_WhenConnectionIsSuccessful()
        {
            // Arrange
            var localSettingsMock     = new Mock <ILocalSettings>();
            var configurationSettings = new ConfigurationSettingsDouble
            {
                ApiBaseUrl = "https://yahoo.com"
            };

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("HTML HERE");

                IDopplerAPI dopplerAPI = new DopplerAPI(configurationSettings, localSettingsMock.Object);

                // Act
                var getHtmlCampaignPreviewResult = await dopplerAPI.GetCampaignHtmlPreviewAsync("*****@*****.**", 12323);

                // Assert
                Assert.True(getHtmlCampaignPreviewResult.IsSuccessResult);
                Assert.Null(getHtmlCampaignPreviewResult.ErrorValue);
                Assert.NotNull(getHtmlCampaignPreviewResult.SuccessValue);
                Assert.NotEmpty(getHtmlCampaignPreviewResult.SuccessValue);
            }
        }