Example #1
0
        /// <inheritdoc />
        protected override bool IsActuallyValid(Commands.Update.Update effect)
        {
            if (effect == null)
            {
                return(false);
            }
            if (effect.EntityType != typeof(T))
            {
                return(false);
            }
            var actual = effect.UpdateValuesStringKeys;

            foreach (var kv in _expectedValues)
            {
                if (!actual.ContainsKey(kv.Key))
                {
                    return(false);
                }

                var v = actual[kv.Key];
                if (!Equals(v, kv.Value))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
 protected override bool IsActuallyValid(Commands.Update.Update effect)
 {
     if (effect == null)
     {
         return(false);
     }
     if (effect.EntityType != typeof(T))
     {
         return(false);
     }
     return(_predicate((T)effect.Entity));
 }
Example #3
0
 protected override string GetMessage(Commands.Update.Update command)
 {
     if (command == null)
     {
         return($"expected updated entity {_explanation}, but story unexpectedly ends");
     }
     if (command.EntityType != typeof(T))
     {
         return
             ($"expected updated entity of type {typeof(T).Name} and {_explanation}, but got one of {command.EntityType.Name}");
     }
     if (string.IsNullOrEmpty(_explanation))
     {
         return($"updated {typeof(T).Name} does not meet conditions");
     }
     return($"update '{_explanation}' does not satisfy conditions");
 }
Example #4
0
        /// <inheritdoc />
        protected override string GetMessage(Commands.Update.Update command)
        {
            if (command == null)
            {
                return($"expected updated entity {_explanation}, but story unexpectedly ends");
            }
            if (command.EntityType != typeof(T))
            {
                return
                    ($"expected updated entity of type {typeof(T).Name} and {_explanation}, but got one of {command.EntityType.Name}");
            }
            List <(string, object, object)> propExpectedActual = new List <(string, object, object)>();
            var actual = command.UpdateValuesStringKeys;

            foreach (var kv in _expectedValues)
            {
                if (!actual.ContainsKey(kv.Key))
                {
                    propExpectedActual.Add((kv.Key, kv.Value, null));
                }

                var v = actual[kv.Key];
                if (!Equals(v, kv.Value))
                {
                    propExpectedActual.Add((kv.Key, kv.Value, v));
                }
            }

            var propsText = string.Join(", ",
                                        propExpectedActual.Select(x => $"{x.Item1}: '{x.Item2}' expected, '{x.Item3}' got"));

            if (string.IsNullOrEmpty(_explanation))
            {
                return($"updated {typeof(T).Name} does not meet conditions: {propsText}");
            }
            return($"update '{_explanation}' does not satisfy conditions: {propsText}");
        }