public ResourceAction AddResourceAction(AddResourceActionCommand command) { command.Validate(true); var action = new ResourceAction { Name = command.Name, Resource = this }; this.availableActions.Add(action); this.AddEvent(new NewResourceActionAddedEvent(this) { Name = action.Name }); return(action); }
public void AddResourceAction_ShouThrowDomainValidationException_WhenCommandIsInvalid(AddResourceActionCommand command, ValidationError[] errors) { var createCmd = ApplicationResourceCmdGenerator.CreateApplicationResourceCommand; var newResource = ApplicationResource.Create(createCmd); var ex = Assert.Throws <DomainValidationException>(() => newResource.AddResourceAction(command)); Assert.Equal(errors.Length, ex.ValidationErrors.Count()); Assert.All(ex.ValidationErrors, e => errors.Any(er => er.Code == e.Code && er.Member == e.Member)); }
public static IEnumerable <ValidationError> Validate(this AddResourceActionCommand command, bool throws = false) => validator.ValidateCommand(command, throws);