public async Task PostProfileEndpointsForNewArticleMetaDataReturnsOk() { // Arrange var documentId = Guid.NewGuid(); string canonicalName = documentId.ToString().ToUpperInvariant(); const string postUrl = "/profile"; var jobProfileModel = new Data.Models.JobProfileModel() { JobProfileId = documentId, CanonicalName = canonicalName, SocLevelTwo = "12", LastReviewed = DateTime.UtcNow, BreadcrumbTitle = "This is my breadcrumb title", IncludeInSitemap = true, AlternativeNames = new string[] { "jp1", "jp2" }, MetaTags = new MetaTags { Title = $"This is a title for {canonicalName}", Description = "This is a description", Keywords = "some keywords or other", }, SequenceNumber = 1, }; var client = factory.CreateClient(); client.DefaultRequestHeaders.Accept.Clear(); var response = await client.PostAsync(postUrl, jobProfileModel, new JsonMediaTypeFormatter()).ConfigureAwait(false); // Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.Created); }
public async Task DeleteProfileEndpointsReturnSuccessWhenFound() { // Arrange var documentId = Guid.NewGuid(); const string postUrl = "/profile"; var deleteUri = new Uri($"/profile/{documentId}", UriKind.Relative); var jobProfileModel = new Data.Models.JobProfileModel() { DocumentId = documentId, CanonicalName = documentId.ToString().ToUpperInvariant(), SocLevelTwo = "12", LastReviewed = DateTime.UtcNow, IncludeInSitemap = true, MetaTags = new MetaTags { Title = $"This is a title", }, SequenceNumber = 1, }; var client = factory.CreateClient(); client.DefaultRequestHeaders.Accept.Clear(); _ = await client.PostAsync(postUrl, jobProfileModel, new JsonMediaTypeFormatter()).ConfigureAwait(false); // Act var response = await client.DeleteAsync(deleteUri).ConfigureAwait(false); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task JobProfileServiceGetByNameReturnsNullWhenMissingInRepository() { // arrange Data.Models.JobProfileModel expectedResult = null; A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).Returns(expectedResult); // act var result = await jobProfileService.GetByNameAsync("article-name").ConfigureAwait(false); // assert A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public void ProfileServiceGetByAlternativeNameReturnsNullWhenMissingRepository() { // arrange const string alternativeName = "name1"; Data.Models.JobProfileModel expectedResult = null; A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).Returns(expectedResult); // act var result = jobProfileService.GetByAlternativeNameAsync(alternativeName).Result; // assert A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task <HttpStatusCode> Create(Data.Models.JobProfileModel jobProfileModel) { if (jobProfileModel == null) { throw new ArgumentNullException(nameof(jobProfileModel)); } jobProfileModel.MetaTags = jobProfileModel.MetaTags is null ? new MetaTags() : jobProfileModel.MetaTags; jobProfileModel.Segments = jobProfileModel.Segments is null ? new List <SegmentModel>() : jobProfileModel.Segments; var existingRecord = await GetByIdAsync(jobProfileModel.DocumentId).ConfigureAwait(false); if (existingRecord != null) { return(HttpStatusCode.AlreadyReported); } return(await repository.UpsertAsync(jobProfileModel).ConfigureAwait(false)); }
public async Task ProfileControllerDocumentHtmlAndJsonReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange var documentId = Guid.NewGuid(); Data.Models.JobProfileModel expectedResult = null; var controller = BuildProfileController(mediaTypeName); A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult); // Act var result = await controller.Profile(documentId).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NoContentResult>(result); Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
public async Task JobProfileControllerHeadJsonReturnsSuccessWhenNoData(string mediaTypeName) { // Arrange const string article = "an-article-name"; Data.Models.JobProfileModel expectedResult = null; var controller = BuildProfileController(mediaTypeName); A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Head(article).ConfigureAwait(false); // Assert A.CallTo(() => FakeJobProfileService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); var jsonResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <HeadViewModel>(jsonResult.Value); model.CanonicalUrl.Should().BeNull(); controller.Dispose(); }
public async Task <HttpStatusCode> Update(Data.Models.JobProfileModel jobProfileModel) { if (jobProfileModel == null) { throw new ArgumentNullException(nameof(jobProfileModel)); } var existingRecord = await GetByIdAsync(jobProfileModel.DocumentId).ConfigureAwait(false); if (existingRecord is null) { return(HttpStatusCode.NotFound); } if (existingRecord.SequenceNumber > jobProfileModel.SequenceNumber) { return(HttpStatusCode.AlreadyReported); } var mappedRecord = mapper.Map(jobProfileModel, existingRecord); return(await repository.UpsertAsync(mappedRecord).ConfigureAwait(false)); }
public async Task PatchProfileEndpointsForNewArticleMetaDataPatchReturnsAlreadyReported() { // Arrange var documentId = Guid.NewGuid(); string canonicalName = documentId.ToString().ToUpperInvariant(); const string postUrl = "/profile"; string patchUrl = $"/profile/{documentId}/metadata"; var jobProfileModel = new Data.Models.JobProfileModel() { JobProfileId = documentId, CanonicalName = canonicalName, SocLevelTwo = "12", LastReviewed = DateTime.UtcNow, BreadcrumbTitle = "This is my breadcrumb title", IncludeInSitemap = true, AlternativeNames = new string[] { "jp1", "jp2" }, MetaTags = new MetaTags { Title = $"This is a title for {canonicalName}", Description = "This is a description", Keywords = "some keywords or other", }, SequenceNumber = 1, }; var jobProfileMetaDataPatchModel = new JobProfileModel() { JobProfileId = documentId, CanonicalName = canonicalName, SocLevelTwo = "12", LastReviewed = DateTime.UtcNow, BreadcrumbTitle = "This is my patched breadcrumb title", IncludeInSitemap = true, AlternativeNames = new string[] { "jp1", "jp2" }, MetaTags = new MetaTags { Title = $"This is a patch title for {canonicalName}", Description = "This is a patch description", Keywords = "some keywords or other", }, SequenceNumber = jobProfileModel.SequenceNumber - 1, }; var client = factory.CreateClient(); client.DefaultRequestHeaders.Accept.Clear(); _ = await client.PostAsync(postUrl, jobProfileModel, new JsonMediaTypeFormatter()).ConfigureAwait(false); using (var request = new HttpRequestMessage(HttpMethod.Patch, patchUrl)) { request.Headers.Accept.Clear(); request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json)); request.Content = new ObjectContent(typeof(JobProfileModel), jobProfileMetaDataPatchModel, new JsonMediaTypeFormatter(), MediaTypeNames.Application.Json); // Act var response = await client.SendAsync(request).ConfigureAwait(false); // Assert response.EnsureSuccessStatusCode(); response.StatusCode.Should().Be(HttpStatusCode.AlreadyReported); } }