public void Constructor_SetsPort() { const int port = 123; var imposter = new HttpImposter(port, null); Assert.AreEqual(port, imposter.Port); }
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); }
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);
public void Constructor_SetsName() { const string expectedName = "Service"; var imposter = new HttpImposter(123, expectedName); Assert.AreEqual(expectedName, imposter.Name); }
public void AddStub_AddsStubToCollection() { var imposter = new HttpImposter(123, null); imposter.AddStub(); Assert.AreEqual(1, imposter.Stubs.Count); }
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); }
/// <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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void Constructor_InitializesDefaultResponse() { var imposter = new HttpImposter(123, null, defaultResponse: new HttpResponseFields()); Assert.IsNotNull(imposter.DefaultResponse); }
public void Constructor_PendingSubmissionUponCreation() { var imposter = new HttpImposter(123, null); Assert.IsTrue(imposter.PendingSubmission); }
private async Task CreateImposter() { _imposter = _client.CreateHttpImposter(ImposterPort); await _client.SubmitAsync(_imposter).ConfigureAwait(false); }
public void Constructor_InitializesStubsCollection() { var imposter = new HttpImposter(123, null); Assert.IsNotNull(imposter.Stubs); }
public void Constructor_AllowsNullPort() { var imposter = new HttpImposter(null, null); Assert.AreEqual(default(int), imposter.Port); }
private void CreateImposter() { _imposter = _client.CreateHttpImposter(ImposterPort); _client.Submit(_imposter); }
public void Constructor_SetsProtocol() { var imposter = new HttpImposter(123, null); Assert.AreEqual("http", imposter.Protocol); }
public void SetUp() { Global.MountebankClient.DeleteImposter(8095); _imposter = Global.MountebankClient.CreateHttpImposter(8095); }