public void Create_SaveWithEmptyOrInvalidCountryName_ReturnsValidationMessage(string countryName)
        {
            var country = new Country
            {
                Name = countryName
            };

            _countryController.ModelState.AddModelError("Error", @"Something went wrong");

            var result = (ViewResult)_countryController.Create(country);

            _countryManagerMock.Verify(m => m.Create(country), Times.Never);
            Assert.AreEqual("", result.ViewName);
        }
        public void Valid_Country_Create()
        {
            //Arrange
            Country c = new Country()
            {
                Name = "test1"
            };

            //Act
            var result = (RedirectToRouteResult)objController.Create(c);

            //Assert
            _countryServiceMock.Verify(m => m.Create(c), Times.Once);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void Valid_Country_Create()
        {
            //Arrange
            Country c = new Country()
            {
                Name = "test1"
            };

            //Act
            var result = (RedirectToActionResult)_controller.Create(c);

            //Assert
            _countryServiceMock.Verify(m => m.Create(c), Times.Once);
            Assert.AreEqual("Index", result.ActionName);
            Assert.AreEqual("Country", result.ControllerName);
        }
        public void Create_NullObject_ShouldReturnBadRequest()
        {
            mock.Setup(repo => repo.GetAllItems(null)).Returns(listItems.AsQueryable());
            mock.Setup(repo => repo.Create(null));
            var controller = new CountryController(mockChild.Object, mock.Object);

            var result = controller.Create(null);

            Assert.IsType <BadRequestResult>(result.Result);
        }
        public void ControllerCreate()
        {
            // Arrange
            CountryController controller = new CountryController();
            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Esempio n. 6
0
        public void CreateGetView_True()
        {
            // Arrange - create the controller
            CountryController target = new CountryController(mock.Object);

            // Act - call the action method
            var result = target.Create() as ViewResult;

            // Assert - check the result
            Assert.AreEqual("", result.ViewName);
        }
        public void CreateTestReturn200()
        {
            FormModel formModel = new()
            {
                Name = "Test3"
            };

            var result = countryController.Create(formModel);

            Assert.IsInstanceOf <OkObjectResult>(result.Result);
        }
Esempio n. 8
0
        public void Create_ReturnsCorrectActionType_RedirectToActionResult()
        {
            //Arrange
            CountryController controller = new CountryController();

            //Act
            IActionResult view = controller.Create();

            //Assert
            Assert.IsInstanceOfType(view, typeof(RedirectToActionResult));
        }
Esempio n. 9
0
        public void CreatePost_CannotCreate_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");
            ViewResult result = target.Create(Country) as ViewResult;

            // Assert - check the result
            mock.Verify(m => m.SaveCountry(It.IsAny <Country>()), Times.Never);
            Assert.IsInstanceOf(typeof(Country), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }
        public void Create_ValidObject_ShouldReturnValidObjectAndCreatedAtObjectResult()
        {
            var country3 = new Country {
                Id = 3, Name = "ua", Code = "333", Businesses = null
            };

            mock.Setup(repo => repo.GetAllItems(null)).Returns(listItems.AsQueryable());
            mock.Setup(repo => repo.Create(country3));
            var controller = new CountryController(mockChild.Object, mock.Object);

            var result = controller.Create(country3);

            Assert.IsAssignableFrom <ActionResult <Country> >(result);
            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
Esempio n. 11
0
        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
            ViewResult result = (ViewResult)target.Create(Country);

            // Assert - check the result
            mock.Verify(m => m.SaveCountry(Country), Times.Once);
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.AreEqual("Index", result.ViewName);
        }
Esempio n. 12
0
        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"]);
        }
Esempio n. 13
0
        public async void Create_Errors()
        {
            CountryControllerMockFacade mock = new CountryControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiCountryResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiCountryResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCountryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCountryResponseModel> >(mockResponse.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.Create(new ApiCountryRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCountryRequestModel>()));
        }
Esempio n. 14
0
        public async void Create_No_Errors()
        {
            CountryControllerMockFacade mock = new CountryControllerMockFacade();

            var mockResponse = new CreateResponse <ApiCountryResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiCountryResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCountryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCountryResponseModel> >(mockResponse));
            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.Create(new ApiCountryRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiCountryResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCountryRequestModel>()));
        }
Esempio n. 15
0
 public void CreateShouldBuildNewInput()
 {
     c.Create();
     A.CallTo(() => v.MapToInput(A <Country> .Ignored)).MustHaveHappened();
 }
 public void CreateShouldBuildNewInput()
 {
     c.Create();
     A.CallTo(() => mapper.Map <Country, CountryInput>(A <Country> .Ignored, null)).MustHaveHappened();
 }