Ejemplo n.º 1
0
        public void Constructor_SetsPort()
        {
            const int port     = 123;
            var       imposter = new HttpImposter(port, null);

            Assert.AreEqual(port, imposter.Port);
        }
Ejemplo n.º 2
0
        public void CreateImposter_SendsRequest_ImposterWithNoPort()
        {
            var response = new HttpResponseMessage();

            response.StatusCode = HttpStatusCode.Created;
            response.Content    = new StringContent(@"
            {
                ""protocol"": ""http"",
                ""port"": 12345,
                ""numberOfRequests"": 0,
                ""requests"": [],
                ""stubs"": [],
                ""_links"": {
                    ""self"": {
                        ""href"": ""http://localhost:2525/imposters/64735""
                    }
                }
            }
            ");

            _mockClient.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .ReturnsAsync(response);

            var imposter = new HttpImposter(null, null);

            _proxy.CreateImposter(imposter);

            Assert.AreEqual(12345, imposter.Port);
        }
Ejemplo n.º 3
0
        public async Task Submit_AllowsNullPort()
        {
            var imposter = new HttpImposter(null, null);

            await Client.SubmitAsync(imposter).ConfigureAwait(false);

            MockRequestProxy.Verify(x => x.CreateImposterAsync(It.Is <Imposter>(imp => imp.Port == default), default), Times.Once);
Ejemplo n.º 4
0
        public void Constructor_SetsName()
        {
            const string expectedName = "Service";
            var          imposter     = new HttpImposter(123, expectedName);

            Assert.AreEqual(expectedName, imposter.Name);
        }
Ejemplo n.º 5
0
        public void AddStub_AddsStubToCollection()
        {
            var imposter = new HttpImposter(123, null);

            imposter.AddStub();
            Assert.AreEqual(1, imposter.Stubs.Count);
        }
Ejemplo n.º 6
0
        public async Task CreateImposter_SendsRequest_ImposterWithNoPort()
        {
            var response = GetResponse(
                HttpStatusCode.Created,
                @"
                {
                    ""protocol"": ""http"",
                    ""port"": 12345,
                    ""numberOfRequests"": 0,
                    ""requests"": [],
                    ""stubs"": [],
                    ""_links"": {
                        ""self"": {
                            ""href"": ""http://localhost:2525/imposters/12345""
                        }
                    }
                }
                ");

            _mockClient.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>(), default))
            .ReturnsAsync(response);

            var imposter = new HttpImposter(null, null);

            await _proxy.CreateImposterAsync(imposter).ConfigureAwait(false);

            Assert.AreEqual(12345, imposter.Port);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new imposter on the specified port with the HTTP protocol. The Submit method
        /// must be called on the client in order to submit the imposter to mountebank.
        /// </summary>
        /// <param name="port">The port the imposter will be set up to receive requests on</param>
        /// <param name="name">The name the imposter will recieve, useful for debugging/logging purposes</param>
        /// <returns>The newly created imposter</returns>
        public HttpImposter CreateHttpImposter(int port, string name = null)
        {
            var imposter = new HttpImposter(port, name);

            Imposters.Add(imposter);
            return(imposter);
        }
Ejemplo n.º 8
0
        public void Submit_AllowsNullPort()
        {
            var imposter = new HttpImposter(null, null);

            Client.Submit(imposter);

            MockRequestProxy.Verify(x => x.CreateImposter(It.Is <Imposter>(imp => imp.Port == default(int))), Times.Once);
        }
        public MountebankTests()
        {
            _httpClient = new HttpClient {
                BaseAddress = _localhostUri
            };

            _mountebankClient = new MountebankClient();

            _mountebankClient.DeleteAllImposters();

            _imposter = _mountebankClient.CreateHttpImposter(_port);
        }
Ejemplo n.º 10
0
        public void Submit_CallsSubmitOnAllPendingImposters()
        {
            const int firstPortNumber  = 123;
            const int secondPortNumber = 456;

            var imposter1 = new HttpImposter(firstPortNumber, null);
            var imposter2 = new HttpImposter(secondPortNumber, null);

            this._client.Submit(new [] { imposter1, imposter2 });

            this._mockRequestProxy.Verify(x => x.CreateImposter(It.Is <Imposter>(imp => imp.Port == firstPortNumber)), Times.Once);
            this._mockRequestProxy.Verify(x => x.CreateImposter(It.Is <Imposter>(imp => imp.Port == secondPortNumber)), Times.Once);
        }
Ejemplo n.º 11
0
        public async Task Submit_CallsSubmitOnAllPendingImposters()
        {
            const int firstPortNumber  = 123;
            const int secondPortNumber = 456;

            var imposter1 = new HttpImposter(firstPortNumber, null);
            var imposter2 = new HttpImposter(secondPortNumber, null);

            await Client.SubmitAsync(new[] { imposter1, imposter2 }).ConfigureAwait(false);

            MockRequestProxy.Verify(x => x.CreateImposterAsync(It.Is <Imposter>(imp => imp.Port == firstPortNumber)), Times.Once);
            MockRequestProxy.Verify(x => x.CreateImposterAsync(It.Is <Imposter>(imp => imp.Port == secondPortNumber)), Times.Once);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public void CreateImposter_SendsRequest_WithJsonBody()
        {
            var imposter = new HttpImposter(123, null);

            var response = GetResponse(HttpStatusCode.Created);

            HttpContent content = null;

            _mockClient.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .ReturnsAsync(response)
            .Callback <string, HttpContent>((res, cont) => content = cont);

            _proxy.CreateImposter(new HttpImposter(123, null));

            var json = content.ReadAsStringAsync().Result;
            var serializedImposter = JsonConvert.DeserializeObject <HttpImposter>(json);

            Assert.AreEqual(imposter.Port, serializedImposter.Port);
        }
Ejemplo n.º 14
0
        public async Task CreateImposter_SendsRequest()
        {
            const string expectedResource = "imposters";

            var imposter = new HttpImposter(123, null);

            var response = GetResponse(HttpStatusCode.Created);

            HttpContent content = null;

            _mockClient.Setup(x => x.PostAsync(expectedResource, It.IsAny <HttpContent>(), default))
            .ReturnsAsync(response)
            .Callback <string, HttpContent, CancellationToken>((res, cont, _) => content = cont);

            await _proxy.CreateImposterAsync(imposter).ConfigureAwait(false);

            var json = await content.ReadAsStringAsync();

            var serializedImposter = JsonConvert.DeserializeObject <HttpImposter>(json);

            Assert.AreEqual(imposter.Port, serializedImposter.Port);
        }
Ejemplo n.º 15
0
        public void Constructor_InitializesDefaultResponse()
        {
            var imposter = new HttpImposter(123, null, defaultResponse: new HttpResponseFields());

            Assert.IsNotNull(imposter.DefaultResponse);
        }
Ejemplo n.º 16
0
        public void Constructor_PendingSubmissionUponCreation()
        {
            var imposter = new HttpImposter(123, null);

            Assert.IsTrue(imposter.PendingSubmission);
        }
Ejemplo n.º 17
0
 private async Task CreateImposter()
 {
     _imposter = _client.CreateHttpImposter(ImposterPort);
     await _client.SubmitAsync(_imposter).ConfigureAwait(false);
 }
Ejemplo n.º 18
0
        public void Constructor_InitializesStubsCollection()
        {
            var imposter = new HttpImposter(123, null);

            Assert.IsNotNull(imposter.Stubs);
        }
Ejemplo n.º 19
0
        public void Constructor_AllowsNullPort()
        {
            var imposter = new HttpImposter(null, null);

            Assert.AreEqual(default(int), imposter.Port);
        }
Ejemplo n.º 20
0
 private void CreateImposter()
 {
     _imposter = _client.CreateHttpImposter(ImposterPort);
     _client.Submit(_imposter);
 }
Ejemplo n.º 21
0
        public void Constructor_SetsProtocol()
        {
            var imposter = new HttpImposter(123, null);

            Assert.AreEqual("http", imposter.Protocol);
        }
Ejemplo n.º 22
0
 public void SetUp()
 {
     Global.MountebankClient.DeleteImposter(8095);
     _imposter = Global.MountebankClient.CreateHttpImposter(8095);
 }