public void CustomerController_TestCreateCustomer() { // Arrange customerController.ControllerContext.HttpContext.Session["UserID"] = 1; var customerToAdd = new Customer { firstName = "SiriusTest", lastName = "BlackTest", status = CustomerStatus.Active }; //Check var result1 = customerController.Index("") as ViewResult; var customers1 = (IEnumerable <Customer>)result1.ViewData.Model; Assert.AreEqual(2, customers1.ToList().Count); Assert.AreEqual(UnitTestsHelper.ListContains(customers1, "SiriusTest"), false); //Act customerController.Create(customerToAdd); var result = customerController.Index("") as ViewResult; //Assert var customers = (IEnumerable <Customer>)result.ViewData.Model; Assert.AreEqual(3, customers.ToList().Count); Assert.AreEqual(UnitTestsHelper.ListContains(customers, "SiriusTest"), true); }
public void Create_should_return_same_view_when_not_valid() { sut.ModelState.AddModelError("x", "asdasd"); var result = sut.Create(new CustomerEditViewModel()) as ViewResult; Assert.IsNull(result.ViewName); //Same as Action }
public void CreateCustomerIsNull() { var response = controller.Create(null); Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest); Assert.AreEqual(((System.Net.Http.ObjectContent)response.Content).Value, Messages.CustomerDataPassedIsNullOrCouldNotBeParsed); }
public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(CustomerVM)); CustomerVM vm = rv.Model as CustomerVM; Customer v = new Customer(); v.CustomerName = "NgFJvC0s"; v.Contract = "hvW"; v.ContractPhone = "wJ33Sm"; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Customer>().FirstOrDefault(); Assert.AreEqual(data.CustomerName, "NgFJvC0s"); Assert.AreEqual(data.Contract, "hvW"); Assert.AreEqual(data.ContractPhone, "wJ33Sm"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
public void Test_CreateCustomer_IsBeingCreated() { var id = Guid.NewGuid(); var newCustomer = new Customer() { Id = id, Name = "Peter Jacobsen", Address = "Kaløgade 7, 8000 Aarhus" }; _customerController.Create(newCustomer); var result = _customerController.Get(newCustomer.Id); Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); }
public void Create_Customer() { var customer = new Customer { Id = 10, Name = "Ica Sollentuna", CorporateStucture = "Ica", CreditLimit = -1, CustomerAuditCode = 12, OrganisationNumber = "SE0001" }; _customerController.Create(customer); _mockSetCustomer.Verify(x => x.Add(customer), Times.Once); _mockContext.Verify(x => x.SaveChanges(), Times.Once); }
public void Task_Register_Return_View() { var controller = new CustomerController(context); var cust = new Customers() { FirstName = "Sambhav", LastName = "Jain", Username = "******", EmailId = "*****@*****.**", Address = "Mayapuri", State = "Delhi", Country = "India", PhoneNo = 98567485235, Zip = 110064, Gender = "Female" }; var data = controller.Create(); Assert.NotNull(data); }
public void CreateCustomerNotNull() { CustomerController controller = new CustomerController(); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); }
private void Button_Click_Save_Customer(object sender, RoutedEventArgs e) { if ( TCustomer_name.Text.Equals("") || TAddress.Text.Equals("") || TDocument_nro.Equals("") || TEmail.Text.Equals("") || TPhone.Text.Equals("") ) { MessageBox.Show("Deben completarse todos los campos!"); } else { var customer = GetCamposCustomer(); // leo y cargo todos los valores de los campos en un objeto Customer var customerController = new CustomerController(); if (this.TCustomerID.Text.Equals(Modo.CREACION.ToString())) { customerController.Create(customer); } else { customerController.Edit(customer); } CustomersList.ItemsSource = customerController.GetAll(); //vuelvo a cargar todos los customers MessageBox.Show("Cliente Guardado!!!"); CustomersList.Items.Refresh(); SetModo(Modo.LECTURA); SetCamposCustomer(customer); } }
public void TestMethod1() { CustomerController controller = new CustomerController(); Customer customer = new Customer("TestName", "TestPhonenumber", "TestEmail", "m1", null); controller.Create(customer, "m1"); }
public void CanAddCustomer() { // arrange IRepo <Customer> customerRepo = new MockContext <Customer>(); IRepo <Car> carRepo = new MockContext <Car>(); IRepo <Reservation> reservationRepo = new MockContext <Reservation>(); IRepo <Location> locationRepo = new MockContext <Location>(); IRepo <Model> modelRepo = new MockContext <Model>(); IRepo <Manufacturer> manufacturerRepo = new MockContext <Manufacturer>(); var controller = new CustomerController(carRepo, customerRepo, reservationRepo, locationRepo, modelRepo, manufacturerRepo); var customerFactory = new CustomerFactory(); var customer = customerFactory.GetQueryCustomer(1, 1, "c"); // act controller.Create(customer); Customer c = customerRepo.Collection().FirstOrDefault(); // assert Assert.IsNotNull(c); Assert.AreEqual(1, customerRepo.Collection().Count()); Assert.AreEqual("c", c.Name); }
public void Create_Post_Adds_The_Customer_And_Redirects_To_The_Index_Page_With_A_Valid_Customer() { /* * Arrange * 1º - Create a dummy list of customers * 2º - Initialize stub of SICustomerManagementService * 3º - Create controller to test */ Customer customer = new Customer() { CustomerCode = "A0001" }; IList <Customer> customers = new List <Customer>(); SICustomerManagementService customerService = new SICustomerManagementService(); customerService.AddCustomerCustomer = x => customers.Add(customer); CustomerController controller = new CustomerController(customerService); //Act RedirectToRouteResult result = controller.Create(customer) as RedirectToRouteResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.RouteValues["page"]); Assert.AreEqual(10, result.RouteValues["pageSize"]); Assert.AreEqual(1, customers.Count); Assert.AreEqual("A0001", customers.First().CustomerCode); }
public void Create_RedirectsToCorrectAction_Index() { CustomerController controller = new CustomerController(); RedirectToActionResult actionResult = controller.Create("Ty", "Butts", "123123312234", "*****@*****.**", "Some road somewhere", "Portland", "Maine", 22030) as RedirectToActionResult; string result = actionResult.ActionName; Assert.AreEqual(result, "index"); }
private void CreateCustomerButton_Click(object sender, EventArgs e) { try { currentEmployee = cmbEmployeesCustomer.SelectedItem as Employee; if (cmbEmployeesCustomer.Text != "") { int empId = Int32.Parse(cmbEmployeesCustomer.Text); currentEmployee = EmployeeController.FindById(empId); } if (currentEmployee == null) { lblresponse.Text = "No Employee selected"; return; } String tempId = txtCustId.Text; tempId = tempId.Trim(); if (String.IsNullOrEmpty(tempId)) { lblresponse.Text = "Id box is empty"; return; } Customer cust = new Customer(); cust.CustomerId = Int32.Parse(tempId); cust.Name = txtCustName.Text; cust.Name = cust.Name.Trim(); cust.Employee = currentEmployee; if (cust.CustomerId < 0) { lblresponse.Text = "Id is less than 0"; return; } if (String.IsNullOrEmpty(cust.Name)) { lblresponse.Text = "You need to write a name"; return; } bool success = CustomerController.Create(cust); if (success) { lblresponse.Text = "Customer Created for " + currentEmployee.Name; } else { lblresponse.Text = "Failed to create Customer"; } } catch (Exception ex) { lblresponse.Text = ErrorHandlern.HandleExceptions(ex); } FillListWithAllCustomers(); }
public void CreateHttpPost() { // Arrange var mock = mockIUnitOfWork(); CustomerController controller = new CustomerController(mock); //ID of the Customer to Edit int id = 1; //customer object returned by html form and passed as a parameter to function Customer source = new Customer { Customer_Id = 3, Customer_Name = "Marc", Contact_Name = "Marc", Contact_Info = new List <ContactInfo> { new ContactInfo { Contact_Info_Id = 1, type = new ContactType { Contact_Type_Id = 1 }, detail = "+1786" }, new ContactInfo { Contact_Info_Id = 2, type = new ContactType { Contact_Type_Id = 2 }, detail = "*****@*****.**" } }, Customer_Type = new CustomerType { Customer_Type_Id = 1 } }; // Act //ViewResult result = controller.Create(source) as ViewResult; var result = (RedirectToRouteResult)controller.Create(source); // Assert //Assert.AreEqual("Index", result.RouteValues["action"]); //Assert.AreEqual("Home", result.RouteValues["controller"]); //AreEqual("Home", result.RouteValues["controller"]) will return null if //if you call redirectAction like this: RedirectToAction("Index"); //it will return a string if you call it like this: //RedirectToAction("Index", "Customer"); //or use below Assert.IsTrue( result.RouteValues["action"].Equals("Index") //&& result.RouteValues["controller"].Equals("Customer") ); }
public void CreateShouldBeNotNull() { //Arrange var mock = new Mock <ICustomerManager>(); var controller = new CustomerController(mock.Object); //Act var result = controller.Create() as ViewResult; //Assert Assert.IsNotNull(result); }
public void Create() { // Arrange var mock = mockIUnitOfWork(); CustomerController controller = new CustomerController(mock); // Act ViewResult result = controller.Create() as ViewResult; // Assert Assert.IsNotNull(result); }
public void ShouldInsertCustomer() { EngineContext.Current.Initialize(); CustomerController homeController = EngineContext.Current.Resolve <CustomerController>(); var customerModel = new CustomerModel() { IsTaxExempt = true, Active = true, FirstName = "dinesh", LastName = "matkar", MobileNumber = "8788069883", Email = "*****@*****.**" }; homeController.Create(customerModel); Assert.IsTrue(customerModel.Id > 0); }
public async Task Customer_ShouldCreateNewCustomerAsync() { // Assemble var context = new ApplicationContext(DbAssembly().Options); var customerController = new CustomerController(context, new AppointmentBookingService()); var customer = (new Customer()); // Act await customerController.Create(customer); // Assert Assert.NotEmpty(context.Customers); }
public void CreateCustomerTest() { TestCustomersContext C = new TestCustomersContext(); CustomerController controller = new CustomerController(C); Customer customerToCreate = new Customer() { CustomerID = 13, CName = "Bob", CAddress = "Tallaght", Phone = "08744458" }; var result = controller.Create(customerToCreate) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }
public void Create_should_redirect_to_Index() { // Arrange var mockDataRepository = new Mock <IDataRepository>(); CustomerController sut = new CustomerController(mockDataRepository.Object); // Act var result = sut.Create(new CustomerModel()) as RedirectToRouteResult; // Assert Assert.AreEqual(result.RouteValues["Action"], "Index"); }
public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(CustomerVM)); CustomerVM vm = rv.Model as CustomerVM; Customer v = new Customer(); v.CardNum = "Ododn6F"; v.StationId = AddStation(); v.AreaId = AddArea(); v.communityId = Addcommunity(); v.buildingId = Addbuilding(); v.Unit = "JFwD3"; v.Room = 12; v.CustomerName = "UGbmE"; v.IDCard = "vVV"; v.BuildingArea = 98; v.HeatingArea = 92; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <Customer>().Find(v.ID); Assert.AreEqual(data.CardNum, "Ododn6F"); Assert.AreEqual(data.Unit, "JFwD3"); Assert.AreEqual(data.Room, 12); Assert.AreEqual(data.CustomerName, "UGbmE"); Assert.AreEqual(data.IDCard, "vVV"); Assert.AreEqual(data.BuildingArea, 98); Assert.AreEqual(data.HeatingArea, 92); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
public void CustomerCreate_RedirectsToIndexPage_IfPostSuccessful() { //ARRANGE var testCustomer = new CustomerModel(); var testController = new CustomerController(CreateIRepository()); //ACT var result = testController.Create(testCustomer); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); //ASSERT Assert.Equal("Index", redirectToActionResult.ActionName); }
public async Task Create_OnPost_WithModelStateInvalid_ReturnsCreateViewWithSameData() { // Arrange CustomerController controller = new CustomerController(_orderRepository.Object, _customerRepository.Object); controller.ModelState.AddModelError("Required", "UserName Parameter Required"); // Act ViewResult result = await controller.Create(TestCVM) as ViewResult; CustomerViewModel resultCVM = (CustomerViewModel)result.Model; //Assert Assert.IsTrue("Create" == result.ViewName); }
public async void AddCustomer_ReturnCorrectAction() { // Arrange var controller = new CustomerController(_context); // Act var cust = new Customer(); cust.firstName = "AddCustomerTest"; cust.emailAddress = "*****@*****.**"; var result = await controller.Create(cust); // Assert Xunit.Assert.IsType <CreatedAtActionResult>(result); }
public void WhenNationalCodeLenth10ModelIsValid() { var controller = new CustomerController(); var model = new CustomerModel() { FirstName = "Morsal", LastName = "Mousavi", NationalCode = "0014071460" }; var result = controller.Create(model); Assert.True(controller.ModelState.IsValid); }
public void CreateCustomer_Test() { var service = new Mock <CustomerService>(); var fakeCustomer = new Mock <CustomerCreateDto>(); //Arrange service.Setup(x => x.Create(fakeCustomer.Object)) .Returns(new CustomerDto()); //Act var controller = new CustomerController(service.Object); var result = controller.Create(fakeCustomer.Object); //Assert Assert.IsType <OkResult>(result); }
public void CustomerCreate_ReturnsAViewResult_IfExceptionThrown() { //ARRANGE var testCustomer = new CustomerModel(); var mockIRepo = new Mock <IRepository>(); mockIRepo.Setup(c => c.AddCustomer(testCustomer)).Throws <Exception>(); var testController = new CustomerController(mockIRepo.Object); //ACT var result = testController.Create(testCustomer); //ASSERT Assert.IsType <ViewResult>(result); }
public void Create_should_return_view() { // Arrange var mockDataRepository = new Mock <IDataRepository>(); CustomerController sut = new CustomerController(mockDataRepository.Object); sut.ModelState.AddModelError("", "Error"); // Act var result = sut.Create(null); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual(((ViewResult)result).ViewName, ""); }
public void Can_create_customer_null_entity() { //Arrange const string expected = "Entity is not valid"; var mockCustomerService = new Mock <ICustomerService>(); var mockSecurityContext = new Mock <ISecurityContext>(); mockSecurityContext.Setup(m => m.UserName).Returns("NewName"); var controller = new CustomerController(mockCustomerService.Object, mockSecurityContext.Object); //Act var actual = controller.Create(null) as BadRequestErrorMessageResult; Assert.IsNotNull(actual); Assert.AreEqual(expected, actual.Message); }