コード例 #1
0
        public void Create()
        {
            // Arrange
            var type       = AlertType.StatsNotification;
            var emailTo    = "*****@*****.**";
            var frequency  = Frequency.Weekly;
            var percentage = 75;

            var apiResponse = @"{
				'created_at': 1451520930,
				'email_to': '*****@*****.**',
				'frequency': 'daily',
				'id': 48,
				'type': 'stats_notification',
				'updated_at': 1451520930
			}"            ;
            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 alerts = new Alerts(mockClient.Object);

            // Act
            var result = alerts.CreateAsync(type, emailTo, frequency, percentage, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(48, result.Id);
        }
コード例 #2
0
        public void Create()
        {
            // Arrange
            var type       = AlertType.StatsNotification;
            var emailTo    = "*****@*****.**";
            var frequency  = Frequency.Weekly;
            var percentage = 75;

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

            var alerts = new Alerts(mockClient.Object, ENDPOINT);

            // Act
            var result = alerts.CreateAsync(type, emailTo, frequency, percentage, CancellationToken.None).Result;

            // Assert
            mockRepository.VerifyAll();
            result.ShouldNotBeNull();
        }
コード例 #3
0
        public async Task Create()
        {
            // Arrange
            var type       = AlertType.StatsNotification;
            var emailTo    = "*****@*****.**";
            var frequency  = Frequency.Weekly;
            var percentage = 75;

            var mockHttp = new MockHttpMessageHandler();

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

            var client = Utils.GetFluentClient(mockHttp);
            var alerts = new Alerts(client);

            // Act
            var result = await alerts.CreateAsync(type, emailTo, frequency, percentage, null, CancellationToken.None).ConfigureAwait(false);

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