public void ThenTrueIsReturnedIfCategoryIsViewAndChangedPropertiesAreMissing()
        {
            // arrange
            var command = new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category        = "View",
                    Description     = "description",
                    RelatedEntities = new List <Entity> {
                        new Entity()
                    },
                    ChangedProperties = null,
                    AffectedEntity    = new Entity {
                        Id = "1", Type = "test"
                    }
                }
            };

            //Act
            var result = _validator.Validate(command);

            //Assert
            Assert.IsTrue(result.IsValid());
        }
        public void ThenFalseIsReturnedIfCategoryIsNotViewAndChangedPropertiesAreMissing()
        {
            // arrange
            var command = new CreateAuditCommand
            {
                EasAuditMessage = new EasAuditMessage
                {
                    Category        = "Changed",
                    Description     = "description",
                    RelatedEntities = new List <Entity> {
                        new Entity()
                    },
                    ChangedProperties = null,
                    AffectedEntity    = new Entity {
                        Id = "1", Type = "test"
                    }
                }
            };

            //Act
            var result = _validator.Validate(command);

            //Assert
            Assert.IsFalse(result.IsValid());
            Assert.Contains(new KeyValuePair <string, string>("ChangedProperties", "ChangedProperties has not been supplied"), result.ValidationDictionary);
        }
Esempio n. 3
0
 public static AuditCommand Create(CreateAuditCommand command, IAuthentificationContext authentificationContext, IAuditSerializer auditSerializer) => new AuditCommand
 {
     Id                 = Guid.NewGuid(),
     CommandName        = command.Command.GetType().UnderlyingSystemType.Name,
     Command            = auditSerializer.Serialize(command.Command),
     CorrelationId      = authentificationContext.CorrelationId,
     Date               = DateTime.UtcNow,
     ImpersonatedUserId = authentificationContext.ImpersonatedUser.Id,
     UserId             = authentificationContext.User.Id
 };
        public async Task HandleAddAuditWithNoApplicationFoundForClientId()
        {
            // Arrange
            var command = new CreateAuditCommand {
                Actor      = "Actor", ActorId = 1,
                ClientId   = "1", Description = "Description",
                Subject    = "Subject", SubjectId = 1,
                Properties = "properties"
            };

            // Act
            var result = await Mediator.Send(command);

            //Assert
            Assert.True(result.IsFailure);
            Assert.AreEqual(Constants.ErrorMessages.NoApplicationFound, result.Error);
        }
Esempio n. 5
0
        public async Task ThenTheCommandIfValidIsPassedToTheService()
        {
            //Arrange
            var auditCommand = new CreateAuditCommand {
                EasAuditMessage = new EasAuditMessage {
                    ChangedProperties = new List <PropertyUpdate> {
                        new PropertyUpdate()
                    }, Description = "test", RelatedEntities = new List <Entity> {
                        new Entity()
                    }
                }
            };

            //Act
            await _createAuditCommandHandler.Handle(auditCommand);

            //Assert
            _auditService.Verify(x => x.SendAuditMessage(It.Is <EasAuditMessage>(c =>
                                                                                 c.Description.Equals(auditCommand.EasAuditMessage.Description) &&
                                                                                 c.ChangedProperties.Count == 1 &&
                                                                                 c.RelatedEntities.Count == 1
                                                                                 )));
        }
        public async Task <IActionResult> CreateAuditAsync([FromBody] CreateAuditCommand command, [FromHeader(Name = "x-requestid")] string requestId)
        {
            long commandResult = -1;

            if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
            {
                var requestCreateAudit = new IdentifiedCommand <CreateAuditCommand, long>(command, guid);

                _logger.LogInformation(
                    "----- Sending command: {CommandName} - ({@Command})",
                    requestCreateAudit.GetGenericTypeName(),
                    requestCreateAudit);

                commandResult = await _mediator.Send(requestCreateAudit);
            }

            if (commandResult == -1)
            {
                return(BadRequest());
            }

            return(Ok(commandResult));
        }