Example #1
0
        public void AddStub_AddsStubToCollection()
        {
            var imposter = new HttpImposter(123, null);

            imposter.AddStub();
            Assert.AreEqual(1, imposter.Stubs.Count);
        }
        public async Task TestStatus(HttpStatusCode statusCode)
        {
            // Arrange
            _imposter
            .AddStub()
            .OnPathAndMethodEqual("/user", Method.Get)
            .ReturnsStatus(statusCode);

            _mountebankClient.Submit(_imposter);

            // Act
            using var response = await _httpClient.GetAsync("/user");

            // Assert
            Assert.Equal(statusCode, response.StatusCode);
        }
Example #3
0
        public async Task Shelly1_WhenResponseIsInternalServerError_ShouldReturnFailure()
        {
            _imposter.AddStub().OnPathEquals("/status").ReturnsStatus(HttpStatusCode.InternalServerError);

            Global.MountebankClient.Submit(_imposter);

            Settings settings = Settings.IntegrationTest();

            var sut = new Shelly1Client(settings.User, settings.Password, new Uri(settings.ShellyUri));

            // act
            var shellyResult = await sut.GetStatus(timeout : TimeSpan.FromSeconds(1), cancellationToken : CancellationToken.None);

            // assert
            shellyResult.IsSuccess.Should().BeFalse();
            shellyResult.IsFailure.Should().BeTrue();
            shellyResult.IsTransient.Should().BeFalse();
        }
Example #4
0
        public static void Impersonate <T>(
            this MountebankClient theClient,
            string mockFriendlyName,
            string path,
            int port,
            MbDotNet.Enums.Method httpMethod,
            HttpStatusCode returnCode,
            T returnBody)
        {
            HttpImposter imposter = theClient.CreateOrReplaceHttpImposter(port, mockFriendlyName);

            imposter.AddStub()
            .OnPathAndMethodEqual(path, httpMethod)
            .ReturnsJson(returnCode, returnBody);
            theClient.Submit(imposter);
        }