public void CheckIfEditServiceWorks() { // Arrange var servicesController = new ServicesController() { Request = new HttpRequestMessage { RequestUri = new Uri("http://localhost:44382/api/services") }, Configuration = new HttpConfiguration() }; try { // Act var result = servicesController.GetService(1); Service service; result.TryGetContentValue <Service>(out service); string noneupdatedtitle = service.Title; service.Title = "Test"; var response = servicesController.EditService(service); var newresult = servicesController.GetService(1); Service actual; newresult.TryGetContentValue <Service>(out actual); // Assert Assert.IsTrue(response.IsSuccessStatusCode); Assert.AreNotEqual(actual.Title, noneupdatedtitle); } catch (Exception) { Assert.Fail(); } }
public void TestRemove() { //Arrange ServiceContext c = new ServiceContext(); var fakeRepo = new FakeServicesRepository(); var controller = new ServicesController(fakeRepo, c); var Service = new ServiceModel() { ServiceID = 0, ServiceName = "SomeJob", ServiceDescription = "FAKE REPO TEST", ServiceEstimated = "more for testing the repo fake", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; //Act controller.Edit(Service); // adds controller.Delete(Service); // and deletes // Assert Checking that story was added. Assert.Empty(fakeRepo.service); }
public void TestDeleteService() { Service a = new Service() { ServiceId = "1", Name = "Service1", Building = "1" }; var mockServiceValidator = new Mock <IServiceValidator>(); mockServiceValidator.Setup(x => x.DeleteService("1")).Verifiable(); mockServiceValidator.Setup(x => x.secure(null)).Verifiable(); mockServiceValidator.Setup(x => x.AtmSecure(null)).Verifiable(); var controller = new ServicesController(mockServiceValidator.Object); var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add("TODO_PAGOS_TOKEN", "1"); controllerContext.Request = request; controller.ControllerContext = controllerContext; IHttpActionResult actionResult = controller.DeleteService("1"); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <Service> >; Assert.IsNotNull(actionResult); }
public ServicesControllerTests() { var user = new ClaimsPrincipal(new ClaimsIdentity( new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), new Claim(ClaimTypes.Role, "Admin"), }, "mock")); var httpContext = new DefaultHttpContext(); httpContext.Request.Headers["Cookie"] = $"access_token=xxxxx"; httpContext.User = user; _mockServiceImageUseCase = new Mock <IServiceImageUseCase>(); _mockGetAddressesUseCase = new Mock <IGetAddressesUseCase>(); _mockDeleteServiceUseCase = new Mock <IDeleteServiceUseCase>(); _mockUpdateServiceUseCase = new Mock <IUpdateServiceUseCase>(); _mockGetServicesUseCase = new Mock <IGetServicesUseCase>(); _mockCreateServiceUseCase = new Mock <ICreateServiceUseCase>(); _classUnderTest = new ServicesController( _mockCreateServiceUseCase.Object, _mockGetServicesUseCase.Object, _mockDeleteServiceUseCase.Object, _mockUpdateServiceUseCase.Object, _mockGetAddressesUseCase.Object, _mockServiceImageUseCase.Object) { ControllerContext = new ControllerContext { HttpContext = httpContext } }; }
public async void Delete_ReturnServiceViewResult(int commentID) { var size = Context.CommentAndEvaluation.Count(); var comment = Context.CommentAndEvaluation.Find(commentID); var servicesController = new ServicesController(Context, UserManager); Controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; servicesController.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await Controller.Delete(commentID); Assert.IsType <ViewResult>(servicesController.Details(comment.ServiceID).Result); //Confirmar Index var resultIndex = await Controller.Index(); var viewResultIndex = Assert.IsType <ViewResult>(resultIndex); var modelIndex = Assert.IsAssignableFrom <IEnumerable <CommentAndEvaluation> >(viewResultIndex.ViewData.Model); Assert.NotNull(modelIndex); Assert.Equal(size - 1, modelIndex.Count()); }
public void CheckIfCreateNewServicesWorks() { // Arrange var servicesController = new ServicesController() { Request = new HttpRequestMessage { RequestUri = new Uri("http://localhost:44382/api/services") }, Configuration = new HttpConfiguration() }; try { // Act Service service = new Service() { ServiceId = 1, Title = "Test1", Description = "Test1", Duration = 30, Price = 300, Gender = "Male" }; var response = servicesController.CreateNewService(service); // Assert Assert.IsTrue(response.IsSuccessStatusCode); Assert.AreEqual("Test1", service.Title); } catch (Exception) { Assert.Fail(); } }
public void AskQuestion_ShouldSendTheEmailToTheCustomer() { //Arrange var wishListBuilder = MockRepository.GenerateStub <IViewModelBuilder>(); wishListBuilder.Stub(x => x.Build()).Return(new WishListViewModel()); var pathBarGenerator = MockRepository.GenerateStub <IPathBarGenerator>(); var settingManager = new FakeSettingManager(); var userMailer = MockRepository.GenerateMock <IUserMailer>(); userMailer.Expect( y => y.AskQuestionCustomerVersion(Arg <string> .Is.Equal("email"), Arg <AskQuestionEmailTemplateViewModel> .Matches( x => x.Email == "email" && x.Name == "name" && x.Phone == "phone" && x.Question == "question"))).Repeat.Once(); var conrtoller = new ServicesController(wishListBuilder, pathBarGenerator, userMailer, settingManager); //Act var result = conrtoller.AskQuestion("name", "email", "phone", "question"); //Assert userMailer.VerifyAllExpectations(); }
public void AskQuestion_ShouldReturnAJsonWithErrorIfMailerThrowsException() { //Arrange var wishListBuilder = MockRepository.GenerateStub <IViewModelBuilder>(); wishListBuilder.Stub(x => x.Build()).Return(new WishListViewModel()); var pathBarGenerator = MockRepository.GenerateStub <IPathBarGenerator>(); var settingManager = new FakeSettingManager(); var userMailer = MockRepository.GenerateStub <IUserMailer>(); userMailer.Stub( y => y.AskQuestionAdminVersion(Arg <string> .Is.Anything, Arg <AskQuestionEmailTemplateViewModel> .Is.Anything)).Throw(new Exception()); var conrtoller = new ServicesController(wishListBuilder, pathBarGenerator, userMailer, settingManager); //Act var result = conrtoller.AskQuestion("name", "email", "phone", "question") as JsonResult; //Assert var actual = result.Data as OporationWithoutReturnValueJsonModel; actual.HasError.Should().BeTrue(); }
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 Search_Without_Location() { var sessionMock = new Mock <ISession>(); var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName); var services = GetSampleServices(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <IQuery <IEnumerable <Service> > >())) .Returns(services); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >())) .Returns(categories); var fileSystemMock = new Mock <IFileSystem>(); var geoCodingServicemMock = new Mock <IGeoCodingService>(); var userLocation = PointFactory.Create(6.9319444, 79.8877778); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName)); controller.SetUserInfoWitLocation(userLocation); var model = new SearchModel { Terms = "Foo" }; controller.Search(model); Assert.AreEqual(model, controller.ViewData.Model); Assert.AreEqual(userLocation, controller.ViewData[ViewDataKeys.UserLocation]); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { using (var repo = new Repo ()) { repo.Initialize (); // // Load initial data // var services = repo.GetActiveServices(); if (services.Count == 0) { repo.InsertDefaultServices(); } } _services = new ServicesController (); _nav = new UINavigationController (_services); window.AddSubview (_nav.View); window.MakeKeyAndVisible (); return true; }
public App() { InitializeComponent(); SplashFactory = (e) => new Views.Splash(e); #region app settings // some settings must be set in app.constructor var settings = SettingsService.Instance; RequestedTheme = settings.AppTheme; CacheMaxDuration = settings.CacheMaxDuration; ShowShellBackButton = settings.UseShellBackButton; AutoSuspendAllFrames = true; AutoRestoreAfterTerminated = true; AutoExtendExecutionSession = true; #endregion using (var EFR = new EFRepositoryContext()) { EFR.Database.Migrate(); } UWPFolder folder = new UWPFolder(); EFRepository EFRepo = new EFRepository(); HockeyClient.Current.Configure("439e0c88350044518bc86c583b8640c6"); ServCon = ServicesController.Instance; if (false == ServCon.IsConfigured) { ServCon.Configure(EFRepo, folder); } }
public async void Create_ReturnRedirect() { var size = Context.Service.Count(); var service = new Service() { ServiceID = 3, UserID = "2", ServiceCategoryID = 1, ServiceName = "Limpeza de Chaminés", Description = "Limpeza de Chaminés de Manhã" }; var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.Create(service); Assert.IsType <RedirectToActionResult>(result); //Confirmar UserServices var resultIndex = await controller.UserServices(1); var viewResultIndex = Assert.IsType <ViewResult>(resultIndex); var modelIndex = Assert.IsAssignableFrom <IEnumerable <Service> >(viewResultIndex.ViewData.Model); Assert.NotNull(modelIndex); Assert.Equal(size + 1, modelIndex.Count()); }
public void TestAdd() { //Arrange ServiceContext c = new ServiceContext(); var fakeRepo = new FakeServicesRepository(); var controller = new ServicesController(fakeRepo, c); var Service = new ServiceModel() { ServiceID = 0, ServiceName = "SomeJob", ServiceDescription = "FAKE REPO TEST", ServiceEstimated = "more for testing the repo fake", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; //Act controller.Edit(Service); // Assert Checking that story was added. var retrievedService = fakeRepo.service.ToList()[0]; Assert.NotNull(retrievedService.ServiceName); }
public void TestMethod1() { var controller = new ServicesController(); var result = controller.GetFronteraAgricola();//as OkNegotiatedContentResult<List<FronteraAgricolaDto>>; //var actionResult = controller.GetFronteraAgricola(); //var result = as IList<FronteraAgricolaDto>; //Assert.IsNotNull result.Count); }
public void CreateServiceTestView() { var controller = new ServicesController(); var result = controller.Create() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("", result.ViewName); }
public void TestHectareasAdecuadasIrrigacion() { var controller = new ServicesController(); var result = controller.GetHectareasAdecuadasIrrigacion() as OkNegotiatedContentResult <IList <APADTDto> >; IList <APADTDto> lista = result.Content; eutility.convertirAexcel(lista, "HecaterasAdecuadas", "c:\\HectareasAdecuadas.xlsx"); Assert.IsNotNull(result.Content.Count); }
public void TestFronteraAgricola() { var controller = new ServicesController(); var result = controller.GetFronteraAgricola() as OkNegotiatedContentResult <IList <FronteraAgricolaDto> >; IList <FronteraAgricolaDto> lista = result.Content; eutility.convertirAexcel(lista, "FronteraAgricola", "c:\\FronteraAgricola.xlsx"); Assert.IsNotNull(result.Content.Count); }
public void TestMethod1() { ServiceRepository repo = new ServiceRepository(); ManagementServices manage = new ManagementServices(repo); ServicesController service = new ServicesController(manage); var prueba = service.Get(); Assert.AreEqual(1, 1); }
public void Setup() { scope = new TransactionScope(); servicesController = new ServicesController() { Request = new System.Net.Http.HttpRequestMessage(), Configuration = new HttpConfiguration() }; }
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 async void Create_ReturnViewResult() { var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.Create(false); Assert.IsType <ViewResult>(result); }
public void SetUp() { _servicesRepository = new Mock <IServicesRepository>(); _unitWork = new Mock <IUnitWork>(); _servicesController = new ServicesController(_servicesRepository.Object, _unitWork.Object, ServiceProvider.GetService <IMapper>()); SetUpServicesRepository(); SetUpUnitWork(); }
public async void Edit_ReturnNotFound(int serviceID) { var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.Edit(serviceID); Assert.IsType <NotFoundResult>(result); }
/// <summary> /// Adds the services. /// </summary> internal void AddServices() { TraceService.WriteLine("Connect::AddServices Version=" + this.ApplicationVersion); ServicesController controller = new ServicesController { DTE2 = this.VSInstance.ApplicationObject }; controller.Run(); }
public ServicesControllerTest() { var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new BillingProfile()); }); mapper = mappingConfig.CreateMapper(); repository = new MockBasicBillingRepoImpl(); controller = new ServicesController(repository, mapper); }
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 TestUpdateService() { ServiceContext c = new ServiceContext(); var fakeRepo = new FakeServicesRepository(); var controller = new ServicesController(fakeRepo, c); var Service = new ServiceModel() { ServiceID = 0, ServiceName = "SomeJob", ServiceDescription = "FAKE REPO TEST", ServiceEstimated = "more for testing the repo fake", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; var Service2 = new ServiceModel() { ServiceID = 1, ServiceName = "Test2", ServiceDescription = "FAKE REPO TEST2", ServiceEstimated = "more for testing the repo fake2", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; var Service3 = new ServiceModel() { ServiceID = 1, ServiceName = "Test3", ServiceDescription = "FAKE REPO TEST3", ServiceEstimated = "more for testing the repo fake3", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; //Act controller.Edit(Service); controller.Edit(Service2); controller.Edit(Service3); //Assert // Assert Checking that story was added. ServiceModel retrievedService = fakeRepo.service.ToList()[0]; Assert.Equal("FAKE REPO TEST3", retrievedService.ServiceDescription); }
public void TestGetByIdService() { ServiceContext c = new ServiceContext(); var fakeRepo = new FakeServicesRepository(); var controller = new ServicesController(fakeRepo, c); var Service = new ServiceModel() { ServiceID = 0,// Add the item will put the count for that ServiceName = "SomeJob", ServiceDescription = "FAKE REPO TEST", ServiceEstimated = "more for testing the repo fake", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; var Service2 = new ServiceModel() { ServiceID = 0,// Add the item will put the count for that ServiceName = "Test2", ServiceDescription = "FAKE REPO TEST2", ServiceEstimated = "more for testing the repo fake2", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; var Service3 = new ServiceModel() { ServiceID = 0,// Add the item will put the count for that ServiceName = "Test3", ServiceDescription = "FAKE REPO TEST3", ServiceEstimated = "more for testing the repo fake3", ServicePrice = 80, User = new User() { UserId = "1", UserName = "******", UserLast = "Fake2" }, }; //Act controller.Edit(Service); controller.Edit(Service2); controller.Edit(Service3); //Assert // Assert Checking that story was added. ServiceModel Service4 = fakeRepo.GetServiceById(2); // that should retrieve Service3 Assert.Equal("FAKE REPO TEST3", Service4.ServiceDescription); }
public async void DeleteConfirmed_ReturnNotFound(int serviceID) { var controller = new ServicesController(Context, UserManager); controller.ControllerContext.HttpContext = new DefaultHttpContext { User = PrestadorLog }; var result = await controller.DeleteConfirmed(serviceID); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal("/Views/Shared/NotFound.cshtml", viewResult.ViewName); }
public void MyTestInitialize() { var request = new HttpRequest("", "http://example.com/", ""); var response = new HttpResponse(TextWriter.Null); HttpContext.Current = new HttpContext(request, response); var sessionStateContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false); SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, sessionStateContainer); _serviceController = new ServicesController(); var httpContext = new HttpContextWrapper(HttpContext.Current); _serviceController.ControllerContext = new ControllerContext(httpContext, new RouteData(), _serviceController); CurrentUser.SetInstance(Utility.GetUserName()); _user = CurrentUser.AsRosettianUser(); }
public void Category_Browse() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var categoryBrowseModel = new CategoryBrowseModel(); var services = GetSampleServices(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<QueryByCategory>())) .Returns(services); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Category/1/", UserName)); controller.SetUserInfo(); controller.Category(categoryBrowseModel); Assert.AreEqual(services, controller.ViewData[ViewDataKeys.Services]); }
public void Search_With_Location() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var services = GetSampleServices(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<IQuery<IEnumerable<Service>>>())) .Returns(services); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); const string location = "Bar"; var locationCood = PointFactory.Create(6.9419444, 79.8977778); geoCodingServicemMock.Setup(g => g.GetCoordinates(It.Is<string>(v => v == location))) .Returns(locationCood); var userLocation = PointFactory.Create(6.9319444, 79.8877778); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName)); controller.SetUserInfoWitLocation(userLocation); var model = new SearchModel { Terms = "Foo", Location = location }; controller.Search(model); Assert.AreEqual(model, controller.ViewData.Model); Assert.AreEqual(locationCood, controller.ViewData[ViewDataKeys.UserLocation]); }
public void Create_Get() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Services/Create/", UserName)); controller.Create(); var actualCategories = (IList<GroupedSelectListItem>)controller.ViewData[ViewDataKeys.Categories]; Assert.AreEqual(3, actualCategories.Count); }
public void Create_Post_valid() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var createServiceModel = new CreateServiceModel(); var categories = GetSampleCategories(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>())) .Returns(categories); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName)); controller.SetUserInfo(); controller.Create(createServiceModel); nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny<ICommand>())); }
public void ServicesNearLocation() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); var services = GetSampleServices(); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Service>>>())) .Returns(services); var fileSystemMock = new Mock<IFileSystem>(); var geoCodingServicemMock = new Mock<IGeoCodingService>(); var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/ServicesNearLocation", UserName)); controller.SetUserInfo(); var jsonResult = controller.ServicesNearLocation(1.337, 3.37); dynamic json = jsonResult.Data; Assert.AreEqual(2, json.Count); }
public void Details_Of_Existing_Service() { var service = GetSampleServices()[0]; var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, Service>>())) .Returns(service); var controller = new ServicesController(nHbernateContextMock.Object, null, null); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/1", UserName)); controller.SetUserInfo(); var result = controller.Details(1); Assert.AreEqual(service, controller.ViewData.Model); }
public void Details_Of_Nonexisting_Service() { var sessionMock = new Mock<ISession>(); var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName); nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, Service>>())) .Returns((Service)null); var controller = new ServicesController(nHbernateContextMock.Object, null, null); controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/10", UserName)); controller.SetUserInfo(); var result = controller.Details(10); var view = result as ViewResult; Assert.AreEqual("ServiceNotFound", view.ViewName); }
public void MyTestInitialize() { // Helper code to get the HttpContext var mySIMPLTestContext = new SIMPLTestContext(); HttpContext.Current = mySIMPLTestContext.GetHttpSession(); // Helper Code to get the user logged into Windows var userName = mySIMPLTestContext.GetNameFromWindowsIdentity(); // Calling actual production code to set the instance for this username CurrentUser.SetInstance(userName); CurrentUser.SetInstance(userName); RosettianUser = CurrentUser.AsUserDto(); // Calling actual production code to get the Rosettian User Object HttpContext.Current = mySIMPLTestContext.GetHttpSession(); // Calling actual production code to set the instance for this username CurrentUser.SetInstance(userName); CurrentUser.SetInstance(userName); RosettianUser = CurrentUser.AsUserDto(); ServicesControllerForTests = DependencyResolver.Current.GetService<ServicesController>(); // Set up the CVoipPhoneControllerForTests ServicesControllerForTests.ControllerContext = new ControllerContext(new HttpContextWrapper(HttpContext.Current), new RouteData(), ServicesControllerForTests); }