public void TestCreate() { Mock <IAreaDao> areaDaoMock = new Mock <IAreaDao>(); areaDaoMock.Setup(x => x.Create(It.IsAny <Country>(), It.IsAny <Area>())); string countryName = "D"; string areaName = "Gebiet 1"; Country fakeCountry = new Country() { Name = countryName }; IAreaService areaService = new AreaService(areaDaoMock.Object); areaService.Create(fakeCountry, areaName); areaDaoMock.Verify(x => x.Create(It.Is <Country>(y => y.Name == countryName), It.Is <Area>(y => y.Name == areaName)), Times.Once); }
public void Create_Correct_Area() { //Arrange var areaDTO = new AreaDTO { LayoutId = 0, Description = "area1", CoordX = 1, CoordY = 1 }; //Act service.Create(areaDTO); var res = service.GetById(1); //Assert Assert.AreEqual(res.Description, "area1"); }
public ActionResult Create(AreaViewModel item) { var exists = _areaService.Get(properties: new[] { "Id", "AreaName" }).Select(p => new SelectListItem { Text = p.AreaName, Value = p.Id.ToString(), }).ToList(); ViewData["Areas"] = exists; if (item.AreaContract.IsValid()) { var rs = _areaService.Create(item.AreaContract); if (rs != ResultStatus.Success) { ModelState.AddModelError("", rs == ResultStatus.Duplicate ? "记录已经存在" : "添加失败"); return(View(new AreaViewModel(item.AreaContract))); } return(RedirectToAction("Index")); } ModelState.AddModelError("", item.AreaContract.ErrorMessage); return(View(new AreaViewModel(item.AreaContract))); }
public ResultView Create([FromBody] AreaView view) { return(_Service.Create(view, LogonInfo)); }