public async Task ReturnCorrectQueryParameterString() { await Task.Run(() => { var CategoryOfmCollectionResourceParameters = new CategoryOfmCollectionResourceParameters() { SearchQuery = "Chest", OrderBy = "", Ids = "1-5,8,10-12", PageNumber = 2, PageSize = 10, Fields = "Id, Name" }; var queryParameterString = CategoryOfmCollectionResourceParameters.ToQueryParameterString(); // Assert var actualQueryParameterString = queryParameterString; var expectedOfmQueryResult = "?SearchQuery=Chest&Ids=1-5,8,10-12&PageNumber=2&PageSize=10&Fields=Id, Name"; Assert.AreEqual(actualQueryParameterString, expectedOfmQueryResult); }); }
public async Task ReturnOfmQueryResultWithErrorMessasges_UsingGetCollection() { await Task.Run(async() => { // Arrange using (var testAppConfiguration = new AppConfigurationMock(File.ReadAllText(Path.GetDirectoryName(typeof(Startup).GetTypeInfo().Assembly.Location) + "\\appsettings.json"))) { // ARRANGE var httpContextAccessorMock = new Mock <IHttpContextAccessor>(); var httpRequestHandlerMock = new Mock <IHttpRequestExecuter>(); var genericAsyncGppdOfm = new CategoryApiModelRepository( testAppConfiguration.Instance, httpContextAccessorMock.Object, httpRequestHandlerMock.Object); var returnedOfmCollectionQueryResult = new Dictionary <string, object>() { { "categories", new List <string>() { "Some error message", "Some other error message" } } }; var resourceParameters = new CategoryOfmCollectionResourceParameters(); var uri = new Uri(testAppConfiguration.Instance.GetValue <string>("FittifyApiBaseUrl") + "api/categories" + resourceParameters.ToQueryParameterString()); var httpResponse = new HttpResponseMessage(); httpResponse.Content = new StringContent(JsonConvert.SerializeObject(returnedOfmCollectionQueryResult)); httpResponse.StatusCode = HttpStatusCode.BadRequest; httpRequestHandlerMock.Setup(s => s.GetCollection(uri, testAppConfiguration.Instance, httpContextAccessorMock.Object)).ReturnsAsync(httpResponse); // ACT var ofmQueryResult = await genericAsyncGppdOfm.GetCollection(resourceParameters); // Assert var actualOfmQueryResult = JsonConvert.SerializeObject(ofmQueryResult, new JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented }).MinifyJson().PrettifyJson(); var expectedOfmQueryResult = @" { ""OfmForGetCollection"": null, ""HttpStatusCode"": 400, ""HttpResponseHeaders"": [], ""ErrorMessagesPresented"": { ""categories"": [ ""Some error message"", ""Some other error message"" ] } } ".MinifyJson().PrettifyJson(); Assert.AreEqual(actualOfmQueryResult, expectedOfmQueryResult); } }); }