public void TestPlaybackWithAssetInUrlClient() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); string assetName1 = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); string assetName2 = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); var result1A = client1.DoStuffX(assetName1).Result; var result1B = client1.DoStuffX(assetName2).Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClientWithBadResult(); string assetName1Playback = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); string assetName2Playback = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); var result3A = client3.DoStuffX(assetName1Playback).Result; var result3B = client3.DoStuffX(assetName2Playback).Result; HttpMockServer.Flush(currentDir); string result1AConent = JObject.Parse(result1A.Content.ReadAsStringAsync().Result).ToString(); string result3AConent = JObject.Parse(result3A.Content.ReadAsStringAsync().Result).ToString(); Assert.True(File.Exists(Path.Combine(HttpMockServer.CallerIdentity, TestUtilities.GetCurrentMethodName() + ".json"))); Assert.Equal(result1A.StatusCode, result3A.StatusCode); Assert.Equal(result1A.RequestMessage.RequestUri.AbsoluteUri, result3A.RequestMessage.RequestUri.AbsoluteUri); Assert.Equal(result1AConent, result3AConent); Assert.Equal(assetName1, assetName1Playback); Assert.Equal(assetName2, assetName2Playback); }
public void NotFoundExceptionContainUrlAndMethodName() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var resultCOrig = client1.DoStuffC("test", "123", "abc").Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClient(); try { var r = client1.DoStuffC("test", "123", "xyz").Result; Assert.False(true); } catch (AggregateException aggregateException) { var exception = aggregateException.InnerExceptions[0]; //TODO: figure out whether exception message ever mentioned 'DoStuffC' Assert.Equal("Unable to find a matching HTTP request for URL 'POST /path/to/resourceB?api-version=xyz (x-ms-version=123)'. Calling method Item().", exception.Message); } }
public void TestRecordingWithOneClientWritesFile() { HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client = CreateClient(); var result = client.DoStuffA().Result; HttpMockServer.Flush(currentDir); Assert.True(File.Exists(Path.Combine(HttpMockServer.CallerIdentity, TestUtilities.GetCurrentMethodName() + ".json"))); }
public void NoneModeCreatesNoFiles() { HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.None); FakeHttpClient client = CreateClient(); var result = client.DoStuffA().Result; HttpMockServer.Flush(currentDir); Assert.False(File.Exists(TestUtilities.GetCurrentMethodName() + ".json")); }
public void TestRecordingWithExplicitDir() { HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); HttpMockServer.RecordsDirectory = Path.GetTempPath(); FakeHttpClient client = CreateClient(); var result = client.DoStuffA().Result; HttpMockServer.Flush(); Assert.True(File.Exists(Path.Combine(Path.GetTempPath(), this.GetType().Name, TestUtilities.GetCurrentMethodName() + ".json"))); HttpMockServer.RecordsDirectory = currentDir; }
public void PlaybackWithDifferentContentTypeDoesNotMatch() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var resultCOrig = client1.DoStuffD("text/json").Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClient(); Assert.Throws <AggregateException>(() => client1.DoStuffD("text/xml").Result); }
public void PlaybackWithSameContentTypeMatches() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var resultDOrig = client1.DoStuffD("text/json").Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClient(); var resultDPlayback = client1.DoStuffD("text/json").Result; Assert.Equal(resultDOrig.RequestMessage.RequestUri, resultDPlayback.RequestMessage.RequestUri); }
public void TestRecordingWithVariablesStoresVariable() { HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client = CreateClient(); var result = client.DoStuffA().Result; HttpMockServer.Variables["varA"] = "varA-value"; HttpMockServer.Flush(currentDir); HttpMockServer.Variables.Clear(); var recording = RecordEntryPack.Deserialize(Path.Combine(HttpMockServer.CallerIdentity, TestUtilities.GetCurrentMethodName() + ".json")); Assert.Equal("varA-value", recording.Variables["varA"]); }
public void TestRecordingWithTwoMethodsWithoutFlushing() { HttpMockServer.Initialize(this.GetType(), "testA", HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); FakeHttpClient client2 = CreateClient(); var result1 = client1.DoStuffA().Result; var result2 = client2.DoStuffA().Result; HttpMockServer.Initialize(this.GetType(), "testB", HttpRecorderMode.Record); FakeHttpClient client3 = CreateClient(); var result3 = client3.DoStuffA().Result; HttpMockServer.Flush(currentDir); Assert.True(File.Exists(Path.Combine(HttpMockServer.CallerIdentity, "testB.json"))); }
public void TestRecordingWithTwoMethodsWritesAllData() { HttpMockServer.Initialize(this.GetType(), "testA", HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); FakeHttpClient client2 = CreateClient(); var result1 = client1.DoStuffA().Result; var result2 = client2.DoStuffA().Result; var name = HttpMockServer.GetAssetName("testA", "tst"); HttpMockServer.Flush(currentDir); RecordEntryPack pack = RecordEntryPack.Deserialize(Path.Combine(HttpMockServer.CallerIdentity, "testA.json")); Assert.NotNull(name); Assert.True(File.Exists(Path.Combine(HttpMockServer.CallerIdentity, "testA.json"))); Assert.Equal(2, pack.Entries.Count); Assert.Equal(1, pack.Names["testA"].Count); }
public void PlaybackWithDifferentBodyIsMatched() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var resultCOrig = client1.DoStuffC("test", "123", "abc").Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClient(); var resultCPlayback = client1.DoStuffC("different", "123", "abc").Result; HttpMockServer.Flush(currentDir); Assert.Equal(resultCOrig.RequestMessage.RequestUri, resultCPlayback.RequestMessage.RequestUri); }
public void TestRecordingWithVariablesStoresAndRetrieves() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client = CreateClient(); var result = client.DoStuffA().Result; HttpMockServer.Variables["varA"] = "varA-value"; HttpMockServer.Flush(currentDir); HttpMockServer.Variables.Clear(); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); Assert.Equal("varA-value", HttpMockServer.Variables["varA"]); }
public void VariablePersistsInARecording() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var result1 = client1.DoStuffA().Result; var value1 = HttpMockServer.GetVariable("varA", "tst123"); Assert.Equal("tst123", value1); HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); var value2 = HttpMockServer.GetVariable("varA", "tst456"); Assert.Equal("tst123", value2); }