protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); _controller = new CountryController(this.listItems); this.DataContext = _controller; }
public void SetUp() { // you have to be an administrator to access the user controller Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new string[] { "Administrator" }); countryRepository = MockRepository.GenerateStub<IRepository<Country>>(); countryController = new CountryController {Repository = countryRepository}; }
public async Task Invalid_Id_Returns_Null() { var id = Guid.NewGuid(); var country = Country.Create(id, "country"); var mockCountryService = new Mock <ICountryService>(); mockCountryService.Setup(s => s.GetCountryAsync(Guid.NewGuid())) .Returns(() => Task.FromResult(country)); var countryController = new CountryController(mockCountryService.Object); var result = await countryController.GetCountry(id); Assert.Null(result); }
public void SetupForBuying(Side side, bool isDisclosing) { if (highlightedHexes.Count != 0) { DesetupForBuying(false); } if (isDisclosing) { CountryController.SelectedEmptyDisclosedHexes(side, ref highlightedHexes); } else { CountryController.SelectedEmptyHexes(side, ref highlightedHexes); } HighLightHexes(highlightedHexes, true); }
public void GetAllReturnsNonCountries() { var mock = new Mock <ICountryRepository>(); mock.Setup(s => s.GetAll()).Returns(Enumerable.Empty <CountryDto>); var controller = new CountryController(mock.Object, Mapper); var result = controller.GetAll(); Assert.NotNull(result); Assert.IsType <OkObjectResult>(result); var collection = (IEnumerable <Country>)((OkObjectResult)result).Value; Assert.Empty(collection); }
public void DeletePost_CanDelete_ValidCountry() { // Arrange - create the controller CountryController target = new CountryController(mock.Object); // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(1); // Assert - check the result mock.Verify(m => m.DeleteCountry(1), Times.Once); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("ABMView", result.RouteValues["action"]); Assert.IsNull(result.RouteValues["tab"]); Assert.IsFalse(result.Permanent); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); }
public void IndexTest1() { // Arrange var mock = new Mock<ControllerContext>(); mock.SetupGet(x => x.HttpContext.User.Identity.Name).Returns(user); mock.SetupGet(x => x.HttpContext.Request.IsAuthenticated).Returns(true); CountryController controller = new CountryController(); controller.ControllerContext = mock.Object; // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public async Task Add_Returns_ViewResult() { // arrange var countryService = new Mock <ICountryService>(MockBehavior.Strict); var controller = new CountryController(countryService.Object) { TempData = new Mock <ITempDataDictionary>().Object }; // act var result = controller.Add(); // assert Assert.IsAssignableFrom <ViewResult>(result); countryService.VerifyAll(); }
public async void Get_Not_Exists() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCountryServerResponseModel>(null)); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public void Setup() { _countryDetails = SetUpCountryDetails(); //_schoolRepository = SetCountryRepository(); //we can't set property to mock object directly. To achive that implemented below code var unitOfData = new Mock <IUnitOfWork>(); //unitOfData.SetupGet(u => u.Repository).Returns(_countryRepository); //_unitOfWork = unitOfData.Object; //_unitOfWork.Repository = _countryRepository; _countryService = new CountryService(_unitOfWork); _countryController = new CountryController(_countryService, CountryAutoMapper.Mapper()); }
public void DeleteCountryTest() { //Arrange var mockrep = new Mock <ICountry>(); mockrep.Setup(c => c.Delete(It.IsAny <string>())).Returns(true); CountryController countryCntlrobject = new CountryController(mockrep.Object); //Act var resultActual = countryCntlrobject.Delete("USA"); //Assert var expected = true; Assert.AreEqual(resultActual, expected); }
public void CreatePost_CanCreate_ValidCountry() { // Arrange - create the controller CountryController target = new CountryController(mock.Object); Country Country = new Country { CountryID = 1, CountryName = "Netherlands", Comment = "Test Comment" }; // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.Create(Country); // Assert - check the result mock.Verify(m => m.SaveCountry(Country), Times.Once); Assert.IsFalse(result.Permanent); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("ABMView", result.RouteValues["action"]); }
public void Initialize() { _countryManagerMock = new Mock <ICountryService>(); _countryController = new CountryController(_countryManagerMock.Object); _countryList = new List <Country> { new Country { Id = 1, Name = "US" }, new Country { Id = 2, Name = "India" }, new Country { Id = 3, Name = "Russia" } }; }
public static async Task UpdateCountryName(CountryId id, string name) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new CountryRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new CountryService(repository, unitOfWork); var countryController = new CountryController(service); var updateCommand = new Commands.SetCountryName { Id = id, Name = name }; await countryController.Put(updateCommand); }
public void EditPost_CanEdit_ValidCountry() { // Arrange - create the controller CountryController target = new CountryController(mock.Object); Country Country = new Country { CountryID = 1, CountryName = "Netherlands", Comment = "Test Comment" }; // Act - call the action method var result = (ViewResult)target.Edit(Country); // Assert - check the result Assert.IsInstanceOf(typeof(ViewResult), result); Assert.AreEqual("Index", result.ViewName); mock.Verify(m => m.SaveCountry(Country), Times.Once); }
public void EditPost_CannotEdit_InvalidCountry() { // Arrange - create the controller Country Country = new Country { }; CountryController target = new CountryController(mock.Object); // Act - call the action method target.ModelState.AddModelError("error", "error"); var result = target.Edit(Country); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target; // Assert - check the result mock.Verify(m => m.SaveCountry(Country), Times.Never); Assert.IsInstanceOf(typeof(JsonResult), result); Assert.AreEqual("", data); //Assert.IsInstanceOf(typeof(Country), result.ViewData.Model); }
public async void Delete_Errors() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); var mockResult = new Mock <ActionResponse>(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object)); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Delete(default(int)); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>())); }
private void btnEdit_Click(object sender, EventArgs e) { if (spIdCountry.Value > 0) { Country country = new Country(); RellenarPais(ref country); CountryController contCont = new CountryController(); if (contCont.AddOrUpdateCountry(country)) { FrmSuccess.ConfirmacionFrom("Editado"); limpiar(); } else { MessageBox.Show("ocurrio un error al guardar."); } } }
public void DeletePost_CannotDelete_ValidCountry() { // Arrange - create the controller CountryController target = new CountryController(mock.Object); mock.Setup(x => x.DeleteCountry(It.IsAny <int>())) .Callback(() => { throw new System.Data.Entity.Infrastructure.DbUpdateException(); }); // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(2); // Assert - check the result mock.Verify(m => m.DeleteCountry(2), Times.Once); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]); }
public static async Task <dynamic> CreateInvalidCountry() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new CountryRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new CountryService(repository, unitOfWork); var command = new Commands.Create { Id = null }; // Create Store var countryController = new CountryController(service); return(await countryController.Post(command)); }
public CountryControllerTests() { var countries = new[] { new CountryModel { Name = "Test" } }; var mockedService = new Mock <ICountryService>(); mockedService .Setup(service => service.GetCountries(It.IsAny <CancellationToken>())) .ReturnsAsync(() => countries); _controller = new CountryController(mockedService.Object); }
private void fillDdl() { ddlPais.DataSource = CountryController.GetAllConuntry(); ddlPais.DataTextField = "Name"; ddlPais.DataValueField = "CountryKey"; ddlPais.DataBind(); ddlPais.SelectedValue = "3177E8C2-FBAA-424B-A60F-0BAF24C34F18"; ddlEstado.DataSource = StateController.GetAllStates(ddlPais.SelectedValue); ddlEstado.DataTextField = "Name"; ddlEstado.DataValueField = "StateKey"; ddlEstado.DataBind(); ddlFuente.DataSource = SourceClientController.GetAllSourceClient(); ddlFuente.DataTextField = "Name"; ddlFuente.DataValueField = "SourceClientKey"; ddlFuente.DataBind(); ddlFuente.Items.Insert(0, new ListItem("-Ninguno-", Guid.Empty.ToString())); ddlInteres.DataSource = InterestController.GetAllInterest(); ddlInteres.DataTextField = "Name"; ddlInteres.DataValueField = "InterestTypeKey"; ddlInteres.DataBind(); ddlInteres.Items.Insert(0, new ListItem("-Ninguno-", Guid.Empty.ToString())); ClearDdlInterest(); ddlTypeContact.DataSource = ContactTypeController.GetAllTypeContact(); ddlTypeContact.DataTextField = "Name"; ddlTypeContact.DataValueField = "ContactTypeKey"; ddlTypeContact.DataBind(); ddlTypeContact.Items.Insert(0, new ListItem("-Ninguno-", Guid.Empty.ToString())); ddlStatusCliente.DataSource = StatusClienteController.GetAll(); ddlStatusCliente.DataTextField = "Name"; ddlStatusCliente.DataValueField = "StatusClienteKey"; ddlStatusCliente.DataBind(); ddlStatusCliente.Items.Insert(0, new ListItem("-Ninguno-", Guid.Empty.ToString())); }
public void Pagination_Properly_Working_Countries() { // Arrange - create the mock repository Mock <IItemRepository> mock = new Mock <IItemRepository>(); mock.Setup(m => m.Countries).Returns(new Country[] { new Country { CountryID = 1, Name = "P1" }, new Country { CountryID = 2, Name = "P2" }, new Country { CountryID = 3, Name = "P3" }, new Country { CountryID = 4, Name = "PX" }, new Country { CountryID = 5, Name = "P4" }, new Country { CountryID = 6, Name = "P5" }, }.AsQueryable <Country>()); // Arrange - create a controller CountryController target = new CountryController(mock.Object); // Action CountryListViewModel result = target.List(1).ViewData.Model as CountryListViewModel; //Request a List for the first page CountryListViewModel result2 = target.List(2).ViewData.Model as CountryListViewModel; //Request a List for the second page // Assert Assert.Equal(4, result.Countries.Count()); Assert.Equal("P1", result.Countries[0].Name); Assert.Equal("P2", result.Countries[1].Name); Assert.Equal("P3", result.Countries[2].Name); Assert.Equal("PX", result.Countries[3].Name); Assert.Equal(2, result2.Countries.Count()); Assert.Equal("P4", result2.Countries[0].Name); Assert.Equal("P5", result2.Countries[1].Name); }
public void Controller_Get_All_Countries() { var serviceMock = new Mock <ICountriesService>(); serviceMock.Setup(x => x.GetAllCountries()).Returns(() => new List <Country> { new Country { Id = 0, Name = "Argentina" }, new Country { Id = 1, Name = "Peru" } }); var controller = new CountryController(serviceMock.Object); var result = controller.Get(); Assert.Equal(2, ((List <Country>)result).Count); }
public async void Get_Exists() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiCountryResponseModel())); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Get(default(int)); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var record = (response as OkObjectResult).Value as ApiCountryResponseModel; record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void All_Not_Exists() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiCountryResponseModel> >(new List <ApiCountryResponseModel>())); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCountryResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public async void Update_NotFound() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); var mockResult = new Mock <UpdateResponse <ApiCountryResponseModel> >(); mockResult.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiCountryRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiCountryResponseModel> >(mockResult.Object)); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCountryResponseModel>(null)); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiCountryModelMapper()); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Update(default(int), new ApiCountryRequestModel()); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public static async Task <Country> CreateValidCountry() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new CountryRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new CountryService(repository, unitOfWork); var command = new Commands.Create { Name = "Rapture", Id = null }; var countryController = new CountryController(service); var country = await countryController.Post(command); return(await repository.GetAsync(country.Value.Id)); }
public void DeleteFailureCountryInTheRepo() { var mock = new Mock <ICountryRepository>(MockBehavior.Strict); // Creating the rules for mock, always send true in this case mock.As <ICRUDRepository <Country, int, CountryFilter> >().Setup(m => m.Remove(It.IsAny <int>())) .Returns(Task.FromResult(false)); // Creating the controller which we want to create CountryController controller = new CountryController(mock.Object); // configuring the context for the controler fakeContext(controller); HttpResponseMessage response = controller.Delete(0).Result; // the result should say "HttpStatusCode.NotFound" Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound); }
public async Task Get_All_Countries() { List <CountryDto> mockCountries = MockCountries(); var mockRepository = new Mock <IRepository <Country, CountryDto, CountryId> >(); mockRepository.Setup(repo => repo.GetAllDtoAsync()) .Returns(() => Task.FromResult(mockCountries.AsEnumerable())); var mockUnitOfWork = new Mock <IUnitOfWork>(); var countryService = new CountryService(mockRepository.Object, mockUnitOfWork.Object); var countryController = new CountryController(countryService); var result = await countryController.GetCountries(); Assert.Equal(10, result.Count()); mockRepository.Verify(mock => mock.GetAllDtoAsync(), Times.Once()); }
public void EditPost_ValidModelConcurrency_ErrorReturned() { //Arrange CountryController controller = new CountryController(mock.Object); mock.Setup(m => m.SaveCountry(It.IsAny <Country>())).Throws(new DbUpdateConcurrencyException()); string modelError = "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled."; //Act JsonResult result = (JsonResult)controller.Edit(mock.Object.Countries.FirstOrDefault()); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(result.Data, "error")).Target; //Assert mock.Verify(d => d.SaveCountry(It.IsAny <Country>()), Times.Once()); Assert.AreEqual(typeof(JsonResult), result.GetType()); Assert.AreEqual(modelError, data); }
public void AddCountryTest() { //Arrange var mockrep = new Mock <ICountry>(); mockrep.Setup(c => c.Add(It.IsAny <Country>())).Returns(true); CountryController countryCntlrobject = new CountryController(mockrep.Object); Country cntobj = new Country() { Id = "USA", Description = "United States Of America" }; //Act var resultActual = countryCntlrobject.Add(cntobj); //Assert var expected = true; Assert.AreEqual(resultActual, expected); }
public void GenerateCountryList() { const int interlineado = 100; int count = 1; for (int i = 0; i < countries.Count; i++) { CountryController cc = countries[i]; GameObject go = Instantiate(listObject, countryList); go.GetComponent <RectTransform>().localPosition -= count * new Vector3(0, interlineado, 0); Text text = go.GetComponentInChildren <Text>(); go.GetComponent <Button>().onClick.AddListener(delegate { SelectedFromMenu(cc); }); botones.Add(go.GetComponent <Button>()); text.text = cc.country.name; count++; } sim.firstSelectedGameObject = botones[0].gameObject; for (int i = 0; i < botones.Count; i++) { Navigation customNav = new Navigation(); customNav.mode = Navigation.Mode.Vertical; if (i > 0) { customNav.selectOnUp = botones[i - 1]; } if (i < botones.Count - 1) { customNav.selectOnDown = botones[i + 1]; } botones[i].navigation = customNav; } }
public void IndexTest2() { // Arrange var mock = new Mock<ControllerContext>(); mock.SetupGet(x => x.HttpContext.User.Identity.Name).Returns(user); mock.SetupGet(x => x.HttpContext.Request.IsAuthenticated).Returns(true); CountryController controller = new CountryController(); controller.ControllerContext = mock.Object; // Act ViewResult result = controller.Index() as ViewResult; // Assert ESecurity actual =result.ViewData["Security"] as ESecurity; ESecurity mustBe =new ESecurity { Add = 1, Edit = 1, Delete = 0, Print = 1 }; Assert.IsNotNull(actual, "Controller Permission is not set yet"); //Assert.AreEqual(actual.Add,mustBe.Add, "Add is not correct"); //Assert.AreEqual(actual.Edit, mustBe.Edit, "Edit is not correct"); //Assert.AreEqual(actual.Delete, mustBe.Delete, "Delete is not correct"); //Assert.AreEqual(actual.Print, mustBe.Print, "print is not correct"); }
public CountryControllerTests() { _countryService = A.Fake<ICountryService>(); _countryController = new CountryController(_countryService); }
public static CountryController Fixture() { CountryController controller = new CountryController(new CountryRepository(), "", new LoginView()); return controller; }
public void SetUp() { Fake.InitializeFixture(this); c = new CountryController(s, v); }