Exemplo n.º 1
0
        /// <inheritdoc />
        public IResult ValidateDomainEvent(DomainEvent domainEvent)
        {
            if (domainEvent is null)
            {
                return(Result.Error("invalid data: null event", ErrorCode.ValidationFailed));
            }

            if (string.IsNullOrWhiteSpace(domainEvent.EventType))
            {
                return(Result.Error("event does not contain EventType", ErrorCode.ValidationFailed));
            }

            var result = domainEvent switch
            {
                ConfigurationBuilt @event => ValidateDomainEvent(@event),
                DefaultEnvironmentCreated @event => ValidateDomainEvent(@event),
                EnvironmentCreated @event => ValidateDomainEvent(@event),
                EnvironmentDeleted @event => ValidateDomainEvent(@event),
                EnvironmentKeysImported @event => ValidateDomainEvent(@event),
                EnvironmentKeysModified @event => ValidateDomainEvent(@event),
                StructureCreated @event => ValidateDomainEvent(@event),
                StructureDeleted @event => ValidateDomainEvent(@event),
                StructureVariablesModified @event => ValidateDomainEvent(@event),
                _ => Result.Error($"DomainEvent '{domainEvent.GetType().Name}' can't be validated; not supported", ErrorCode.ValidationFailed)
            };

            KnownMetrics.EventsValidated.WithLabels(result.IsError ? "Invalid" : "Valid").Inc();

            return(result);
        }
        public void NullCheckOperatorNegated(string structName, int structVersion)
        {
            var left  = new StructureDeleted(new StructureIdentifier(structName, structVersion));
            var right = new StructureDeleted(new StructureIdentifier(structName, structVersion));

            Assert.False(left != right, "left != right");
        }
        public void Equality(string structName, int structVersion)
        {
            var left  = new StructureDeleted(new StructureIdentifier(structName, structVersion));
            var right = new StructureDeleted(new StructureIdentifier(structName, structVersion));

            Assert.True(left.Equals(right), "left.Equals(right)");
        }
        public void MetadataFilled(string structName, int structVersion)
        {
            var domainEvent = new StructureDeleted(new StructureIdentifier(structName, structVersion));

            var metadata = domainEvent.GetMetadata();

            Assert.NotEmpty(metadata.Filters);
        }
        public void GetHashCodeStable(string structName, int structVersion)
        {
            var domainEvent = new StructureDeleted(new StructureIdentifier(structName, structVersion));

            var hashes = Enumerable.Range(0, 1000)
                         .Select(i => domainEvent.GetHashCode())
                         .ToList();

            var example = domainEvent.GetHashCode();

            Assert.True(hashes.All(h => h == example), "hashes.All(h=>h==example)");
        }
Exemplo n.º 6
0
        private IResult ValidateDomainEvent(StructureDeleted @event)
        {
            if (@event is null)
            {
                return(Result.Error("invalid data: null event", ErrorCode.ValidationFailed));
            }

            var identifierResult = ValidateIdentifier(@event.Identifier);

            if (identifierResult.IsError)
            {
                return(identifierResult);
            }

            return(Result.Success());
        }