public void Encode_Numbers() { //Arrange string expectedResult1 = "2"; string expectedResult2 = "b3q"; string expectedResult3 = "dltl"; string expectedResult4 = "oiob7b"; string expectedResult5 = "djnn9jlzff"; //Act string result1 = converter.Encode(1); string result2 = converter.Encode(12345); string result3 = converter.Encode(540000); string result4 = converter.Encode(1234512345); string result5 = converter.Encode(987777775554654); result1 = _GetValuePartOfString(result1); result2 = _GetValuePartOfString(result2); result3 = _GetValuePartOfString(result3); result4 = _GetValuePartOfString(result4); result5 = _GetValuePartOfString(result5); //Assert Assert.AreEqual(expectedResult1, result1); Assert.AreEqual(expectedResult2, result2); Assert.AreEqual(expectedResult3, result3); Assert.AreEqual(expectedResult4, result4); Assert.AreEqual(expectedResult5, result5); }
// POST api/records public HistoryRecordViewModel Post([FromBody] HistoryRecordViewModel viewModelHistoryRecord) { if (ModelState.IsValid) { HistoryRecord historyRecord = Mapper.Map <HistoryRecordViewModel, HistoryRecord>(viewModelHistoryRecord); try { historyRecord.CreateDate = DateTime.Now; //todo настроить в EF автогенерацию historyRecordService.CreateHistoryRecord(historyRecord); historyRecordService.SaveHistoryRecord(); } catch (Exception ex) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); } ConverterUrl converter = new ConverterUrl(10); //todo вынести в настройки 10 string hash = converter.Encode(historyRecord.Id); //historyRecord.UrlShort = $"{Request.RequestUri.Authority}api/values/{hash}"; //to do Или проще так? historyRecord.UrlShort = $"{Request.RequestUri.Authority}/Home/Record/{hash}"; historyRecordService.UpdateHistoryRecord(historyRecord); historyRecordService.SaveHistoryRecord(); viewModelHistoryRecord = Mapper.Map <HistoryRecord, HistoryRecordViewModel>(historyRecord); } return(viewModelHistoryRecord); }