public async Task InitialStatusIsPendingIfOverLimit() { _authMock.SetPolicyResult("RaiseSpendLimit", false); int newId = 1; _repairsGatewayMock.ReturnWOId(newId); await _classUnderTest.Execute(new WorkOrder()); VerifyPlacedOrder(wo => wo.StatusCode == WorkStatusCode.PendingApproval); }
public void Setup() { _fixture = new Fixture(); _repairsGatewayMock = new MockRepairsGateway(); _authMock = new AuthorisationMock(); _authMock.SetPolicyResult("RaiseSpendLimit", true); _scheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); ContractorUsesExternalScheduler(false); _currentUserServiceMock = new CurrentUserServiceMock(); _featureManagerMock = new Mock <IFeatureManager>(); _featureManagerMock.Setup(fm => fm.IsEnabledAsync(It.IsAny <string>())).ReturnsAsync(true); _notificationMock = new NotificationMock(); _drsOptions = new DrsOptions { Login = "******", Password = "******", APIAddress = new Uri("https://apiAddress.none"), ManagementAddress = new Uri("https://managementAddress.none") }; _classUnderTest = new CreateWorkOrderUseCase( _repairsGatewayMock.Object, _scheduleOfRatesGateway.Object, new NullLogger <CreateWorkOrderUseCase>(), _currentUserServiceMock.Object, _authMock.Object, _featureManagerMock.Object, _notificationMock, Options.Create(_drsOptions) ); }
public async Task SetsVariationPendingApprovalWhenAuthRequired() { const int desiredWorkOrderId = 42; var workOrder = BuildWorkOrder(desiredWorkOrderId); workOrder.StatusCode = WorkStatusCode.Open; var request = BuildUpdate(workOrder); _featureManagerMock.SetFeature(FeatureFlags.SpendLimits, true); _authorisationMock.SetPolicyResult("VarySpendLimit", false); await _classUnderTest.Execute(request); workOrder.StatusCode.Should().Be(WorkStatusCode.VariationPendingApproval); request.TypeCode.Should().Be(Generated.JobStatusUpdateTypeCode.ContractManagerApprovalNeeded_180); }
public async Task ThrowsUnauthorisedWhenAboveSpendLimit() { var workOrder = _fixture.Create <WorkOrder>(); workOrder.StatusCode = WorkStatusCode.PendingApproval; var jobStatusUpdate = BuildUpdate(workOrder); _currentUserServiceMock.SetSecurityGroup(UserGroups.AuthorisationManager); _authorisationMock.SetPolicyResult("RaiseSpendLimit", false); Func <Task> act = async() => await _classUnderTest.Execute(jobStatusUpdate); await act.Should().ThrowAsync <UnauthorizedAccessException>(); }
public async Task ThrowsNotAuthorisedWhenAboveSpendLimit() { const int desiredWorkOrderId = 42; var workOrder = CreateReturnWorkOrder(desiredWorkOrderId); workOrder.StatusCode = WorkStatusCode.VariationPendingApproval; var request = CreateJobStatusUpdateRequest(workOrder, Generated.JobStatusUpdateTypeCode.ApproveVariation_10020); _currentUserServiceMock.SetSecurityGroup(UserGroups.ContractManager); _authorisationMock.SetPolicyResult("VarySpendLimit", false); Func <Task> fn = async() => await _classUnderTest.Execute(request); await fn.Should().ThrowAsync <UnauthorizedAccessException>(); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _currentUserServiceMock = new CurrentUserServiceMock(); _notifierMock = new NotificationMock(); _expectedName = "Expected Name"; _currentUserServiceMock.SetUser("1111", "*****@*****.**", _expectedName); _authorisationMock = new AuthorisationMock(); _authorisationMock.SetPolicyResult("RaiseSpendLimit", true); _classUnderTest = new ApproveWorkOrderStrategy( _currentUserServiceMock.Object, _notifierMock, _authorisationMock.Object ); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _repairsGatewayMock = new MockRepairsGateway(); _currentUserServiceMock = new CurrentUserServiceMock(); _jobStatusUpdateGateway = new Mock <IJobStatusUpdateGateway>(); _updateSorCodesUseCaseMock = new Mock <IUpdateSorCodesUseCase>(); _expectedName = "Expected Name"; _currentUserServiceMock.SetUser("1111", "*****@*****.**", _expectedName); _notifierMock = new NotificationMock(); _authorisationMock = new AuthorisationMock(); _authorisationMock.SetPolicyResult("VarySpendLimit", true); _classUnderTest = new ApproveVariationUseCase( _repairsGatewayMock.Object, _jobStatusUpdateGateway.Object, _currentUserServiceMock.Object, _updateSorCodesUseCaseMock.Object, _notifierMock, _authorisationMock.Object); }