Exemplo n.º 1
0
        public void TryAdd_Should_ReturnFalse_When_IsValidReturnFalse()
        {
            var source    = _fixture.Create <string>();
            var converted = _fixture.Create <object>();

            _jsonConvertible.TryConvert(source, out Arg.Any <object>())
            .Returns(x =>
            {
                x[1] = converted;
                return(true);
            });

            _schemaValidation.IsValid(converted)
            .Returns(false);


            _collection.TryAdd(source, out _).Should().BeFalse();

            _jsonConvertible
            .Received(1)
            .TryConvert(source, out Arg.Any <object>());

            _schemaValidation
            .Received(1)
            .IsValid(converted);
        }
        /// <summary>
        /// Try to add Action to collection.
        /// </summary>
        /// <param name="source">The <see cref="object"/> to be convert to <see cref="ThingActionInformation"/>.</param>
        /// <param name="info">The <see cref="ThingActionInformation"/> created.</param>
        /// <returns>Return true if could convert and added on collection, otherwise return false.</returns>
        public bool TryAdd(object source, [NotNullWhen(true)] out ThingActionInformation?info)
        {
            info = null;

            if (!_inputConvertible.TryConvert(source, out var inputProperty))
            {
                return(false);
            }

            if (!_inputValidation.IsValid(inputProperty))
            {
                return(false);
            }

            info = _actionInformationFactory.Convert(_convertible.Convert(inputProperty) as Dictionary <string, object?>);

            info.StatusChanged += OnStatusChange;

            return(_actions.TryAdd(info.GetId(), info));
        }