public async Task PoliciesPageModel_OnGet_WhenUserHasApproveSpecificationPermission_ThenDoesUserHavePermissionToApproveIsTrue() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient); string specificationId = "spec123"; Specification specification = new Specification() { Id = specificationId, Name = "Test Specification", FundingPeriod = new Reference("1617", "2016/2017"), Description = "Test Description", FundingStreams = new List <FundingStream>() { new FundingStream("fs1", "Funding Stream Name"), } }; specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); // Act IActionResult result = await policiesModel.OnGet(specificationId, null, null); // Assert policiesModel.DoesUserHavePermissionToApprove.Should().Be("true"); }
public IActionResult Policies(string ShopId) { try { ViewData["ShopId"] = ShopId; var shops = _serviceFacade.GetUserShops(new Guid(HttpContext.Session.Id)); var shop = shops.FirstOrDefault(currshop => currshop.Guid.Equals(new Guid(ShopId))); PoliciesModel model = new PoliciesModel(); model.PurchasePolicies = shop.PurchasePolicies; model.DiscountPolicies = shop.DiscountPolicies; model.name = shop.ShopName; return(View(model)); } catch (GeneralServerError) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again."); return(View("UserMessage", message)); } catch (DatabaseConnectionTimeoutException) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again. (Database connection lost)."); return(View("UserMessage", message)); } }
public async Task PoliciesPageModel_OnGet_WhenDatasetsApiFailedReturningNull_ThenErrorShouldBeReturned() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); ILogger logger = CreateLogger(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient, logger); string specificationId = "spec123"; specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, new Specification())); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns((ApiResponse <IEnumerable <DatasetSchemasAssigned> >)null); // Act IActionResult result = await policiesModel.OnGet(specificationId, null, null); // Assert result.Should().BeOfType <ObjectResult>() .Which.Value.Should().Be("Datasets Lookup API Failed and returned null"); result.Should().BeOfType <ObjectResult>() .Which.StatusCode.Should().Be(500); logger .Received(1) .Warning("Dataset Schema Response API Request came back null for Specification ID = '{specificationId}'", specificationId); }
public async Task PoliciesPageModel_OnGet_WhenOperationTypeIsSpecifiedButNoOperationId_ThenPrecondionFailedReturned() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient); string specificationId = "spec123"; Specification specification = CreateSpecificationForBannerChecks(specificationId); specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); // Act IActionResult result = await policiesModel.OnGet(specificationId, PoliciesPageBannerOperationType.CalculationUpdated, null); // Assert result .Should() .BeOfType <PreconditionFailedResult>() .Which .Value .Should() .Be("Operation ID not provided"); }
public async Task PoliciesPageModel_OnGet_WhenSpecificationsApiFailed_ThenErrorShouldBeReturned() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient); string specificationId = "spec123"; specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.InternalServerError, null)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); // Act IActionResult result = await policiesModel.OnGet(specificationId, null, null); // Assert result.Should().BeOfType <ObjectResult>() .Which.Value.Should().Be("Specification Lookup API Failed"); result.Should().BeOfType <ObjectResult>() .Which.StatusCode.Should().Be(500); }
public ActionResult Grid(PoliciesModel model) { model.ClientList = _clientService.GetClientList(); model.ClientPolicies = _policyService.GetPoliciesByClientId(model.ClientIdSelected); return(View(model)); }
public ActionResult Index() { PoliciesModel model = new PoliciesModel(); model.ClientList = _clientService.GetClientList(); return(View(model)); }
public static IServiceCollection ResolveDependencies(this IServiceCollection services) { services.AddAuthorization(config => { config.AddPolicy(PoliciesModel.Admin, PoliciesModel.AdminPolicy()); config.AddPolicy(PoliciesModel.User, PoliciesModel.UserPolicy()); }); services.AddScoped <IRepositoryWork, RepositoryWork>(); services.AddTransient <IUserService, UserService>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); return(services); }
public async Task PoliciesPageModel_OnGet_WhenUserDoesNotHaveApproveSpecificationPermission_ThenDoesUserHavePermissionToApproveIsFalse() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); IAuthorizationHelper authorizationHelper = Substitute.For <IAuthorizationHelper>(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient, authorizationHelper: authorizationHelper); string specificationId = "spec123"; Specification specification = new Specification() { Id = specificationId, Name = "Test Specification", FundingPeriod = new Reference("1617", "2016/2017"), Description = "Test Description", FundingStreams = new List <FundingStream>() { new FundingStream("fs1", "Funding Stream Name"), } }; specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); authorizationHelper.DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanApproveSpecification)) .Returns(false); // Act IActionResult result = await policiesModel.OnGet(specificationId, null, null); // Assert policiesModel.DoesUserHavePermissionToApprove.Should().Be("false"); }
public async Task PoliciesPageModel_OnGet_WhenOperationTypeIsSubPolicyCalculationUpdated_ThenBannerPopulated() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient); string specificationId = "spec123"; Specification specification = CreateSpecificationForBannerChecks(specificationId); specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); // Act IActionResult result = await policiesModel.OnGet(specificationId, PoliciesPageBannerOperationType.CalculationUpdated, "subpolicyCalculation1"); // Assert result .Should() .BeOfType <PageResult>(); policiesModel .PageBanner .Should() .BeEquivalentTo(new PageBannerOperation() { EntityName = "Sub Policy 2 Calculation 1", EntityType = "Calculation specification", OperationAction = "updated", OperationId = null, ActionText = "Edit", ActionUrl = $"/specs/EditCalculation/subpolicyCalculation1?specificationId={specificationId}", }); }
public IActionResult AddCompoundPurchasePolicy(string Description, int policy1, string Sign, int policy2, int Percent, string ShopId) { try { PoliciesModel policy = new PoliciesModel(); var shops = _serviceFacade.GetUserShops(new Guid(HttpContext.Session.Id)); var shop = shops.FirstOrDefault(currshop => currshop.Guid.Equals(new Guid(ShopId))); policy.PurchasePolicies = shop.PurchasePolicies; _serviceFacade.AddNewPurchasePolicy(new Guid(HttpContext.Session.Id), new Guid(ShopId), (object)"Compound purchase policy", policy.PurchasePolicies.ElementAt(policy1 - 1).Guid, (object)Sign, policy.PurchasePolicies.ElementAt(policy2 - 1).Guid, (object)Description); return(RedirectToAction("Policies", "Seller", new { ShopId = ShopId })); } catch (IllegalArgumentException) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "Please fill in all the fields in a valid manner."); return(View("UserMessage", message)); } catch (NoPrivilegesException) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "You haven't sufficient priviliges. Cannot complete the request."); return(View("UserMessage", message)); } catch (GeneralServerError) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again."); return(View("UserMessage", message)); } catch (DatabaseConnectionTimeoutException) { var redirect = this.Url.Action("Index", "Seller"); var message = new UserMessage(redirect, "An error has occured. Please refresh and try again. (Database connection lost)."); return(View("UserMessage", message)); } }
public async Task PoliciesPageModel_OnGet_WhenPoliciesAreRequestedForASpecification_ThenResultIsReturned() { // Arrange ISpecsApiClient specsApiClient = CreateSpecsApiClient(); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); PoliciesModel policiesModel = GetPoliciesModel(specsApiClient, datasetsApiClient); string specificationId = "spec123"; Specification specification = new Specification() { Id = specificationId, Name = "Test Specification", FundingPeriod = new Reference("1617", "2016/2017"), Description = "Test Description", FundingStreams = new List <FundingStream>() { new FundingStream("fs1", "Funding Stream Name"), }, Policies = new List <Policy>() { new Policy() { Id = "pol1", Name = "Policy 1", Description = "Policy 1 Description", Calculations = new List <Calculation>() { new Calculation() { Id = "calc1", Name = "Calculation 1", Description = "Calculation with allocation line", AllocationLine = new Reference("al1", "Allocation Line 1"), }, new Calculation() { Id = "calc2", Name = "Calculation Two", Description = "Calculation without allocation line", AllocationLine = null }, }, SubPolicies = new List <Policy>(), }, } }; specsApiClient.GetSpecification(Arg.Any <string>()) .Returns(new ApiResponse <Specification>(HttpStatusCode.OK, specification)); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(specificationId) .Returns(new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, Enumerable.Empty <DatasetSchemasAssigned>())); // Act IActionResult result = await policiesModel.OnGet(specificationId, null, null); // Assert result.Should().BeOfType <PageResult>(); SpecificationViewModel expectedResult = new SpecificationViewModel() { Id = specificationId, Name = "Test Specification", FundingPeriod = new ReferenceViewModel("1617", "2016/2017"), Description = "Test Description", FundingStreams = new List <ReferenceViewModel>() { new ReferenceViewModel("fs1", "Funding Stream Name"), }, Policies = new List <PolicyViewModel>() { new PolicyViewModel() { Id = "pol1", Name = "Policy 1", Description = "Policy 1 Description", Calculations = new List <CalculationViewModel>() { new CalculationViewModel() { Id = "calc1", Name = "Calculation 1", Description = "Calculation with allocation line", AllocationLine = new ReferenceViewModel("al1", "Allocation Line 1"), }, new CalculationViewModel() { Id = "calc2", Name = "Calculation Two", Description = "Calculation without allocation line", AllocationLine = null }, }, SubPolicies = new List <PolicyViewModel>(), }, } }; policiesModel.Specification.Should().BeEquivalentTo(expectedResult, o => o.RespectingRuntimeTypes().WithAutoConversion().WithTracing()); }