public void ShouldSearchManualRequestHasCorrectQueryString() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <MeshNameAttributeClassTest> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <MeshNameAttributeClassTest> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); var pageNumber = new Random().Next(); var pageSize = new Random().Next(); var searchFilter = "{ 'FavoriteNumber': { '$gt': 5000 } }"; var orderBy = "{ FavoriteNumber: -1 }"; service.Search <MeshNameAttributeClassTest>(searchFilter, orderBy, pageNumber, pageSize); var encodedFilter = WebUtility.UrlEncode(searchFilter); var encodedOrderBy = WebUtility.UrlEncode("{ FavoriteNumber: -1 }"); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}?filter={encodedFilter}&orderby={encodedOrderBy}&page={pageNumber}&pageSize={pageSize}", passedUrl); requestService.VerifyAll(); }
public async Task ShouldSearchCompiledRequestHasCorrectQueryString() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <MeshNameAttributeClassTest> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <MeshNameAttributeClassTest> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); var pageNumber = new Random().Next(); var pageSize = new Random().Next(); await service.SearchAsync <MeshNameAttributeClassTest>(x => x.FavoriteNumber > 5000, OrderByDefinition <MeshNameAttributeClassTest> .OrderByDescending("FavoriteNumber"), pageNumber, pageSize).ConfigureAwait(false); var encodedFilter = WebUtility.UrlEncode("{ \"FavoriteNumber\" : { \"$gt\" : 5000 } }"); var encodedOrderBy = WebUtility.UrlEncode("{ FavoriteNumber:-1 }"); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}?filter={encodedFilter}&orderby={encodedOrderBy}&page={pageNumber}&pageSize={pageSize}", passedUrl); requestService.VerifyAll(); }
public async Task ShouldUpdateAsyncFromModelRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; var passedModel = default(MeshNameAttributeClassTest); var expectedModel = new MeshNameAttributeClassTest(); requestService.Setup(x => x.PutRequest <MeshNameAttributeClassTest>(It.IsAny <string>(), It.IsAny <object>())).Callback((string url, object model) => { passedUrl = url; passedModel = model as MeshNameAttributeClassTest; }).Returns(() => { return(Task.FromResult(It.IsAny <MeshNameAttributeClassTest>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); expectedModel.Id = id; await service.UpdateAsync(expectedModel).ConfigureAwait(false); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}/{id}", passedUrl); Assert.Equal(expectedModel, passedModel); requestService.VerifyAll(); }
public void ShouldUpdateFromModelRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; var passedModel = default(TestMeshNameFromClass); var expectedModel = new TestMeshNameFromClass(); requestService.Setup(x => x.PutRequest <TestMeshNameFromClass>(It.IsAny <string>(), It.IsAny <object>())).Callback((string url, object model) => { passedUrl = url; passedModel = model as TestMeshNameFromClass; }).Returns(() => { return(Task.FromResult(It.IsAny <TestMeshNameFromClass>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); expectedModel.Id = id; service.Update(expectedModel); Assert.Equal($"meshes/testmeshnamefromclass/{id}", passedUrl); Assert.Equal(expectedModel, passedModel); requestService.VerifyAll(); }
public async Task ShouldCreateAsyncRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; var passedModel = default(MeshNameAttributeClassTest); var passedFormat = default(RequestDataFormat); var expectedModel = new MeshNameAttributeClassTest(); requestService.Setup(x => x.PostRequest <MeshNameAttributeClassTest>(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <RequestDataFormat>())).Callback((string url, object model, RequestDataFormat format) => { passedUrl = url; passedModel = model as MeshNameAttributeClassTest; passedFormat = format; }).Returns(() => { return(Task.FromResult(It.IsAny <MeshNameAttributeClassTest>())); }).Verifiable(); var service = new MeshesService(requestService.Object); await service.CreateAsync(expectedModel).ConfigureAwait(false); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}", passedUrl); Assert.Equal(expectedModel, passedModel); Assert.Equal(RequestDataFormat.Json, passedFormat); requestService.VerifyAll(); }
public void ShouldCreateRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; var passedModel = default(TestMeshNameFromClass); var passedFormat = default(RequestDataFormat); var expectedModel = new TestMeshNameFromClass(); requestService.Setup(x => x.PostRequest <TestMeshNameFromClass>(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <RequestDataFormat>())).Callback((string url, object model, RequestDataFormat format) => { passedUrl = url; passedModel = model as TestMeshNameFromClass; passedFormat = format; }).Returns(() => { return(Task.FromResult(It.IsAny <TestMeshNameFromClass>())); }).Verifiable(); var service = new MeshesService(requestService.Object); service.Create(expectedModel); Assert.Equal($"meshes/testmeshnamefromclass", passedUrl); Assert.Equal(expectedModel, passedModel); Assert.Equal(RequestDataFormat.Json, passedFormat); requestService.VerifyAll(); }
public void ShouldCreate() { var requestService = new Mock <IRequestService>(); var service = new MeshesService(requestService.Object); Assert.NotNull(service); }
public async Task ShouldGetAsyncRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <TestMeshNameFromClass>(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <TestMeshNameFromClass>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); await service.GetDataAsync <TestMeshNameFromClass>(id).ConfigureAwait(false); Assert.Equal($"meshes/testmeshnamefromclass/{id}", passedUrl); requestService.VerifyAll(); }
public void ShouldGetRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <MeshNameAttributeClassTest>(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <MeshNameAttributeClassTest>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); service.GetData <MeshNameAttributeClassTest>(id); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}/{id}", passedUrl); requestService.VerifyAll(); }
public async Task ShouldSearchManualAsyncRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <MeshNameAttributeClassTest> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <MeshNameAttributeClassTest> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); await service.SearchAsync <MeshNameAttributeClassTest>().ConfigureAwait(false); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}?filter=&orderby=&page=1&pageSize=25", passedUrl); requestService.VerifyAll(); }
public void ShouldSearchManualRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <TestMeshNameFromClass> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <TestMeshNameFromClass> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); service.Search <TestMeshNameFromClass>(); Assert.Equal($"meshes/testmeshnamefromclass?filter=&orderby=&page=1&pageSize=25", passedUrl); requestService.VerifyAll(); }
public void ShouldSearchCompiledRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <MeshNameAttributeClassTest> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <MeshNameAttributeClassTest> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); service.Search <MeshNameAttributeClassTest>(x => true); var encodedFilter = WebUtility.UrlEncode("{ }"); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}?filter={encodedFilter}&orderby=&page=1&pageSize=25", passedUrl); requestService.VerifyAll(); }
public async Task ShouldDeleteAsyncRequestHaveCorrectMeshNameFromAttributeAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.DeleteRequest <object>(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <object>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); await service.DeleteAsync <MeshNameAttributeClassTest>(id).ConfigureAwait(false); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}/{id}", passedUrl); requestService.VerifyAll(); }
public void ShouldDeleteRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.DeleteRequest <object>(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <object>())); }).Verifiable(); var service = new MeshesService(requestService.Object); var id = Generator.RandomString(25); service.Delete <TestMeshNameFromClass>(id); Assert.Equal($"meshes/testmeshnamefromclass/{id}", passedUrl); requestService.VerifyAll(); }
public async Task ShouldSearchCompiledAsyncRequestHaveCorrectMeshNameFromClassAndUrl() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <TestMeshNameFromClass> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <TestMeshNameFromClass> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); await service.SearchAsync <TestMeshNameFromClass>(x => true).ConfigureAwait(false); var encodedFilter = WebUtility.UrlEncode("{ }"); Assert.Equal($"meshes/testmeshnamefromclass?filter={encodedFilter}&orderby=&page=1&pageSize=25", passedUrl); requestService.VerifyAll(); }