public void TestIndexViewFindsCorrectServicesMultipleServices()
        {
            var repository = new Mock <IServicesRepository>();

            Service service1 = new Service();

            service1.ServiceName = "UnitTest ServiceName";

            Service service2 = new Service();

            service2.ServiceName = "Another UnitTest ServiceName";

            repository.Setup(m => m.GetServicesForUserName(TEST_USER_NAME)).Returns(() => new List <Service> {
                service1, service2
            });

            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);


            ViewResult     result         = controller.Index() as ViewResult;
            List <Service> resultServices = result.Model as List <Service>;

            CollectionAssert.AreEquivalent(new List <Service> {
                service1, service2
            }, resultServices);
        }
        public void TestIndexReturnsView()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
        public void TestIndexViewNoServicesForUserName()
        {
            var repository = new Mock <IServicesRepository>();

            repository.Setup(m => m.GetServicesForUserName(TEST_USER_NAME)).Returns(() => null);

            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNull(result.Model);
        }
        public void TestDeleteServiceGETCantFindId()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            int ServiceId = 1;

            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => null);
            ViewResult result = controller.Delete(ServiceId) as ViewResult;

            Assert.IsNull(result);
        }
        public void TestAddService()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            Service service = new Service();

            service.ServiceName = "UnitTest ServiceName";

            controller.Create(service);

            repository.Verify(r => r.AddService(It.IsAny <Service>()), Times.Once);
        }
        public void TestDeleteServiceGETCanFindIdOtherServiceOwner()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            int     ServiceId = 1;
            Service service1  = new Service();

            service1.ServiceName  = "UnitTest ServiceName";
            service1.ServiceOwner = "Not " + TEST_USER_NAME;
            service1.ServiceiD    = ServiceId;

            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => service1);
            ViewResult result = controller.Delete(ServiceId) as ViewResult;

            Assert.IsNull(result);
        }
        public void TestEditServicePOSTOtherServiceOwner()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            int     ServiceId = 1;
            Service service1  = new Service();

            service1.ServiceName  = "UnitTest ServiceName";
            service1.ServiceOwner = "Not " + TEST_USER_NAME;
            service1.ServiceiD    = ServiceId;
            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => service1);

            ViewResult resultView = controller.Edit(service1) as ViewResult;

            Assert.AreEqual(service1, resultView.Model);
        }
        public void TestIndexViewFindsCorrectServicesOneService()
        {
            var repository = new Mock <IServicesRepository>();

            Service service = new Service();

            service.ServiceName = "UnitTest ServiceName";
            repository.Setup(m => m.GetServicesForUserName(TEST_USER_NAME)).Returns(() => new List <Service> {
                service
            });

            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            ViewResult     result         = controller.Index() as ViewResult;
            List <Service> resultServices = result.Model as List <Service>;

            Assert.AreEqual(service, resultServices[0]);
        }
        public void TestDeleteServicePOST()
        {
            var repository = new Mock <IServicesRepository>();
            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            int     ServiceId = 1;
            Service service1  = new Service();

            service1.ServiceName  = "UnitTest ServiceName";
            service1.ServiceOwner = TEST_USER_NAME;
            service1.ServiceiD    = ServiceId;

            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => service1);

            RedirectToRouteResult result = controller.DeleteConfirmed(ServiceId) as RedirectToRouteResult;

            repository.Verify(r => r.DeleteService(It.IsAny <Service>()), Times.Once);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void TestDetailsNoServiceWithThatId()
        {
            var repository = new Mock <IServicesRepository>();

            int     ServiceId = 1;
            Service service1  = new Service();

            service1.ServiceName  = "UnitTest ServiceName";
            service1.ServiceOwner = TEST_USER_NAME;
            service1.ServiceiD    = ServiceId;

            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => null);

            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            ViewResult result = controller.Details(ServiceId) as ViewResult;

            Assert.IsNull(result);
        }
        public void TestDetailsCanFindService()
        {
            var repository = new Mock <IServicesRepository>();

            int     ServiceId = 1;
            Service service1  = new Service();

            service1.ServiceName  = "UnitTest ServiceName";
            service1.ServiceOwner = TEST_USER_NAME;
            service1.ServiceiD    = ServiceId;

            repository.Setup(m => m.GetServiceById(ServiceId)).Returns(() => service1);

            var controller = ServicesController.CreateServicesControllerAs(TEST_USER_NAME, repository.Object);

            ViewResult result = controller.Details(ServiceId) as ViewResult;

            Service resultService = result.Model as Service;

            Assert.AreEqual(service1, resultService);
        }