public ActionResult Create(Observation observation) { if (ModelState.IsValid) { _repository.Insert(observation); _repository.Save(); } return RedirectToAction("Details", new { id = observation.Id }); }
public ActionResult Edit(Observation observation) { if (ModelState.IsValid) { _repository.Update(observation); _repository.Save(); } return View(observation); }
public void ObservationMapTest() { // Arrange var mockCommentMapper = new Mock<IMapper<Comment>>().Object; var mockIdentificationMapper = new Mock<IMapper<Identification>>().Object; var mockPhotoMapper = new Mock<IMapper<Photo>>().Object; var mockTaxonMapper = new Mock<IMapper<Taxon>>().Object; var mockUserMapper = new Mock<IMapper<User>>().Object; var observationMapper = new ObservationMapper(mockCommentMapper, mockIdentificationMapper, mockPhotoMapper, mockTaxonMapper, mockUserMapper); dynamic obj = new JObject(); obj.id = "101"; obj.created_at = "2016-11-20T14:28:53.572+11:00"; obj.observed_on = "2012-11-20T14:28:53.572+11:00"; obj.description = "Pretty!"; obj.latitude = "75"; obj.longitude = "150"; obj.community_taxon_id = "102"; obj.observation_sounds_count = "10"; obj.quality_grade = "research"; var observation = new Observation(); // Act observationMapper.Map(obj, observation); // Assert Assert.AreEqual(observation.Id, 101); Assert.AreEqual(observation.CreatedAt, Convert.ToDateTime("2016-11-20T14:28:53.572+11:00")); Assert.AreEqual(observation.ObservedOn, Convert.ToDateTime("2012-11-20T14:28:53.572+11:00")); Assert.AreEqual(observation.Description, "Pretty!"); Assert.AreEqual(observation.Location.Latitude, 75); Assert.AreEqual(observation.Location.Longitude, 150); Assert.AreEqual(observation.CommunityTaxonId, 102); Assert.AreEqual(observation.SoundsCount, 10); Assert.AreEqual(observation.QualityGrade, "research"); Assert.AreEqual(observation.Taxon, null); Assert.AreEqual(observation.User, null); Assert.AreEqual(observation.Photos.Count, 0); Assert.AreEqual(observation.Feedback.Count, 0); }