Example #1
0
        public async Task <IHttpActionResult> Revoke([FromBody] RevokePermissionsRouteValues routeValues)
        {
            if (routeValues.Ukprn == null)
            {
                ModelState.AddModelError(nameof(routeValues.Ukprn), "A Ukprn needs to be supplied");
            }

            if (string.IsNullOrWhiteSpace(routeValues.AccountLegalEntityPublicHashedId))
            {
                ModelState.AddModelError(nameof(routeValues.AccountLegalEntityPublicHashedId), "A Public Hashed Id for an Account Legal Entity needs to be supplied");
            }

            if (routeValues.OperationsToRevoke == null || routeValues.OperationsToRevoke.Length == 0)
            {
                ModelState.AddModelError(nameof(routeValues.OperationsToRevoke), "One or more operations need to be supplied");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new RevokePermissionsCommand(
                ukprn: routeValues.Ukprn.Value,
                accountLegalEntityPublicHashedId: routeValues.AccountLegalEntityPublicHashedId,
                operationsToRevoke: routeValues.OperationsToRevoke);
            await _mediator.Send(command);

            return(Ok());
        }
        public RevokePermissionsCommandHandlerTestsFixture()
        {
            UnitOfWorkContext = new UnitOfWorkContext();

            CreateDb();
            CreateDefaultEntities();

            EncodingService = new Mock <IEncodingService>();
            EncodingService
            .Setup(x => x.Decode(AccountLegalEntity.PublicHashedId, EncodingType.PublicAccountLegalEntityId))
            .Returns(AccountLegalEntity.Id);

            var lazyDb = new Lazy <ProviderRelationshipsDbContext>(() => Db);

            Handler = new RevokePermissionsCommandHandler(lazyDb, EncodingService.Object);

            RevokePermissionsCommand = new RevokePermissionsCommand(
                ukprn: 299792458,
                accountLegalEntityPublicHashedId: "ALE1",
                operationsToRevoke: new[] { Operation.Recruitment });

            UnitOfWorkContext = new UnitOfWorkContext();
        }