static void Main(string[] args) { var task = Task.Run(async() => { Console.WriteLine("Starting test"); var path = "api/person/{id}/details"; var mockApi = new MockApiClient("http://localhost:5000"); await mockApi.Setup("GET", path).Returns("{id: {id}}"); // Perfom an action var result = await "http://localhost:5000/api/person/12/details".GetAsync().ReceiveString(); var calls = (await mockApi.Calls("GET", path)).ToList(); Console.WriteLine(calls.Count); // Assert the number of calls made to the end point Console.WriteLine(calls[0].Path); // Assert the actual path (for checking url params) //Console.WriteLine(calls[0].Body.SelectToken("request.accounts[0].id")); // Assert information sent in the request Console.ReadLine(); }); task.Wait(); Console.WriteLine("Test complete"); }
public void Test_GetDpuBreakdown() { MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}", 200, 150)); Definition def = new Definition(m_user, TestData.definition); Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly"); Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash"); MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"detail\":{\"contains\":{\"count\":1,\"dpu\":4,\"targets\":{\"interaction.content\":{\"count\":1,\"dpu\":4}}}},\"dpu\":4}", 200, 150)); Dpu dpu = def.getDpuBreakdown(); Assert.AreEqual(4, dpu.getTotal(), "The total DPU is incorrect"); Assert.AreEqual(1, dpu.getDpu().Count, "Incorrect number of detail items"); Assert.AreEqual(1, dpu.getDpu()["contains"].getCount(), "Incorrect count for contains"); Assert.AreEqual(4, dpu.getDpu()["contains"].getDpu(), "Incorrect DPU for contains"); Assert.AreEqual(1, dpu.getDpu()["contains"].getTargets()["interaction.content"].getCount(), "Incorrect count for interaction.content"); Assert.AreEqual(4, dpu.getDpu()["contains"].getTargets()["interaction.content"].getDpu(), "Incorrect DPU for interaction.content"); }
public void OAuth2Token_SetByClientIdConstructor_AreSame() { var oAuth2Token = MockOAuth2Token.GetOAuth2Token(); var client = new MockApiClient("ClientId", oAuth2Token); Assert.Same(oAuth2Token, client.OAuth2Token); }
public void Test_CompileSuccess() { MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}", 200, 150)); Definition def = new Definition(m_user, TestData.definition); Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly"); try { def.compile(); } catch (InvalidDataException e) { Assert.Fail("InvalidDataException: " + e.Message); } catch (CompileFailedException e) { Assert.Fail("CompileFailedException: " + e.Message); } catch (ApiException e) { Assert.Fail("ApiException: " + e.Message); } Assert.AreEqual(200, m_user.getRateLimit(), "Incorrect rate limit"); Assert.AreEqual(150, m_user.getRateLimitRemaining(), "Incorrect rate limit remaining"); Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash"); Assert.AreEqual(DateTime.ParseExact("2011-12-13 14:15:16", "yyyy-MM-dd HH:mm:ss", null), def.getCreatedAt(), "Incorrect created at date"); Assert.AreEqual(10, def.getTotalDpu(), "Incorrect total DPU"); }
public void Test_CompileFailure() { MockApiClient.setAPIResponse( new ApiResponse( 400, "{\"error\":\"The target interactin.content does not exist\"}", 200, 150)); Definition def = new Definition(m_user, TestData.invalid_definition); Assert.AreEqual(TestData.invalid_definition, def.get(), "Definition CSDL not set correctly"); try { def.compile(); Assert.Fail("Expected CompileFailedException was not thrown"); } catch (InvalidDataException e) { Assert.Fail("InvalidDataException: " + e.Message); } catch (CompileFailedException e) { Assert.AreEqual("The target interactin.content does not exist", e.Message, "Incorrect compile error message in the CompileFailedException"); } catch (ApiException e) { Assert.Fail("ApiException: " + e.Message); } }
public void OAuth2Token_SetBySetOAuth2Token_AreSame() { var oAuth2Token = MockOAuth2Token.GetOAuth2Token(); var client = new MockApiClient("ClientId", "ClientSecret"); Assert.Null(client.OAuth2Token); client.SetOAuth2Token(oAuth2Token); Assert.Same(oAuth2Token, client.OAuth2Token); }
public void Test_RateLimits() { MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}", 200, 150)); Definition def = m_user.createDefinition(TestData.definition); def.compile(); Assert.AreEqual(200, m_user.getRateLimit(), "Rate limit is incorrect"); Assert.AreEqual(150, m_user.getRateLimitRemaining(), "Rate limit remaining is incorrect"); }
public void Test_GetUsage() { MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"start\":\"Mon, 07 Nov 2011 10:25:00 +0000\",\"end\":\"Mon, 07 Nov 2011 11:25:00 +0000\",\"streams\":{\"6fd9d61afba0149e0f1d42080ccd9075\":{\"licenses\":{\"twitter\":3},\"seconds\":300}}}", 200, 150)); Usage u = m_user.getUsage("day"); Assert.AreEqual(DateTime.ParseExact("2011-11-07 10:25:00", "yyyy-MM-dd HH:mm:ss", null), u.getStartDate(), "Usage start date is incorrect"); Assert.AreEqual(DateTime.ParseExact("2011-11-07 11:25:00", "yyyy-MM-dd HH:mm:ss", null), u.getEndDate(), "Usage end date is incorrect"); Assert.AreEqual(3, u.getLicenseUsage("6fd9d61afba0149e0f1d42080ccd9075", "twitter"), "Twitter license usage is incorrect"); Assert.AreEqual(300, u.getSeconds("6fd9d61afba0149e0f1d42080ccd9075"), "Usage seconds is incorrect"); }
public async void MyWebTest() { // Arrange var path = "api/person/{id}/details"; var mockApi = new MockApiClient("http://localhost:56729"); await mockApi.Setup("GET", path).Returns("{id: {id}}"); //Act - do something //Assert var calls = (await mockApi.Calls("GET", path)).ToList(); Assert.Equal(1, calls.Count); Assert.Equal("api/person/12/details", calls[0].Path); Assert.Equal("test", calls[0].Body.SelectToken("request.accounts[0].id")); }
public MockedUnleashSettings() { AppName = "test"; InstanceTag = "test instance 1"; UnleashApi = new Uri("http://localhost:4242/"); UnleashApiClient = new MockApiClient(); FileSystem = new MockFileSystem(); UnleashContextProvider = new DefaultUnleashContextProvider(new UnleashContext { UserId = "userA", SessionId = "sessionId", RemoteAddress = "remoteAddress", Properties = new Dictionary <string, string>() }); }
public void PublishTest() { // Arrange var scheduler = new TestScheduler(); var testUserIds = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; MockApiClient client = new MockApiClient(); var ticks = TimeSpan.FromMilliseconds(500).Ticks; // Act MessageProcessor messageProcessor = new MessageProcessor(client, 2, scheduler); messageProcessor.Publish(testUserIds); // Assert for (int i = 0; i < testUserIds.Count; i++) { scheduler.AdvanceBy(ticks); Assert.Equal(testUserIds[i], client.Value); } }
public void SyncConsistency() { var xmlRegistry = SyncTestHelper.GetRegistry(); var apiProjects = SyncTestHelper.GetProjects(); var apiKeywords = SyncTestHelper.GetKeywords(); var client = new MockApiClient(); client.SetProjects(apiProjects); client.SetKeywords(apiKeywords); var syncClient = new SyncClient(client); syncClient.LoadSyncObjects(); var syncProjectsCount = syncClient.SyncProjects(xmlRegistry.Projects); Assert.IsTrue(syncProjectsCount != 0); syncProjectsCount = syncClient.SyncProjects(xmlRegistry.Projects); Assert.IsTrue(syncProjectsCount == 0); var syncGroupsCount = syncClient.SyncGroups(xmlRegistry.Projects); Assert.IsTrue(syncGroupsCount != 0); syncGroupsCount = syncClient.SyncGroups(xmlRegistry.Projects); Assert.IsTrue(syncGroupsCount == 0); var syncKeywordsCount = syncClient.SyncKeywords(xmlRegistry.Projects); Assert.IsTrue(syncKeywordsCount != 0); syncKeywordsCount = syncClient.SyncKeywords(xmlRegistry.Projects); Assert.IsTrue(syncKeywordsCount == 0); }
public void Test_GetBuffered() { MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}", 200, 150)); Definition def = new Definition(m_user, TestData.definition); Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly"); Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash"); MockApiClient.setAPIResponse( new ApiResponse( 200, "{\"stream\":[{\"interaction\":{\"source\":\"Snaptu\",\"author\":{\"username\":\"nittolexia\",\"name\":\"nittosoetreznoe\",\"id\":172192091,\"avatar\":\"http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg\",\"link\":\"http://twitter.com/nittolexia\"},\"type\":\"twitter\",\"link\":\"http://twitter.com/nittolexia/statuses/89571192838684672\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\",\"content\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"id\":\"1e0a9eedc207acc0e074ea8aecb2c5ea\"},\"twitter\":{\"user\":{\"name\":\"nittosoetreznoe\",\"description\":\"f**k all\",\"location\":\"denpasar, bali\",\"statuses_count\":6830,\"followers_count\":88,\"friends_count\":111,\"screen_name\":\"nittolexia\",\"lang\":\"en\",\"time_zone\":\"Alaska\",\"id\":172192091,\"geo_enabled\":true},\"mentions\":[\"ayyuchadel\",\"nittolexia\",\"sansan_arie\"],\"id\":\"89571192838684672\",\"text\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"source\":\"<a href=\\\"http://www.snaptu.com\\\" rel=\\\"nofollow\\\">Snaptu</a>\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\"},\"klout\":{\"score\":45,\"network\":55,\"amplification\":17,\"true_reach\":31,\"slope\":0,\"class\":\"Networker\"},\"peerindex\":{\"score\":30},\"language\":{\"tag\":\"da\"}}]}", 200, 150)); Interaction[] interactions = def.getBuffered(); Assert.AreEqual("nittosoetreznoe", interactions[0].getStringVal("twitter.user.name"), "The Twitter username is incorrect"); Assert.AreEqual(89571192838684672, interactions[0].getLongVal("twitter.id"), "The Twitter ID is incorrect"); Assert.AreEqual("http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg", interactions[0].getStringVal("interaction.author.avatar"), "The author avatar is incorrect"); }
public void Test_UsageWithApiErrors() { try { MockApiClient.setAPIResponse( new ApiResponse( 400, "{\"error\":\"Bad request from user supplied data\"}", 200, 150)); Usage u = m_user.getUsage(); Assert.Fail("Expected ApiException not thrown"); } catch (ApiException e) { Assert.AreEqual("Bad request from user supplied data", e.Message, "400 exception messages is not as expected"); } try { MockApiClient.setAPIResponse( new ApiResponse( 401, "{\"error\":\"User banned because they are a very bad person\"}", 200, 150)); Usage u = m_user.getUsage(); Assert.Fail("Expected ApiException not thrown"); } catch (AccessDeniedException e) { Assert.AreEqual("User banned because they are a very bad person", e.Message, "401 exception messages is not as expected"); } try { MockApiClient.setAPIResponse( new ApiResponse( 404, "{\"error\":\"Endpoint or data not found\"}", 200, 150)); Usage u = m_user.getUsage(); Assert.Fail("Expected ApiException not thrown"); } catch (ApiException e) { Assert.AreEqual("Endpoint or data not found", e.Message, "404 exception messages is not as expected"); } try { MockApiClient.setAPIResponse( new ApiResponse( 500, "{\"error\":\"Problem with an internal service\"}", 200, 150)); Usage u = m_user.getUsage(); Assert.Fail("Expected ApiException not thrown"); } catch (ApiException e) { Assert.AreEqual("Problem with an internal service", e.Message, "500 exception messages is not as expected"); } }
public void ClientId_SetByConstructor_AreEqual() { var client = new MockApiClient("ClientId123", "ClientSecret123"); Assert.Equal("ClientId123", client.ClientId); }
public void Intialize() { MockApiClient = new MockApiClient(); Client = new WaniKaniClient("00000000000000000000000000000000", MockApiClient); }
public void RateLimit_AutoProperty_NotNull() { var client = new MockApiClient("ClientId", "ClientSecret"); Assert.NotNull(client.RateLimit); }