コード例 #1
0
        public async Task AddAsync()
        {
            // Arrange
            var emails      = new[] { "*****@*****.**", "*****@*****.**" };
            var apiResponse = @"{
				""recipient_emails"": [
					""*****@*****.**"",
					""*****@*****.**""
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Post, Utils.GetSendGridApiUri(ENDPOINT)).Respond("application/json", apiResponse);

            var client             = Utils.GetFluentClient(mockHttp);
            var globalSuppressions = new GlobalSuppressions(client);

            // Act
            await globalSuppressions.AddAsync(emails, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
        }
コード例 #2
0
        public void Add()
        {
            // Arrange
            var emails      = new[] { "*****@*****.**", "*****@*****.**" };
            var apiResponse = @"{
				'recipient_emails': [
					'*****@*****.**',
					'*****@*****.**'
				]
			}"            ;

            var mockClient = new Mock <IClient>(MockBehavior.Strict);

            mockClient.Setup(c => c.PostAsync(ENDPOINT, It.Is <JObject>(o => o["recipient_emails"].ToObject <JArray>().Count == emails.Length), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(apiResponse)
            });

            var globalSuppressions = new GlobalSuppressions(mockClient.Object);

            // Act
            globalSuppressions.AddAsync(emails, CancellationToken.None).Wait();

            // Assert
        }