Пример #1
0
 public ActionResult Create(Macroregion model)
 {
     //throw new NotImplementedException();
     //Repository.Add(model);
     //Repository.Save();
     //TempData["message"] = "Дані регіону збережено";
     //return RedirectToAction("Index");
     return(EditingOperation(model, Repository.Add));
 }
        public void CreatePost_TempData_KeysContains_message_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            ActionResult result = controller.Create(model);

            Assert.IsTrue(controller.TempData.Keys.Contains("message"));
        }
        public void CreatePost_Repository_SaveIsCalled_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            ActionResult result = controller.Create(model);

            mock.Verify(e => e.Save());
        }
        public void CreatePost_Result_RedirectToActionIndex_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            ActionResult result = controller.Create(model);

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            var redirectResult = result as RedirectToRouteResult;

            Assert.AreEqual(redirectResult.RouteValues["action"], "Index");
        }
        public void CreatePost_AddingError_ModelStateIsNotValid_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            mock.Setup(m => m.Add(It.IsAny <Macroregion>())).Throws <Exception>();
            Assert.IsFalse(controller.ModelState.Count > 0);

            ActionResult result = controller.Create(model);

            Assert.IsTrue(controller.ModelState.Count > 0);
            Assert.IsTrue(controller.ModelState.Keys.ElementAt(0) == "");
        }
        public void CreatePost_AddingError_ReturnedViewResult_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            mock.Setup(m => m.Add(It.IsAny <Macroregion>())).Throws <Exception>();

            ActionResult result = controller.Create(model);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = result as ViewResult;

            Assert.AreEqual(viewResult.Model, model);
        }
        public void CreatePost_ModelStateIsNotValid_ReturnedViewResult_moq()
        {
            var mock       = new Mock <IRepository <Macroregion> >();
            var controller = new MacroregionsCrudController()
            {
                Repository = mock.Object
            };
            Macroregion model = new Macroregion();

            controller.ModelState.AddModelError("", "error message");

            ActionResult result = controller.Create(model);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = result as ViewResult;

            Assert.AreEqual(viewResult.Model, model);
        }
Пример #8
0
 private ActionResult EditingOperation(Macroregion model, Action <Macroregion> action)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     //Repository.Add(model);
     //action(model);
     //Repository.Save();
     try {
         action(model);
         Repository.Save();
     }
     //catch (Exception)
     catch (Exception ex) {
         ModelState.AddModelError("", ex.Message);
         return(View(model));
     }
     //TempData["message"] = "Дані регіону збережено";
     TempData["message"] = string.Format(
         "Дані регіону \"{0}\" збережено", model.Name);
     return(RedirectToAction("Index"));
 }
Пример #9
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (Name != null)
                {
                    hashCode = hashCode * 59 + Name.GetHashCode();
                }
                if (Label != null)
                {
                    hashCode = hashCode * 59 + Label.GetHashCode();
                }

                hashCode = hashCode * 59 + Score.GetHashCode();
                if (HouseNumber != null)
                {
                    hashCode = hashCode * 59 + HouseNumber.GetHashCode();
                }
                if (Street != null)
                {
                    hashCode = hashCode * 59 + Street.GetHashCode();
                }
                if (Region != null)
                {
                    hashCode = hashCode * 59 + Region.GetHashCode();
                }
                if (RegionCode != null)
                {
                    hashCode = hashCode * 59 + RegionCode.GetHashCode();
                }
                if (Neighbourhood != null)
                {
                    hashCode = hashCode * 59 + Neighbourhood.GetHashCode();
                }
                if (County != null)
                {
                    hashCode = hashCode * 59 + County.GetHashCode();
                }
                if (Macroregion != null)
                {
                    hashCode = hashCode * 59 + Macroregion.GetHashCode();
                }
                if (City != null)
                {
                    hashCode = hashCode * 59 + City.GetHashCode();
                }
                if (Country != null)
                {
                    hashCode = hashCode * 59 + Country.GetHashCode();
                }
                if (CountryCode != null)
                {
                    hashCode = hashCode * 59 + CountryCode.GetHashCode();
                }
                if (Continent != null)
                {
                    hashCode = hashCode * 59 + Continent.GetHashCode();
                }
                if (Postcode != null)
                {
                    hashCode = hashCode * 59 + Postcode.GetHashCode();
                }
                if (Features != null)
                {
                    hashCode = hashCode * 59 + Features.GetHashCode();
                }
                return(hashCode);
            }
        }
Пример #10
0
        /// <summary>
        /// Returns true if ResponseGeocodingProperties instances are equal
        /// </summary>
        /// <param name="other">Instance of ResponseGeocodingProperties to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ResponseGeocodingProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                     ) &&
                 (
                     Label == other.Label ||
                     Label != null &&
                     Label.Equals(other.Label)
                 ) &&
                 (
                     Score == other.Score ||

                     Score.Equals(other.Score)
                 ) &&
                 (
                     HouseNumber == other.HouseNumber ||
                     HouseNumber != null &&
                     HouseNumber.Equals(other.HouseNumber)
                 ) &&
                 (
                     Street == other.Street ||
                     Street != null &&
                     Street.Equals(other.Street)
                 ) &&
                 (
                     Region == other.Region ||
                     Region != null &&
                     Region.Equals(other.Region)
                 ) &&
                 (
                     RegionCode == other.RegionCode ||
                     RegionCode != null &&
                     RegionCode.Equals(other.RegionCode)
                 ) &&
                 (
                     Neighbourhood == other.Neighbourhood ||
                     Neighbourhood != null &&
                     Neighbourhood.Equals(other.Neighbourhood)
                 ) &&
                 (
                     County == other.County ||
                     County != null &&
                     County.Equals(other.County)
                 ) &&
                 (
                     Macroregion == other.Macroregion ||
                     Macroregion != null &&
                     Macroregion.Equals(other.Macroregion)
                 ) &&
                 (
                     City == other.City ||
                     City != null &&
                     City.Equals(other.City)
                 ) &&
                 (
                     Country == other.Country ||
                     Country != null &&
                     Country.Equals(other.Country)
                 ) &&
                 (
                     CountryCode == other.CountryCode ||
                     CountryCode != null &&
                     CountryCode.Equals(other.CountryCode)
                 ) &&
                 (
                     Continent == other.Continent ||
                     Continent != null &&
                     Continent.Equals(other.Continent)
                 ) &&
                 (
                     Postcode == other.Postcode ||
                     Postcode != null &&
                     Postcode.Equals(other.Postcode)
                 ) &&
                 (
                     Features == other.Features ||
                     Features != null &&
                     Features.Equals(other.Features)
                 ));
        }