public void EditTest() { Connection v = new Connection(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.Name = "KgH"; v.Host = "gMTL"; v.Port = 12; v.Database = "tBEa"; v.Username = "******"; v.Password = "******"; v.ID = 10; context.Set <Connection>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(ConnectionVM)); ConnectionVM vm = rv.Model as ConnectionVM; v = new Connection(); v.ID = vm.Entity.ID; v.Name = "us3obVjYg"; v.Host = "Dv6R8YTw"; v.Port = 61; v.Database = "KGi"; v.Username = "******"; v.Password = "******"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.Name", ""); vm.FC.Add("Entity.Host", ""); vm.FC.Add("Entity.Port", ""); vm.FC.Add("Entity.Database", ""); vm.FC.Add("Entity.Username", ""); vm.FC.Add("Entity.Password", ""); vm.FC.Add("Entity.ID", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Connection>().FirstOrDefault(); Assert.AreEqual(data.Name, "us3obVjYg"); Assert.AreEqual(data.Host, "Dv6R8YTw"); Assert.AreEqual(data.Port, 61); Assert.AreEqual(data.Database, "KGi"); Assert.AreEqual(data.Username, "5SGjrD"); Assert.AreEqual(data.Password, "MH10RD"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
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); }
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); }
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"); }
public void Edit_Get_Should_Display_Error_When_Invalid_Id() { // arrange FakeConnectionRepository connectionRepository = new FakeConnectionRepository(); ConnectionController connectionController = new ConnectionController(connectionRepository); // act ViewResult viewResult = connectionController.Edit(1) as ViewResult; // assert Assert.IsNotNull(viewResult); Assert.IsTrue(viewResult.ViewName == "NotFound"); }
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); }
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); }