public async Task CreateAsync()
        {
            // Arrange
            var name        = "Product Suggestions";
            var description = "Suggestions for products our users might like.";
            var isDefault   = true;

            var apiResponse = @"{
				'name': 'Product Suggestions',
				'description': 'Suggestions for products our users might like.',
				'is_default': true
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

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

            var client = Utils.GetFluentClient(mockHttp);
            var goups  = new UnsubscribeGroups(client);

            // Act
            var result = await goups.CreateAsync(name, description, isDefault, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Name.ShouldBe(name);
            result.Description.ShouldBe(description);
            result.IsDefault.ShouldBe(isDefault);
        }
Exemple #2
0
        public void Create()
        {
            // Arrange
            var name        = "Product Suggestions";
            var description = "Suggestions for products our users might like.";
            var isDefault   = true;

            var apiResponse = @"{
				'name': 'Product Suggestions',
				'description': 'Suggestions for products our users might like.',
				'is_default': true
			}"            ;

            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(apiResponse)
            })
            .Verifiable();

            var goups = new UnsubscribeGroups(mockClient.Object, ENDPOINT);

            // Act
            var result = goups.CreateAsync(name, description, isDefault, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
            result.Name.ShouldBe(name);
            result.Description.ShouldBe(description);
            result.IsDefault.ShouldBe(isDefault);
        }