Example #1
0
        public void ReturnJsonArrayWithTheEditedCountry_WhenPassedModelParamIsNotNull()
        {
            // arrange
            var countryService   = new Mock <ICountryService>();
            var countryViewModel = new GridCountryViewModel()
            {
                Name = "someName"
            };

            var mapService = new Mock <IMappingService>();

            var countryDataModel = new Country()
            {
                Name = "someName"
            };

            mapService.Setup(c => c.Map <Country>(It.IsAny <Object>()))
            .Returns(countryDataModel);

            MappingService.MappingProvider = mapService.Object;
            var controller = new CountriesGridController(countryService.Object);

            // act
            controller.EditCountry(countryViewModel);

            // assert
            controller.WithCallTo(c => c.EditCountry(countryViewModel))
            .ShouldReturnJson((data) => Assert.AreSame(data[0], countryViewModel));
        }
Example #2
0
        public void CallCountryServiceUpdateMethodWithCOrrectMappedCountryDateModel_WhenPassedModelParamIsNotNull()
        {
            // arrange
            var countryService   = new Mock <ICountryService>();
            var countryViewModel = new GridCountryViewModel()
            {
                Name = "someName"
            };

            var mapService = new Mock <IMappingService>();

            var countryDataModel = new Country()
            {
                Name = "someName"
            };

            mapService.Setup(c => c.Map <Country>(It.IsAny <Object>()))
            .Returns(countryDataModel);

            MappingService.MappingProvider = mapService.Object;
            var controller = new CountriesGridController(countryService.Object);

            // act
            controller.EditCountry(countryViewModel);

            // assert
            countryService.Verify(c => c.Update(countryDataModel), Times.Once);
        }
        public ActionResult DeleteCountry(GridCountryViewModel model)
        {
            if (model != null)
            {
                this.countryService.Delete(model.Name);
            }

            return(this.Json(new[] { model }));
        }
        public ActionResult EditCountry(GridCountryViewModel countryModel)
        {
            if (countryModel != null)
            {
                var countryDataModel = MappingService.MappingProvider.Map <Country>(countryModel);
                this.countryService.Update(countryDataModel);
            }

            return(this.Json(new[] { countryModel }));
        }
        public void CallCountryServiceDeleteMethodWithCorrectCountryName_WhenPassedModelIsNotNull()
        {
            // arrange
            var countryService = new Mock <ICountryService>();
            var controller     = new CountriesGridController(countryService.Object);

            var countryViewModel = new GridCountryViewModel()
            {
                Name = "someName"
            };

            // act
            controller.DeleteCountry(countryViewModel);

            // assert
            countryService.Verify(c => c.Delete("someName"), Times.Once);
        }
        public void ReturnJsonAsResult_WhenInvoked()
        {
            // arrange
            var countryService = new Mock <ICountryService>();
            var controller     = new CountriesGridController(countryService.Object);

            var countryViewModel = new GridCountryViewModel()
            {
                Name = "someName"
            };

            // act
            controller.DeleteCountry(countryViewModel);

            // assert
            controller.WithCallTo(c => c.DeleteCountry(countryViewModel))
            .ShouldReturnJson(data =>
            {
                Assert.That(data[0].Name, Is.EqualTo("someName"));
            });
        }