public async Task GetResponseAsString_NotFoundResponse() { //arrange var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("[{'id':1,'value':'1'}]") }) .Verifiable(); var srv = new HttpServiceClient(new HttpClient(handlerMock.Object)); //act var request = srv.CreateRequest(HttpMethod.Post, "https://mock/users"); var result = await srv.GetResponseAsStringAsync(request).ConfigureAwait(false); //assert Assert.IsNull(result); }
public async Task GetResponseAsStream_NullResponse() { //arrange var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new ByteArrayContent(new byte[0]) }) .Verifiable(); var srv = new HttpServiceClient(new HttpClient(handlerMock.Object)); //act var request = srv.CreateRequest(HttpMethod.Post, "https://mock/users"); var result = await srv.GetResponseAsStreamAsync(request).ConfigureAwait(false); //assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Length); }
private async static void GetHttpRepoFiles(SourceTypes sourceTypes, bool isUpdated, bool findLast = false) { var fileTypeConfiguration = process.FindFileTypeConfiguration(sourceTypes); var repoPath = findLast ? Path.Combine(process.Configuration.RepoBaseUrl, fileTypeConfiguration.RepoRelativeFilePath) : Path.Combine(process.Configuration.RepoBaseUrl, fileTypeConfiguration.RepoRelativeFilePath, fileTypeConfiguration.RepoFileName); var(result, dateTime) = await HttpServiceClient.GetAsync(new Uri(repoPath)); var sourcePath = Path.Combine(process.Configuration.SourceBasePath, fileTypeConfiguration.SourceFileName); if (findLast) { var fileNameToSearch = $"{DateTime.Today:MM-dd-yyyy}.csv"; Trace.TraceInformation(fileNameToSearch); repoPath = Directory.GetFiles(repoPath) .Where(f => f.EndsWith(".csv")) .OrderBy(f => f) .LastOrDefault(); } Trace.TraceInformation(repoPath); isUpdated = fileTypeConfiguration.LastUpdate != null? File.GetLastWriteTime(repoPath) > fileTypeConfiguration.LastUpdate: true; if (isUpdated) { fileTypeConfiguration.LastUpdate = File.GetLastWriteTime(repoPath); process.Configuration.Write(configurationFilePath); File.Copy(repoPath, sourcePath, true); } }
public void SerializeNull() { //arrange var srv = new HttpServiceClient(HttpClientFactory.CreateHttpClient()); //act var result = srv.Serialize(null); //assert Assert.IsNull(result); }
public void SerializeIncompatibleContent() { //arrange var srv = new HttpServiceClient(HttpClientFactory.CreateHttpClient()); //act var result = srv.Serialize(new object()); //assert Assert.IsNull(result); }
private async Task <bool> SynchronizeBookById(int idBook) { var book = JsonConvert.DeserializeObject <Book>(await HttpServiceClient.Get(fakeServiceUrlBase + "Books/" + idBook.ToString())); if (book.Id == 0) { return(false); } await UnitOfWork.Books.InsertAsync(book); return(UnitOfWork.SaveChanges() > 0); }
public void SerializeByteArray() { //arrange var srv = new HttpServiceClient(HttpClientFactory.CreateHttpClient()); var str = "Hello World!"; var content = Encoding.ASCII.GetBytes(str); //act var result = srv.Serialize(content); //assert Assert.IsNotNull(result); Assert.AreEqual(typeof(ByteArrayContent), result.GetType()); }
public BaseTest(MockHttpClientFixture mockHttpClientFixture) { MockHttpClientFixture = mockHttpClientFixture; var httpClient = new HttpServiceClient( new HttpClient(MockHttpClientFixture.MockHandler.Object) { BaseAddress = new Uri("https://sandbox.transactions.globallypaid.com") }); Client = new HttpServiceClient(httpClient); MockHttpClientFixture.Reset(); }
private async Task <bool> SynchronizeBooks() { var books = JsonConvert.DeserializeObject <List <Book> >(await HttpServiceClient.Get(fakeServiceUrlBase + "Books")); foreach (var book in books) { if (!UnitOfWork.Books.BookExist(book.Id)) { await UnitOfWork.Books.InsertAsync(book); } } return(UnitOfWork.SaveChanges() > 0); }
public void SerializeStream() { //arrange var srv = new HttpServiceClient(HttpClientFactory.CreateHttpClient()); var str = "Hello World!"; using (Stream content = new MemoryStream(Encoding.ASCII.GetBytes(str))) { //act var result = srv.Serialize(content); //assert Assert.IsNotNull(result); Assert.AreEqual(typeof(StreamContent), result.GetType()); } }
public async Task <AuthenticationResult> LoginUser(User user) { var users = JsonConvert.DeserializeObject <List <User> >(await HttpServiceClient.Get(fakeServiceUrlBase + "Users")); if (users.Count(p => p.UserName == user.UserName && p.Password == user.Password) > 0) { return(GenerateAuthenticationResultForUserAsync(user)); } else { return(new AuthenticationResult { Errors = new[] { "User doesn't exist." } }); } }
private async Task <bool> SynchronizeAuthors() { var authors = JsonConvert.DeserializeObject <List <Author> >(await HttpServiceClient.Get(fakeServiceUrlBase + "Authors")); foreach (var author in authors) { if (!UnitOfWork.Authors.AuthorExist(author.Id)) { if (!UnitOfWork.Books.BookExist(author.IdBook)) { await SynchronizeBookById(author.IdBook); } await UnitOfWork.Authors.InsertAsync(author); } } return(UnitOfWork.SaveChanges() > 0); }
public RecyclingCenterController() { _serviceClient = new HttpServiceClient <RecyclingCenter>("http://localhost:5050/api/RecyclingCenter/"); }
public TaxaJurosControllerTests() { _serviceClient = NativeInjectorBootStrapper.GetInstance <HttpServiceClient>(); _serviceClient.Should().NotBeNull(); }
public SkatController() { _serviceClient = new HttpServiceClient <Vehicle>("http://localhost:5030/api/Skat"); }
public VehicleController() { _serviceClient = new HttpServiceClient <Vehicle>("http://localhost:5040/api/Vehicle/"); }
public BackplaneIntegrationTests() { _httpClient = new HttpServiceClient(new TestUrlProvider()); }
public MockHttpClientFixture() { MockHandler = new Mock <HttpMessageHandler>(); HttpClient = new HttpServiceClient(new HttpClient(MockHandler.Object)); }