コード例 #1
0
        public void Equality(string envCategory, string envName)
        {
            var left  = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));
            var right = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));

            Assert.True(left.Equals(right), "left.Equals(right)");
        }
コード例 #2
0
        public void NullCheckOperatorNegated(string envCategory, string envName)
        {
            var left  = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));
            var right = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));

            Assert.False(left != right, "left != right");
        }
コード例 #3
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);
        }
コード例 #4
0
        public void MetadataFilled(string envCategory, string envName)
        {
            var domainEvent = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));

            var metadata = domainEvent.GetMetadata();

            Assert.NotEmpty(metadata.Filters);
        }
コード例 #5
0
        private IResult ValidateDomainEvent(EnvironmentCreated @event)
        {
            var identifierResult = ValidateIdentifier(@event.Identifier);

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

            return(Result.Success());
        }
コード例 #6
0
        public void GetHashCodeStable(string envCategory, string envName)
        {
            var domainEvent = new EnvironmentCreated(new EnvironmentIdentifier(envCategory, envName));

            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)");
        }
コード例 #7
0
        public void ReturnValidationErrors()
        {
            var validator = new Mock <ICommandValidator>(MockBehavior.Strict);

            validator.Setup(v => v.ValidateDomainEvent(It.IsAny <EnvironmentCreated>()))
            .Returns(() => Result.Error("Something went wrong", ErrorCode.Undefined));

            var domainObject = new DefaultDomainObject();
            var domainEvent  = new EnvironmentCreated(new EnvironmentIdentifier("Foo", "Bar"));

            domainObject.AddEvent(domainEvent);

            var result = domainObject.Validate(new List <ICommandValidator> {
                validator.Object
            });

            Assert.NotEmpty(result[domainEvent]);
        }