public async Task WebhooksServiceProcessConfigurationSetAsyncForUpdateReturnsSuccess() { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.OK; var expectedValidConfigurationSetApiDataModel = BuildValidConfigurationSetApiDataModel(); var expectedValidConfigurationSetModel = BuildValidConfigurationSetModel(); var url = new Uri("https://somewhere.com"); var service = BuildWebhooksService(); A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidConfigurationSetApiDataModel); A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).Returns(expectedValidConfigurationSetModel); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedValidConfigurationSetModel); A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).Returns(HttpStatusCode.OK); // Act var result = await service.ProcessConfigurationSetAsync(url).ConfigureAwait(false); // Assert A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeConfigurationSetDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened(); Assert.Equal(expectedResponse, result); }
public async Task PagesControllerDocumentReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange ConfigurationSetModel?expectedResult = null; var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Document(ConfigurationSetKeyHelper.ConfigurationSetKey).ConfigureAwait(false); // Assert A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <NoContentResult>(result); A.Equals((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
public async Task PagesControllerCallsContentPageServiceUsingPagesDocumentRouteForOkResult(string route, Guid documentId, string actionMethod, int configurationSetCount) { // Arrange var controller = BuildController(route); var expectedConfigurationSetResult = new ConfigurationSetModel() { PhoneNumber = "1234", LinesOpenText = "lines are open" }; A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedConfigurationSetResult); // Act var result = await RunControllerAction(controller, documentId, actionMethod).ConfigureAwait(false); // Assert Assert.IsType <OkObjectResult>(result); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappened(configurationSetCount, Times.Exactly); controller.Dispose(); }
public async Task PagesControllerIndexReturnsNotAcceptable(string mediaTypeName) { // Arrange var expectedConfigurationSetResults = A.Dummy <ConfigurationSetModel>(); using var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedConfigurationSetResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ConfigurationSetModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); }
public async Task PagesControllerDocumentJsonReturnsSuccess(string mediaTypeName) { // Arrange var expectedResult = A.Fake <ConfigurationSetModel>(); var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ConfigurationSetModel> .Ignored)).Returns(A.Fake <DocumentViewModel>()); // Act var result = await controller.Document(ConfigurationSetKeyHelper.ConfigurationSetKey).ConfigureAwait(false); // Assert A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly(); var jsonResult = Assert.IsType <OkObjectResult>(result); _ = Assert.IsAssignableFrom <DocumentViewModel>(jsonResult.Value); controller.Dispose(); }
public async Task PagesControllerIndexJsonReturnsSuccess(string mediaTypeName) { // Arrange var expectedConfigurationSetResults = A.Dummy <ConfigurationSetModel>(); using var controller = BuildPagesController(mediaTypeName); A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedConfigurationSetResults); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ConfigurationSetModel> .Ignored)).Returns(A.Fake <IndexDocumentViewModel>()); // Act var result = await controller.Index().ConfigureAwait(false); // Assert A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly(); var jsonResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <IndexViewModel>(jsonResult.Value); A.Equals(3, model.Documents !.Count); }
public async Task PagesControllerDocumentHtmlReturnsSuccess(string mediaTypeName) { // Arrange var expectedResult = A.Fake <ConfigurationSetModel>(); var controller = BuildPagesController(mediaTypeName); var expectedModel = new DocumentViewModel { Id = ConfigurationSetKeyHelper.ConfigurationSetKey, Title = "A title", PartitionKey = "partition-key", Url = new Uri("https://somewhere.com", UriKind.Absolute), ConfigurationSetBodyViewModel = new ConfigurationSetBodyViewModel { PhoneNumber = "1234", LinesOpenText = "lines are open" }, LastReviewed = DateTime.Now, }; A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedResult); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ConfigurationSetModel> .Ignored)).Returns(expectedModel); // Act var result = await controller.Document(expectedModel.Id).ConfigureAwait(false); // Assert A.CallTo(() => FakeConfigurationSetDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model); var model = viewResult.ViewData.Model as DocumentViewModel; Assert.Equal(expectedModel, model); controller.Dispose(); }