Example #1
0
        /// <summary>
        /// Creates a visualization of the <paramref name="payload"/>.
        /// </summary>
        /// <param name="payload">An event payload to visualize.</param>
        /// <returns>A visualization of the <paramref name="payload"/>.</returns>
        public ObjectVisualization Create(IEvent payload)
        {
            Ensure.NotNull(payload, "payload");
            IModelDefinition payloadDefinition;

            if (!modelDefinitionProvider.TryGet(payload.GetType(), out payloadDefinition))
            {
                Debug.Fail(String.Format("Can't find a model definition for event '{0}'.", payload.GetType()));
                return(null);
            }

            IModelValueGetter            paylodValueGetter = modelValueGetterFactory.Create(payload);
            DictionaryModelValueProvider stringValueGetter = new DictionaryModelValueProvider();

            foreach (IFieldDefinition fieldDefinition in payloadDefinition.Fields)
            {
                object fieldValue;
                if (paylodValueGetter.TryGetValue(fieldDefinition.Identifier, out fieldValue))
                {
                    object rawValue;
                    if (converters.TryConvert(fieldDefinition.FieldType, typeof(string), fieldValue, out rawValue))
                    {
                        stringValueGetter.TrySetValue(fieldDefinition.Identifier, rawValue);
                    }
                    else
                    {
                        stringValueGetter.TrySetValue(fieldDefinition.Identifier, fieldValue);
                    }
                }
            }

            ObjectVisualization model = new ObjectVisualization(payloadDefinition, stringValueGetter, new KeyValueCollection());

            return(model);
        }
Example #2
0
        public void GetValues()
        {
            IModelDefinition modelDefinition = modelDefinitions.Get <RegisterUserModel>();

            RegisterUserModel model = new RegisterUserModel();

            model.Username      = "******";
            model.Password      = "******";
            model.PasswordAgain = "y";
            IModelValueProvider          reflection = new ReflectionModelValueProvider(model, valueUpdaters);
            DictionaryModelValueProvider dictionary = new DictionaryModelValueProvider();

            CopyModelValueProvider copyProvider = new CopyModelValueProvider(modelDefinition, true);

            copyProvider.Update(dictionary, reflection);

            object value;

            Assert.IsTrue(dictionary.TryGetValue(nameof(RegisterUserModel.Username), out value));
            Assert.AreEqual(model.Username, value);

            Assert.IsTrue(dictionary.TryGetValue(nameof(RegisterUserModel.Password), out value));
            Assert.AreEqual(model.Password, value);

            Assert.IsTrue(dictionary.TryGetValue(nameof(RegisterUserModel.PasswordAgain), out value));
            Assert.AreEqual(model.PasswordAgain, value);
        }