Exemplo n.º 1
0
        public void Should_Create_Empty_List_From_Empty_Form_Collection()
        {
            // arrange
            FormCollection formCollection = new FormCollection();

            // act
            List <ConnectionParameterModel> connectionParameterList = ConnectionParameterModel.FromFormCollection(formCollection);

            // assert
            Assert.IsTrue(connectionParameterList.Count == 0);
        }
Exemplo n.º 2
0
        public void Should_Instantiate()
        {
            // arrange
            ConnectionParameterModel connectionParameter;

            // act
            connectionParameter = new ConnectionParameterModel();

            // assert
            Assert.IsNotNull(connectionParameter);
        }
Exemplo n.º 3
0
        public void Should_Create_List_From_Valid_Form_Collection()
        {
            // arrange
            FormCollection formCollection = new FormCollection();

            formCollection["ConnectionParameterKey1"]   = "key1";
            formCollection["ConnectionParameterValue1"] = "value1";

            // act
            List <ConnectionParameterModel> connectionParameterList = ConnectionParameterModel.FromFormCollection(formCollection);

            // assert
            Assert.IsTrue(connectionParameterList.Count == 1);
            Assert.IsTrue(connectionParameterList[0].Key == "key1");
            Assert.IsTrue(connectionParameterList[0].Value == "value1");
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            ConnectionModel connection = null;

            try
            {
                connection = this._connectionRepository.GetConnection(id);
                if (connection == null)
                {
                    return(View("NotFound", "The specified connection was not found"));
                }

                this.UpdateModel(connection);
                connection.ConnectionParameters.Clear();
                connection.ConnectionParameters.AddRange(ConnectionParameterModel.FromFormCollection(collection));

                if (connection.IsValid)
                {
                    IEnumerable <RuleViolation> ruleViolations = null;
                    if (!this._connectionRepository.IsValid(connection, out ruleViolations))
                    {
                        ModelState.AddRuleViolations(ruleViolations);
                        return(View(connection));
                    }
                    this._connectionRepository.Save();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddRuleViolations(connection.GetRuleViolations());
                    return(View(connection));
                }
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            ConnectionModel connection = null;

            try
            {
                connection = new ConnectionModel();
                this.UpdateModel(connection);
                connection.ConnectionParameters.Clear();
                connection.ConnectionParameters.AddRange(ConnectionParameterModel.FromFormCollection(collection));

                if (connection.IsValid)
                {
                    IEnumerable <RuleViolation> ruleViolations = null;
                    if (!this._connectionRepository.IsValid(connection, out ruleViolations))
                    {
                        ModelState.AddRuleViolations(ruleViolations);
                        return(View(connection));
                    }

                    this._connectionRepository.AddConnection(connection);
                    this._connectionRepository.Save();
                }
                else
                {
                    ModelState.AddRuleViolations(connection.GetRuleViolations());
                    return(View(connection));
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }