public void TestAddAsync_ServerAccepts_ReturnsExternalApi() { var header = new ExternalApiHeader { Name = "Header", Value = "Api header" }; var externalApi = new ExternalApi { Name = "New ExternalApi", Description = "New Description", Headers = new List <ExternalApiHeader> { header } }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); var content = new StringContent(JsonConvert.SerializeObject(externalApi)); mockedHttpClient .Setup(client => client.PostAsJsonAsync(new Uri(ServiceAddress, "externalapis/"), externalApi)) .Returns(CreateTask(HttpStatusCode.OK, content)); var target = new NfieldExternalApisService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actual = target.AddAsync(externalApi).Result; Assert.Equal(externalApi.Name, actual.Name); Assert.Equal(externalApi.Description, actual.Description); Assert.Equal(externalApi.Headers.First().Name, header.Name); Assert.Equal(externalApi.Headers.First().Value, header.Value); }
public void TestQueryAsync_ServerReturnsQuery_ReturnsListWithExternalApis() { var header1 = new ExternalApiHeader { HeaderId = 1, Name = "Header1", Value = "Api 0 header 0" }; var header2 = new ExternalApiHeader { HeaderId = 2, Name = "Header2", Value = "Api 1 header 1" }; var expectedExternalApis = new[] { new ExternalApi { Name = "TestExternalApi", Description = "Description", Headers = new List <ExternalApiHeader> { header1 } }, new ExternalApi { Name = "AnotherTestExternalApi", Description = "Another Description", Headers = new List <ExternalApiHeader> { header2 } } }; var mockedNfieldConnection = new Mock <INfieldConnectionClient>(); var mockedHttpClient = CreateHttpClientMock(mockedNfieldConnection); mockedHttpClient .Setup(client => client.GetAsync(new Uri(ServiceAddress, "externalapis/"))) .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedExternalApis)))); var target = new NfieldExternalApisService(); target.InitializeNfieldConnection(mockedNfieldConnection.Object); var actualExternalApis = target.QueryAsync().Result.ToArray(); Assert.Equal(expectedExternalApis[0].Name, actualExternalApis[0].Name); Assert.Equal(expectedExternalApis[0].Description, actualExternalApis[0].Description); Assert.Equal(expectedExternalApis[0].Headers.First().HeaderId, header1.HeaderId); Assert.Equal(expectedExternalApis[0].Headers.First().Name, header1.Name); Assert.Equal(expectedExternalApis[0].Headers.First().Value, header1.Value); Assert.Equal(expectedExternalApis[1].Name, actualExternalApis[1].Name); Assert.Equal(expectedExternalApis[1].Description, actualExternalApis[1].Description); Assert.Equal(expectedExternalApis[1].Headers.First().HeaderId, header2.HeaderId); Assert.Equal(expectedExternalApis[1].Headers.First().Name, header2.Name); Assert.Equal(expectedExternalApis[1].Headers.First().Value, header2.Value); Assert.Equal(2, actualExternalApis.Count()); }
private void SetupReadOnlyService(string url, string username) { _proxy = new ReadOnlyService(); _proxy.Url = url; ExternalApiHeader header = new ExternalApiHeader(); header.version = Config.Version; header.username = username; header.languageCode = Config.LanguageCode; _proxy.ExternalApiHeaderValue = header; }
private void SetupSecureServiceProxy(string url, string username, string password) { _proxy = new SecureService(); _proxy.Url = url; ExternalApiHeader header = new ExternalApiHeader(); header.version = Config.Version; header.username = username; header.password = password; header.languageCode = Config.LanguageCode; _proxy.ExternalApiHeaderValue = header; }