public void OnPostNewTest() { var geoPoint = new GeoPoint { Lat = 0, Lon = 0 }; const string name = "Name"; var newLocationRequest = new AdventureLocation(geoPoint, name); var newLocationResponse = new AdventureLocation(geoPoint, name) { Id = "newId" }; var expectedNewResponse = new AdventureLocationSaveResponse(newLocationRequest) { AdventureLocation = newLocationResponse }; var mock = new Mock<IAdventureLocationRepository>(); mock.Setup(a => a.SaveAdventureLocation(newLocationRequest)).Returns(newLocationResponse); var target = new AdventureLocationService { AdventureLocationRepository = mock.Object }; var actual = target.OnPost(newLocationRequest) as AdventureLocationSaveResponse; Assert.AreEqual(expectedNewResponse, actual); }
public AdventureLocation SaveAdventureLocation(AdventureLocation model) { var response = new AdventureLocationSaveResponse(model); response.AdventureLocation = (string.IsNullOrEmpty(model.Id)) ? AdventureLocationRepository.Add(model) : AdventureLocationRepository.Update(model); return response.AdventureLocation; }