public async Task GetReturnsProfileForSpecifiedIdTest() { var account = Model.Create <Account>(); var profile = Model.Create <ExportProfile>(); var user = ClaimsIdentityFactory.BuildPrincipal(account); var query = Substitute.For <IExportQuery>(); var httpContext = Substitute.For <HttpContext>(); httpContext.User = user; var routerData = new RouteData(); var actionDescriptor = new ControllerActionDescriptor(); var actionContext = new ActionContext(httpContext, routerData, actionDescriptor); var controllerContext = new ControllerContext(actionContext); using (var tokenSource = new CancellationTokenSource()) { query.GetExportProfile(account.Id, tokenSource.Token).Returns(profile); using (var target = new ExportController(query)) { target.ControllerContext = controllerContext; var actual = await target.Get(tokenSource.Token).ConfigureAwait(false); actual.Should().BeOfType <OkObjectResult>(); var result = actual.As <OkObjectResult>(); result.Value.Should().BeEquivalentTo(profile); } } }
public async Task GetReturnsNotFoundWhenQueryReturnsNullTest() { var account = Model.Create <Account>(); var user = ClaimsIdentityFactory.BuildPrincipal(account); var query = Substitute.For <IExportQuery>(); var httpContext = Substitute.For <HttpContext>(); httpContext.User = user; var routerData = new RouteData(); var actionDescriptor = new ControllerActionDescriptor(); var actionContext = new ActionContext(httpContext, routerData, actionDescriptor); var controllerContext = new ControllerContext(actionContext); using (var tokenSource = new CancellationTokenSource()) { using (var target = new ExportController(query)) { target.ControllerContext = controllerContext; var actual = await target.Get(tokenSource.Token).ConfigureAwait(false); actual.Should().BeOfType <ErrorMessageResult>().Which.StatusCode.Should().Be((int)HttpStatusCode.NotFound); } } }
public void export_as_csv_sanity_check() { var controller = new ExportController(new RecordQueryer(Db)); var input = new RecordQueryInputModel { Q = "", F = new FilterOptions { Keywords = new[] { "vocab.jncc.gov.uk/jncc-category/Seabed Habitat Maps" } }, P = 0, N = -1 }; var result = controller.Get(input, "CSV"); var task = (PushStreamContent)result.Content; var content = task.ReadAsStringAsync().Result; content.Should().NotBeNullOrWhiteSpace(); var matches = Regex.Matches(content, @"""""Value"""":""""GB\d{6}"""""); // match a mesh identifier e.g. GB000272 matches.Count.Should().Be(189); // the number of mesh records }
public void GetWillCallZipperMethodsAndDbMethods() { //Arrange var allStudents = new List <Student> { new StudentBuilder().Build() }; _studentRepoMock.Setup(repo => repo.GetAllStudents()).Returns(allStudents); //Act var result = _controller.Get() as SkeletResponse; //Assert Assert.That(result, Is.Not.Null); _studentRepoMock.Verify(repo => repo.GetAllStudents(), Times.Once); }
// [Test] public void export_with_format_filter() { var controller = new ExportController(Db, new RecordQueryer(Db)); var input = new RecordQueryInputModel { Q = "sea", F = new FilterOptions { DataFormats = new[] { "Other" } }, P = 0, N = 15 }; var result = controller.Get(input, "csv"); var task = (PushStreamContent)result.Content; string content = task.ReadAsStringAsync().Result; content.Should().Contain("A simple Overseas Territories example record"); Regex.Matches(content, @"\r\n").Count.Should().Be(2); // 2 new lines means only one record }