コード例 #1
0
        public void Edit_Post_Should_Redisplay_With_Errors_When_Duplicate_Name()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });
            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 2, Name = "connection2"
            });

            FormCollection formCollection = new FormCollection();

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

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Edit(1, formCollection) as ViewResult;

            // assert
            Assert.IsTrue(viewResult.ViewData.ModelState["Name"].Errors.Count == 1);
        }
コード例 #2
0
        public void Edit_Post_Should_Redisplay_With_Errors_When_Invalid()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });

            FormCollection formCollection = new FormCollection();

            formCollection["Name"] = String.Empty;

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult viewResult = connectionController.Edit(1, formCollection) as ViewResult;

            // assert
            Assert.IsTrue(viewResult.ViewData.Model is ConnectionModel);
            Assert.IsTrue(viewResult.ViewData.ModelState["Name"].Errors.Count > 0);
        }
コード例 #3
0
        public void Edit_Post_Should_Update_Connection_When_Valid()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });

            FormCollection formCollection = new FormCollection();

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

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            connectionController.ValueProvider = formCollection.ToValueProvider();

            // act
            ViewResult      viewResult = connectionController.Edit(1, formCollection) as ViewResult;
            ConnectionModel connection = connectionRepository.GetConnection(1);

            // assert
            Assert.IsTrue(connection.Name == "connectionA");
        }
コード例 #4
0
        public void Index_Get_Should_Display_Connections()
        {
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });
            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 2, Name = "connection2"
            });

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            // act
            ViewResult viewResult = connectionController.Index() as ViewResult;
            IEnumerable <ConnectionModel> connectionList = viewResult.ViewData.Model as IEnumerable <ConnectionModel>;

            // assert
            Assert.IsNotNull(connectionList);
            Assert.IsTrue(connectionList.Count() == 2);
        }
コード例 #5
0
        public void Edit_Get_Should_Return_View_When_Valid_Id()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            // act
            ViewResult viewResult = connectionController.Edit(1) as ViewResult;

            // assert
            Assert.IsNotNull(viewResult);
        }
コード例 #6
0
        public void Edit_Get_Should_Display_Connection_When_Valid_Id()
        {
            // arrange
            FakeConnectionRepository connectionRepository = new FakeConnectionRepository();

            connectionRepository.AddConnection(new ConnectionModel()
            {
                ConnectionId = 1, Name = "connection1"
            });

            ConnectionController connectionController = new ConnectionController(connectionRepository);

            // act
            ViewResult      viewResult = connectionController.Edit(1) as ViewResult;
            ConnectionModel connection = viewResult.ViewData.Model as ConnectionModel;

            // assert
            Assert.IsNotNull(connection);
            Assert.IsTrue(connection.ConnectionId == 1);
        }