Exemplo n.º 1
0
    public async Task <IActionResult> UpdateAsync(int id, [FromBody] RecoveryDto input)
    {
        // Map.
        var recovery = _mapper.Map <Recovery>(input);

        recovery.Id = id;

        Recovery recovery_existing = await _recoveryRepository.GetByIdAsync(id);

        if (recovery_existing.Attribution.Creator == input.Reviewer)
        {
            throw new AuthorizationException();
        }

        // Act.
        await _recoveryRepository.UpdateAsync(recovery);

        // FUTURE: Does this make sense?
        // Only when this item was rejected can we move into
        // a pending state after update.
        if (recovery.State.AuditStatus == AuditStatus.Rejected)
        {
            // Transition.
            recovery.State.TransitionToPending();

            // Act.
            await _recoveryRepository.SetAuditStatusAsync(recovery.Id, recovery);
        }

        // Return.
        return(NoContent());
    }
Exemplo n.º 2
0
        public static async Task DeleteRecoveryAsync(BackendFixtureFactory factory, RecoveryDto recovery)
        {
            // Arrange
            using var client = factory.CreateClient(OrganizationRole.Superuser);

            // Act
            var response = await client.DeleteAsync($"api/recovery/{recovery.Id}");

            // Assert
            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
        }
Exemplo n.º 3
0
    public async Task <IActionResult> CreateAsync([FromBody] RecoveryDto input)
    {
        // Map.
        var recovery = _mapper.Map <Recovery>(input);

        if (_appContext.UserId == input.Reviewer)
        {
            throw new AuthorizationException();
        }

        // Act.
        recovery = await _recoveryRepository.AddGetAsync(recovery);

        // Map.
        var output = _mapper.Map <RecoveryDto>(recovery);

        // Return.
        return(Ok(output));
    }
Exemplo n.º 4
0
        public static async Task <RecoverySampleDto> CreateRecoverySampleAsync(BackendFixtureFactory factory, RecoveryDto recovery)
        {
            // Arrange
            using var client = factory.CreateClient(OrganizationRole.Writer);
            var newObject = new RecoverySampleDtoFaker()
                            .RuleFor(f => f.Address, f => "gfm-351cc5645ab7457b92d3629e8c163f0b")
                            .RuleFor(f => f.Contractor, f => Guid.Parse("62af863e-2021-4438-a5ea-730ed3db9eda"))
                            .Generate();

            // Act
            var response = await client.PostAsJsonAsync($"api/recovery/{recovery.Id}/sample", newObject);

            var returnObject = await response.Content.ReadFromJsonAsync <RecoverySampleDto>();

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(recovery.Id, returnObject.Recovery);
            Assert.Equal(newObject.Address, returnObject.Address);

            return(returnObject);
        }