public async Task DetailsPost_PublishOrganisation_WhenApiReturnsTrue() { var providerCode = "PROVIDERCODE"; var viewModel = new OrganisationViewModel { AboutTrainingProviders = new List <TrainingProviderViewModel>() }; var providerName = "ProviderName"; var providerCourses = new List <Course> { new Course { }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToUpperInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToLowerInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 1, ProviderName = providerName } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 2 } }, }; var apiMock = new Mock <IManageApi>(); apiMock.Setup(x => x.GetProviderSummary(providerCode)) .ReturnsAsync(new ProviderSummary { ProviderCode = providerCode, ProviderName = providerName }); apiMock.Setup(x => x.GetCoursesOfProvider(providerCode)) .ReturnsAsync(providerCourses); var enrichmentModel = new ProviderEnrichmentModel { AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>() }; var ucasProviderEnrichmentGetModel = new UcasProviderEnrichmentGetModel() { EnrichmentModel = enrichmentModel }; apiMock.Setup(x => x.GetProviderEnrichment(providerCode)) .ReturnsAsync(ucasProviderEnrichmentGetModel); var objectValidator = new Mock <IObjectModelValidator>(); objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(), It.IsAny <ValidationStateDictionary>(), It.IsAny <string>(), It.IsAny <Object>())); apiMock.Setup(x => x.PublishAllCoursesOfProviderToSearchAndCompare(providerCode)) .ReturnsAsync(true); var frontendUrlMock = new Mock <IFrontendUrlService>(); var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object); controller.ObjectValidator = objectValidator.Object; controller.TempData = new Mock <ITempDataDictionary>().Object; var result = await controller.DetailsPost(providerCode, viewModel); var actionResult = result as RedirectToActionResult; Assert.IsNotNull(actionResult); Assert.AreEqual("Details", actionResult.ActionName); Assert.AreEqual(providerCode, actionResult.RouteValues[providerCode]); }
public void DetailsPost_PublishOrganisation_WhenApiReturnsFalse() { var providerCode = "PROVIDERCODE"; var providerName = "ProviderName"; var viewModel = new OrganisationViewModel { AboutTrainingProviders = new List <TrainingProviderViewModel>() }; var providerCourses = new List <Course> { new Course { }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToUpperInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode.ToLowerInvariant() } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 1, ProviderName = providerName } }, new Course { AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider { ProviderCode = providerCode + 2 } }, }; var apiMock = new Mock <IManageApi>(); apiMock.Setup(x => x.GetProviderSummary(providerCode)) .ReturnsAsync(new ProviderSummary { ProviderCode = providerCode, ProviderName = providerName }); apiMock.Setup(x => x.GetCoursesOfProvider(providerCode)) .ReturnsAsync(providerCourses); var enrichmentModel = new ProviderEnrichmentModel { AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment> { } }; var ucasProviderEnrichmentGetModel = new UcasProviderEnrichmentGetModel() { EnrichmentModel = enrichmentModel }; apiMock.Setup(x => x.GetProviderEnrichment(providerCode)) .ReturnsAsync(ucasProviderEnrichmentGetModel); var objectValidator = new Mock <IObjectModelValidator>(); objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(), It.IsAny <ValidationStateDictionary>(), It.IsAny <string>(), It.IsAny <Object>())); var frontendUrlMock = new Mock <IFrontendUrlService>(); var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object); controller.ObjectValidator = objectValidator.Object; controller.TempData = new Mock <ITempDataDictionary>().Object; Assert.ThrowsAsync <InvalidOperationException>(async() => await controller.DetailsPost(providerCode, viewModel)); }