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 GetParameterReturnsParameterIfSelected(NameOnlyParameterViewModel sut)
 {
     var expected = Maybe.ToMaybe(new NameOnlyParameter(sut.Name));
     sut.IsSelected = true;
     var actual = sut.GetParameter();
     Assert.Equal(expected, actual);
 }
 private static void SetupItemToDeleteOn(CmdApplicationConfigurationListViewModel sut)
 {
     sut.SelectedConfiguration = sut.ApplicationConfigurations.First();
     var vm = new NameOnlyParameterViewModel((Name)"testParameter");
     vm.IsSelected = true;
     sut.SelectedConfiguration.Properties.Add(vm);
 }
Exemple #4
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 void WithParameterWithDiffParameterNameDoesNotSetIsSelected(
     NameOnlyParameter parameter,
     NameOnlyParameterViewModel sut)
 {
     Assert.NotEqual(parameter.Name, sut.Name);
     sut.WithParameter(parameter);
     Assert.False(sut.IsSelected);
 }
 public void WithParameterWithSameParameterNameSetsIsSelected(
     [Frozen]Name name,
     NameOnlyParameter parameter,
     NameOnlyParameterViewModel sut)
 {
     Assert.Equal(parameter.Name, sut.Name);
     sut.WithParameter(parameter);
     Assert.True(sut.IsSelected);
 }
        public void GetCmdApplicationConfigurationReturnsConfigurationIfAtleastOneParameterHasValue(
            CmdApplicationConfigurationViewModel sut)
        {
            Assert.True(!string.IsNullOrEmpty(sut.FriendlyName));

            var vm = new NameOnlyParameterViewModel((Name)"testParameter");
            vm.IsSelected = true;
            sut.Properties.Add(vm);

            var actual = sut.GetCmdApplicationConfiguration();
            Assert.True(actual.Any());
        }
Exemple #8
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 SaveCmdApplicationConfigurationCommandSendWhenViewModelIsInValidState(
            [Frozen]Mock<IChannel<SaveCmdApplicationConfigurationCommand>> channel,
            CmdApplicationConfigurationViewModel sut)
        {
            sut.ToggleEdit.Execute(null);
            sut.FriendlyName = "Valid Friendly Name";
            var vm = new NameOnlyParameterViewModel((Name)"testParameter");
            vm.IsSelected = true;
            sut.Properties.Add(vm);

            sut.Save.Execute(null);

            channel.Verify(m => m.Send(It.Is<SaveCmdApplicationConfigurationCommand>(a =>
           a.ApplicationConfiguration.ApplicationName == sut.ApplicationName &&
           a.ApplicationConfiguration.Name == (Name)sut.FriendlyName &&
           a.ApplicationConfiguration.Parameters.Count == 1)), Times.Once());
        }
 public void GetNameReturnsNameAsExpected(NameOnlyParameterViewModel sut)
 {
     Assert.Equal(sut.Name, sut.GetName());
 }
 public void WithParameterWithNullValueDoesNotSetIsSelected(NameOnlyParameterViewModel sut)
 {
     sut.WithParameter(null);
     Assert.False(sut.IsSelected);
 }
 public void GetParameterReturnsEmptyIfSelectedFalse(NameOnlyParameterViewModel sut)
 {
     sut.IsSelected = false;
     var parameter = sut.GetParameter();
     Assert.Equal(Maybe.Empty<IParameter>(), parameter);
 }
 public void SutWithoutDisplayNameReturnsEmptyDisplayName(Name aName)
 {
     var sut = new NameOnlyParameterViewModel(aName);
     Assert.Equal(Name.EmptyName, sut.DisplayName);
 }
 public void SutIsViewModelBase(NameOnlyParameterViewModel sut)
 {
     Assert.IsAssignableFrom<ParameterViewModel>(sut);
     Assert.Equal(typeof(NameOnlyParameter), sut.GetParameterType());
 }