Пример #1
0
        public void Create()
        {
            // Arrange
            var name   = "My API Key";
            var scopes = new[] { "mail.send", "alerts.create", "alerts.read" };

            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockClient     = mockRepository.Create <IClient>();

            mockClient
            .Setup(c => c.PostAsync(ENDPOINT, It.IsAny <JObject>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(SINGLE_API_KEY_JSON)
            })
            .Verifiable();

            var apiKeys = new ApiKeys(mockClient.Object, ENDPOINT);

            // Act
            var result = apiKeys.CreateAsync(name, scopes, CancellationToken.None).Result;

            // Assert
            mockRepository.VerifyAll();
            result.ShouldNotBeNull();
        }
Пример #2
0
        public void Create()
        {
            // Arrange
            var name   = "My API Key";
            var scopes = new[] { "mail.send", "alerts.create", "alerts.read" };

            var apiResponse = @"{
				'api_key': 'SG.xxxxxxxx.yyyyyyyy',
				'api_key_id': 'xxxxxxxx',
				'name': 'My API Key',
				'scopes': [
					'mail.send',
					'alerts.create',
					'alerts.read'
				]
			}"            ;
            var mockClient  = new Mock <IClient>(MockBehavior.Strict);

            mockClient.Setup(c => c.PostAsync(ENDPOINT, It.IsAny <JObject>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(apiResponse)
            });

            var apiKeys = new ApiKeys(mockClient.Object);

            // Act
            var result = apiKeys.CreateAsync(name, scopes, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
        }
Пример #3
0
        public async Task CreateAsync()
        {
            // Arrange
            var name   = "My API Key";
            var scopes = new[] { "mail.send", "alerts.create", "alerts.read" };

            var mockHttp = new MockHttpMessageHandler();

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

            var client  = Utils.GetFluentClient(mockHttp);
            var apiKeys = new ApiKeys(client);

            // Act
            var result = await apiKeys.CreateAsync(name, scopes, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
        }