public ActionResult <Response <string> > Create([FromForm] string fullUrl) { var guid = HelperUrl.GetGuid(Request); Response.Cookies.Append("Guid", guid); string shortUrl = ""; List <string> errors = new List <string>(); if (string.IsNullOrWhiteSpace(fullUrl)) { errors.Add("Параметр url не должен быть пустым"); } if (errors.Count == 0) { shortUrl = GetShortUrlName(); var link = new Link() { FullUrl = fullUrl, ShortUrl = shortUrl, СlickThroughs = 0, Guid = guid }; _linkService.Create(link); } return(new Response <string>() { Errors = errors, Object = shortUrl }); }
static async Task Main(string[] args) { Console.WriteLine("Press Enter"); Console.ReadLine(); RebrandlyConfiguration.ApiKey = "YOUR API KEY"; LinkService rebrandlyLinkService = new LinkService(); var response = await rebrandlyLinkService.Create(new LinkCreateOptions { Title = "New Short link", Destination = "https://www.processimlabs.com/products" }); Console.WriteLine(response); Console.ReadLine(); }
public async void Create() { var mock = new ServiceMockFacade <ILinkRepository>(); var model = new ApiLinkRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Link>())).Returns(Task.FromResult(new Link())); var service = new LinkService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock, mock.BOLMapperMockFactory.BOLLinkLogMapperMock, mock.DALMapperMockFactory.DALLinkLogMapperMock); CreateResponse <ApiLinkResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.LinkModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Link>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ILinkService, ILinkRepository>(); var model = new ApiLinkServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Link>())).Returns(Task.FromResult(new Link())); var service = new LinkService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkModelValidatorMock.Object, mock.DALMapperMockFactory.DALLinkMapperMock, mock.DALMapperMockFactory.DALLinkLogMapperMock); CreateResponse <ApiLinkServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.LinkModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Link>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LinkCreatedNotification>(), It.IsAny <CancellationToken>())); }
public ActionResult <Link> Create(Link book, string username, string userid, string projectid) { _linkService.Create(book); // AddLink logger =new AddLink(){ // type="Gantt@AddDependency", // id ="userid", // description=username+" added a dependency to gantt chart", // published=DateTime.Now, // data=new Data(){ // id=book.id // } // }; // RabbitMQProducer producer=new RabbitMQProducer(); // producer.AddLink(logger); Logger logger1 = new Logger() { type = "activity@AddDependency", id = userid, project_id = projectid, description = username + " added a dependency to gantt chart", published = DateTime.Now, data = new Data() { id = book.id } }; //Console.WriteLine(JsonConvert.SerializeObject(logger1)); // Console.WriteLine(logger1); _loggerService.Create(logger1); // RabbitMQProducer producer1=new RabbitMQProducer(); // producer1.AddLinkAct(logger1); return(CreatedAtRoute("GetLink", new { id = book.LinkId.ToString() }, book)); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ILinkService, ILinkRepository>(); var model = new ApiLinkServerRequestModel(); var validatorMock = new Mock <IApiLinkServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiLinkServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new LinkService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALLinkMapperMock, mock.DALMapperMockFactory.DALLinkLogMapperMock); CreateResponse <ApiLinkServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LinkCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async Task <string> PostLink([FromBody] Link model) { return(await db.Create(model.Title)); }