public void ThrowArgumentNullException_WhenModelParameterIsNull()
        {
            // Arrange
            var advertService = new Mock <IAdvertService>();

            // Act
            var ajaxAdvertController = new CarAdverts.Web.Areas.Administrator.Controllers.AjaxAdvertController(advertService.Object);

            // Arrange
            Assert.Throws <ArgumentNullException>(() => ajaxAdvertController.Add(null));
        }
        public void InvokeAdvertServiceMethod_CreateAdvert_Once_WhennModelStateIsValid()
        {
            // Arrange
            // This code mock User.Identity.GetUserId()
            var context  = new Mock <HttpContextBase>();
            var identity = new GenericIdentity("*****@*****.**");

            identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "1"));
            var principal = new GenericPrincipal(identity, new[] { "user" });

            context.Setup(s => s.User).Returns(principal);
            //

            var advertViewModel = new AdvertViewModel()
            {
                Title            = "advert",
                VehicleModelId   = 1,
                UserId           = "user id",
                Year             = 100,
                Price            = 100m,
                Power            = 100,
                DistanceCoverage = 100,
                CityId           = 1,
                Description      = "ani description",
                CreatedOn        = DateTime.Now
            };

            var advertService        = new Mock <IAdvertService>();
            var ajaxAdvertController = new CarAdverts.Web.Areas.Administrator.Controllers.AjaxAdvertController(advertService.Object);

            ajaxAdvertController.ControllerContext = new ControllerContext(context.Object, new RouteData(), ajaxAdvertController);

            // Act
            ajaxAdvertController.Add(advertViewModel);

            // Arrange
            advertService.Verify(a => a.CreateAdvert(It.IsAny <Advert>(), It.IsAny <IEnumerable <HttpPostedFileBase> >()), Times.Once);
        }