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 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 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 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 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); }
public void TestPlaybackWithOneClient() { HttpMockServer.RecordsDirectory = currentDir; HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Record); FakeHttpClient client1 = CreateClient(); var result1A = client1.DoStuffA().Result; var result1B = client1.DoStuffB().Result; string assetName1 = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); string assetName2 = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.None); FakeHttpClient client2 = CreateClientWithBadResult(); var result2 = client2.DoStuffA().Result; HttpMockServer.Flush(currentDir); HttpMockServer.Initialize(this.GetType(), TestUtilities.GetCurrentMethodName(), HttpRecorderMode.Playback); FakeHttpClient client3 = CreateClientWithBadResult(); var result3B = client3.DoStuffB().Result; var result3A = client3.DoStuffA().Result; string assetName1Playback = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); string assetName2Playback = HttpMockServer.GetAssetName(TestUtilities.GetCurrentMethodName(), "tst"); 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(HttpStatusCode.Conflict, result2.StatusCode); Assert.Equal(assetName1, assetName1Playback); Assert.Equal(assetName2, assetName2Playback); }