//[ExpectedException(typeof(AssertFailedException))] protected void any_IFakeServer_should_verified_received_request() { using (IFakeServer fakeserver = BuildTestingServer()) { fakeserver.ShouldReceived(); fakeserver.CheckAllReceiverConditional(); } }
protected void any_IFakeServer_should_return_set_response() { using (IFakeServer fakeserver = BuildTestingServer()) { fakeserver.ShouldReceived().Post(REQUEST_SAMPLE_BODY).Response(RESPONSE_SEMPLE_BODY); var response = HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY); Assert.AreEqual(RESPONSE_SEMPLE_BODY, response); } }
protected void any_IFakeServer_should_stop_without_exception() { IFakeServer fakeserver = BuildTestingServer(); fakeserver.ShouldReceived().Post(REQUEST_SAMPLE_BODY).Response(RESPONSE_SEMPLE_BODY); var response = HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY); Assert.AreEqual(RESPONSE_SEMPLE_BODY, response); fakeserver.CheckAllReceiverConditional(); fakeserver.StopServer(); }
public static IFakeServer CreateServer(PaymentType paymentType, IAccountDetails account) { IFakeServer fakeServer = paymentType switch { PaymentType.BitCoin when account.CanHandle(paymentType) => new FakeBitCoinPaymentServer(), PaymentType.PayPal when account.CanHandle(paymentType) => new FakePayPalPaymentServer(), PaymentType.DebitCard when account.CanHandle(paymentType) => new FakeDirectDebitPaymentServer("ROTE-0001UK"), _ => throw new ArgumentOutOfRangeException(nameof(paymentType), paymentType, null) }; return(fakeServer); } }
protected void any_IFakeServer_should_return_set_response_headers() { const string EXAMPLE_HEADER_KEY = "Content-Type"; const string EXAMPLE_HEADER_VALUE = "text/xml"; string[] exampleResponseHeaders = new string[] { EXAMPLE_HEADER_KEY + ": " + EXAMPLE_HEADER_VALUE }; using (IFakeServer fakeserver = BuildTestingServer()) { fakeserver.ShouldReceived().Post(REQUEST_SAMPLE_BODY).Response(RESPONSE_SEMPLE_BODY, exampleResponseHeaders); WebHeaderCollection responseHeaders = null; HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY, out responseHeaders); Assert.AreEqual(EXAMPLE_HEADER_VALUE, responseHeaders[EXAMPLE_HEADER_KEY], "Wrong value in actual response headers"); } }
internal void any_IFakeServer_should_able_to_set_default_response() { using (IFakeServer fakeserver = BuildTestingServer()) { const string DEFAAULT_RESPONSE = "example of de"; const string HEADER_KEY = "Content-Type"; const string HEADER_VAL = "text/xml"; string[] headers = { HEADER_KEY + ": " + HEADER_VAL }; WebHeaderCollection responseHeaders = null; fakeserver.SetDefaultResponse(DEFAAULT_RESPONSE, headers); string response = HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY, out responseHeaders); Assert.AreEqual(DEFAAULT_RESPONSE, response); Assert.AreEqual(HEADER_VAL, responseHeaders[HEADER_KEY]); } }
public void FakeServer_should_able_to_compare_XML_body_with_different_representation() { const string EXPECTED_XML = "<?xml version=\"1.0\" encoding=\"utf - 8\"?><some-tag>value of some tag</some-tag>"; const string ACTUAL_XML = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\n" + " <!-- some comment -->\n" + " <some-tag>value of some tag</some-tag>"; fakeserver = new FakeHttpServer(LISTNED_HOST); fakeserver.ShouldReceived(new XMLReceiverConditional()).Post(EXPECTED_XML).Response(SUCCESS_RESPONSE); string actualResponse = HttpSender.SendPost(LISTNED_HOST, ACTUAL_XML); Assert.AreEqual(SUCCESS_RESPONSE, actualResponse, "Wrong response"); fakeserver.CheckAllReceiverConditional(); }
protected void any_IFakeServer_should_return_deffault_message_for_no_mathced_requests() { IFakeServer fakeserver = BuildTestingServer(); fakeserver.ShouldReceived(); string actualDeffaultMessage = HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY); Assert.AreEqual(AFakeServer.DEFAULT_RESPONSE_BODY, actualDeffaultMessage, "Wrong DeffaultMessage"); try { fakeserver.StopServer(); } catch (Exception) { //Сервер должен сказать что не все запросы пришли. Но в данном тесте это не проверяется. } }
protected void any_IFakeServer_should_able_to_get_history_of_ricivers_messages() { IFakeServer fakeserver = BuildTestingServer(); fakeserver.ShouldReceived(); HttpSender.SendPost(ListenedFakeServerURL, REQUEST_SAMPLE_BODY); string[] actualReceiveMessages = fakeserver.GetReceiveHistory(); Assert.AreEqual(1, actualReceiveMessages.Length, "Wrong count of element for array was returned by method GetReceiveHistory"); Assert.AreEqual(REQUEST_SAMPLE_BODY, actualReceiveMessages[0], "Wrong content of element for array was returned by method GetReceiveHistory"); try { fakeserver.StopServer(); } catch (Exception) { //Сервер должен сказать что не все запросы пришли. Но в данном тесте это не проверяется. } }
public void FakeServer_should_able_to_compare_XML_body_with_ignore_some_node() { const string EXPECTED_XML = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\n" + " <root>\n" + " <some-tag>value of some tag</some-tag>\n" + " <ignored-node>#:={Ignore the node}</ignored-node>" + " </root>"; const string ACTUAL_XML = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>\n" + " <root>\n" + " <ignored-node>some value</ignored-node>\n" + " <some-tag>value of some tag</some-tag>\n" + " </root>"; fakeserver = new FakeHttpServer(LISTNED_HOST); //For this fiture should use XMLWithIgnoreNodeRreceiverConditional fakeserver.ShouldReceived(new XMLWithIgnoreNodeReceiverConditional()).Post(EXPECTED_XML).Response(SUCCESS_RESPONSE); string actualResponse = HttpSender.SendPost(LISTNED_HOST, ACTUAL_XML); Assert.AreEqual(SUCCESS_RESPONSE, actualResponse, "Wrong response"); fakeserver.CheckAllReceiverConditional(); }
protected override IFakeServer BuildTestingServer() { SoapRemoteFakeServer = SoapHttpRemoteServer.TakeListenHost(ListenedFakeServerURL, RemotServerManagerHost); return(SoapRemoteFakeServer); }