Exemple #1
0
        public CmdApplicationConfigurationViewModel Create(CmdApplicationMeta meta)
        {
            if (meta == null)
            {
                throw new ArgumentNullException(nameof(meta));
            }

            var properties = new List <ParameterViewModel>();

            foreach (var parameterMeta in meta.ParameterMetas)
            {
                ParameterViewModel viewModel = null;
                if (parameterMeta.ParameterType == typeof(NameValueParameter))
                {
                    viewModel = new NameValueParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                }
                else if (parameterMeta.ParameterType == typeof(NameOnlyParameter))
                {
                    viewModel = new NameOnlyParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                }
                else
                {
                    throw new ArgumentException(string.Format("Type {0} not supported for parameter {1}", parameterMeta.ParameterType, parameterMeta.Name));
                }

                properties.Add(viewModel);
            }

            return(new CmdApplicationConfigurationViewModel(meta, properties, Channel, StringParsers));
        }
        public CmdApplicationConfigurationViewModel Create(CmdApplicationMeta meta)
        {
            if (meta == null)
                throw new ArgumentNullException(nameof(meta));

            var properties = new List<ParameterViewModel>();
            foreach (var parameterMeta in meta.ParameterMetas)
            {
                ParameterViewModel viewModel = null;
                if (parameterMeta.ParameterType == typeof(NameValueParameter))
                {
                    viewModel = new NameValueParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                }
                else if (parameterMeta.ParameterType == typeof(NameOnlyParameter))
                {
                    viewModel = new NameOnlyParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                }
                else
                {
                    throw new ArgumentException(string.Format("Type {0} not supported for parameter {1}", parameterMeta.ParameterType, parameterMeta.Name));
                }

                properties.Add(viewModel);
            }

            return new CmdApplicationConfigurationViewModel(meta, properties, Channel, StringParsers);
        }
 public void WithParameterWithDiffParameterNameDoesNotSetIsSelected(
     NameValueParameter parameter,
     NameValueParameterViewModel sut)
 {
     Assert.NotEqual(parameter.Name, sut.Name);
     sut.WithParameter(parameter);
     Assert.True(string.IsNullOrEmpty(sut.Value));
 }
 public void WithParameterWithSameParameterNameSetsIsSelected(
     [Frozen]Name name,
     NameValueParameter parameter,
     NameValueParameterViewModel sut)
 {
     Assert.Equal(parameter.Name, sut.Name);
     sut.WithParameter(parameter);
     Assert.Equal(parameter.Value, sut.Value);
 }
Exemple #5
0
        public CmdApplicationConfigurationViewModel Create(
            CmdApplicationConfiguration applicationConfiguration,
            CmdApplicationMeta applicationMeta)
        {
            if (applicationConfiguration == null)
            {
                throw new ArgumentNullException(nameof(applicationConfiguration));
            }

            if (applicationMeta == null)
            {
                throw new ArgumentNullException(nameof(applicationMeta));
            }

            var properties = new List <ParameterViewModel>();

            foreach (var parameterMeta in applicationMeta.ParameterMetas)
            {
                ParameterViewModel viewModel = null;
                if (parameterMeta.ParameterType == typeof(NameValueParameter))
                {
                    viewModel = new NameValueParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                    viewModel.WithParameter(applicationConfiguration
                                            .Parameters
                                            .FirstOrDefault(a => a.Name == parameterMeta.Name));
                }
                else if (parameterMeta.ParameterType == typeof(NameOnlyParameter))
                {
                    viewModel = new NameOnlyParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                    viewModel.WithParameter(applicationConfiguration.Parameters.FirstOrDefault(a => a.Name == parameterMeta.Name));
                }
                else
                {
                    throw new ArgumentException(string.Format("Type {0} not supported for parameter {1}", parameterMeta.ParameterType, parameterMeta.Name));
                }

                properties.Add(viewModel);
            }
            var returnValue = new CmdApplicationConfigurationViewModel(
                applicationMeta,
                properties,
                Channel,
                StringParsers);

            returnValue.FriendlyName = (string)applicationConfiguration.Name;
            return(returnValue);
        }
        public CmdApplicationConfigurationViewModel Create(
            CmdApplicationConfiguration applicationConfiguration,
            CmdApplicationMeta applicationMeta)
        {
            if (applicationConfiguration == null)
                throw new ArgumentNullException(nameof(applicationConfiguration));

            if (applicationMeta == null)
                throw new ArgumentNullException(nameof(applicationMeta));

            var properties = new List<ParameterViewModel>();
            foreach (var parameterMeta in applicationMeta.ParameterMetas)
            {
                ParameterViewModel viewModel = null;
                if (parameterMeta.ParameterType == typeof(NameValueParameter))
                {
                    viewModel = new NameValueParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                    viewModel.WithParameter(applicationConfiguration
                         .Parameters
                         .FirstOrDefault(a => a.Name == parameterMeta.Name));
                }
                else if (parameterMeta.ParameterType == typeof(NameOnlyParameter))
                {
                    viewModel = new NameOnlyParameterViewModel(parameterMeta.Name, parameterMeta.DisplayName);
                    viewModel.WithParameter(applicationConfiguration.Parameters.FirstOrDefault(a => a.Name == parameterMeta.Name));
                }
                else
                {
                    throw new ArgumentException(string.Format("Type {0} not supported for parameter {1}", parameterMeta.ParameterType, parameterMeta.Name));
                }

                properties.Add(viewModel);
            }
            var returnValue = new CmdApplicationConfigurationViewModel(
                applicationMeta,
                properties,
                Channel,
                StringParsers);
            returnValue.FriendlyName = (string)applicationConfiguration.Name;
            return returnValue;
        }
 public void GetNameReturnsNameAsExpected(NameValueParameterViewModel sut)
 {
     Assert.Equal(sut.Name, sut.GetName());
 }
 public void WithParameterWithNullValueDoesNotSetIsSelected(NameValueParameterViewModel sut)
 {
     sut.WithParameter(null);
     Assert.True(string.IsNullOrEmpty(sut.Value));
 }
 public void GetParameterReturnsParameterIfValuePresent(NameValueParameterViewModel sut)
 {
     var expected = Maybe.ToMaybe<NameValueParameter>(new NameValueParameter(sut.Name, sut.Value));
     var actual = sut.GetParameter();
     Assert.Equal(expected, actual);
 }
 public void GetParameterReturnsEmptyIfNoValueIsPresent(NameValueParameterViewModel sut)
 {
     sut.Value = string.Empty;
     var actual = sut.GetParameter();
     Assert.Equal(Maybe.Empty<IParameter>(), actual);
 }
 public void SutWithoutDisplayNameReturnsEmptyDisplayName(Name aName)
 {
     var sut = new NameValueParameterViewModel(aName);
     Assert.Equal(Name.EmptyName, sut.DisplayName);
 }
 public void SutIsViewModelBase(NameValueParameterViewModel sut)
 {
     Assert.IsAssignableFrom<ParameterViewModel>(sut);
     Assert.Equal(typeof(NameValueParameter), sut.GetParameterType());
 }