Ejemplo n.º 1
0
 public void CreateWithExistingCustomerId()
 {
     long? existingcustomerId = 1;
     string stringifiedexistingCustomerId = Convert.ToString(existingcustomerId.Value);
     var customer = new customer { customerID = existingcustomerId.Value, name = "Test customer", state = "Florida" };
     customer.customerList = new List<SelectListItem>();
     customer.StateList = new List<SelectListItem>();
     customer.TrainList = new List<SelectListItem>();
     customer.CityList = new List<SelectListItem>();
     mockedCustomerRepository.Setup(m => m.FindById(stringifiedexistingCustomerId)).Returns(customer);
     var customerList = new List<customer> { customer };
     mockedRepositoryCustomer.Setup(m => m.GetAll()).Returns(customerList.AsQueryable());
     var stateList = new List<source>() { new source { state = "FL", state_name = "Florida", city = "Florida" } };
     mockedCustomerRepository.Setup(m => m.GetStateList()).Returns(stateList);
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     var returnObj = controller.Create(existingcustomerId);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(PartialViewResult));
     var result = (PartialViewResult)returnObj;
     Assert.IsNotNull(result);
     mockedCustomerRepository.Verify(m => m.FindById(Convert.ToString(existingcustomerId)), Times.Once());
     mockedRepositoryCustomer.Verify(m => m.GetAll(), Times.Once());
     mockedCustomerRepository.Verify(m => m.GetStateList(), Times.Once());
 }
        public void WaterConductivity()
        {
            long customerId = 1;
            SystemSummaryViewModel systemSummaryViewModel = new SystemSummaryViewModel();
            mockedICustomerRepository.Setup(m => m.GetAll()).Returns(new List<customer>().AsQueryable());
            mockedCustomerRepository.Setup(m => m.GetWaterSourceIds(customerId)).Returns(new customer_water() { first_sourceID = 1, second_sourceID = 1 });
            mockedCustomerRepository.Setup(m => m.GetCustomerTrains(customerId)).Returns(new List<train>());
            //mockedVesselRepository.Setup(m => m.GetAll()).Returns((new List<vessel>()).AsQueryable());

            var controller = new ConductivityController(mockedConductivityRepository.Object, mockedConductivityService.Object, mockedICustomerRepository.Object, mockedCustomerRepository.Object);
            controller.ControllerContext = new ControllerContext();
            var mockedHttpContext = new Mock<HttpContextBase>();
            var mockedSessionState = new HttpSessionMock();
            mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
            controller.ControllerContext.HttpContext = mockedHttpContext.Object;
            controller.ControllerContext.HttpContext.Session["CustomerId"] = customerId;
            controller.ControllerContext.HttpContext.Session["HasTrainDetails"] = "Verify";

            var returnObj = controller.WaterConductivity();
            Assert.IsNotNull(returnObj);
            Assert.IsInstanceOfType(returnObj, typeof(ViewResult));
            var result = (ViewResult)returnObj;
            Assert.IsNotNull(result);
            mockedICustomerRepository.Verify(m => m.GetAll(), Times.Once());
            mockedCustomerRepository.Verify(m => m.GetWaterSourceIds(customerId), Times.Once());
            mockedCustomerRepository.Verify(m => m.GetCustomerTrains(customerId), Times.Once());
            //mockedVesselRepository.Verify(m => m.GetAll(), Times.Once());
        }
Ejemplo n.º 3
0
 public void CreateWithoutExistingCustomerIdWithDuplicate()
 {
     var customer = new customer { customerID = (long)1, name = "Test customer", state = "Florida" };
     customer.customerList = new List<SelectListItem>();
     customer.StateList = new List<SelectListItem>();
     customer.TrainList = new List<SelectListItem>();
     customer.CityList = new List<SelectListItem>();
     mockedCustomerRepository.Setup(m => m.FindById(It.IsAny<string>())).Verifiable();
     var customerList = new List<customer> { customer };
     mockedRepositoryCustomer.Setup(m => m.GetAll()).Returns(customerList.AsQueryable());
     var stateList = new List<source>() { new source { state = "FL", state_name = "Florida", city = "Florida" } };
     mockedCustomerRepository.Setup(m => m.GetStateList()).Returns(stateList);
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedSessionState["IsDuplicate"] = "True";
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     long? customerId = null;
     var returnObj = controller.Create(customerId);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(PartialViewResult));
     var result = (PartialViewResult)returnObj;
     Assert.IsNotNull(result);
     Assert.AreEqual(result.ViewName, "_Create");
     Assert.AreEqual(result.ViewData.ModelState.IsValid, false);
     Assert.AreEqual(result.ViewData.ModelState["notes"].Errors[0].ErrorMessage, "Customer Already exists");
     mockedCustomerRepository.Verify(m => m.FindById(Convert.ToString(It.IsAny<string>())), Times.Never());
     mockedRepositoryCustomer.Verify(m => m.GetAll(), Times.Once());
     mockedCustomerRepository.Verify(m => m.GetStateList(), Times.Once());
 }
Ejemplo n.º 4
0
 public void UpdateCustomerWithErrors()
 {
     customer customer = new customer() { customerID = 1 };
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     controller.ModelState.AddModelError("Error", "ErrorMessage"); ;
     var returnObj = controller.Create(customer);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(RedirectToRouteResult));
     var result = (RedirectToRouteResult)returnObj;
     Assert.IsNotNull(result);
     mockedCustomerRepository.Verify(m => m.CheckForDuplicates(customer), Times.Never());
     mockedCustomerRepository.Verify(m => m.UpdateCustomer(customer), Times.Never());
 }
Ejemplo n.º 5
0
 public void UpdateCustomer()
 {
     customer customer = new customer() { customerID = 1 };
     bool IsDuplicate = false;
     mockedCustomerRepository.Setup(item => item.CheckForDuplicates(customer)).Returns(IsDuplicate);
     mockedCustomerRepository.Setup(item => item.UpdateCustomer(customer)).Verifiable();
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     var returnObj = controller.Create(customer);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(RedirectToRouteResult));
     var result = (RedirectToRouteResult)returnObj;
     Assert.IsNotNull(result);
     mockedCustomerRepository.Verify(m => m.CheckForDuplicates(customer), Times.Never());
     mockedCustomerRepository.Verify(m => m.UpdateCustomer(customer), Times.Once());
 }
Ejemplo n.º 6
0
 public void SaveCustomer()
 {
     customer customer = new customer() { customerID = -1 };
     long newCustomerId = 0;
     mockedRepositoryCustomer.Setup(item => item.InsertAndGetID(customer)).Returns(newCustomerId);
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     var returnObj = controller.Create(customer);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(RedirectToRouteResult));
     var result = (RedirectToRouteResult)returnObj;
     Assert.IsNotNull(result);
     mockedRepositoryCustomer.Verify(m => m.InsertAndGetID(customer), Times.Once());
 }
Ejemplo n.º 7
0
 public void EditCustomerSaveFail()
 {
     customer customer = new customer();
     var controller = new CustomerController(mockedRepositoryCustomer.Object, mockedCustomerRepository.Object, mockedRepositorySource.Object);
     controller.ControllerContext = new ControllerContext();
     var mockedHttpContext = new Mock<HttpContextBase>();
     var mockedSessionState = new HttpSessionMock();
     mockedHttpContext.SetupGet(ctx => ctx.Session).Returns(mockedSessionState);
     controller.ControllerContext.HttpContext = mockedHttpContext.Object;
     controller.ModelState.AddModelError("Error", "ErrorMessage"); ;
     var returnObj = controller.Edit(customer);
     Assert.IsNotNull(returnObj);
     Assert.IsInstanceOfType(returnObj, typeof(ViewResult));
     var result = (ViewResult)returnObj;
     Assert.IsNotNull(result);
 }