public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ITweetService service = testServer.Host.Services.GetService(typeof(ITweetService)) as ITweetService;
            var           model   = new ApiTweetServerRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, TimeSpan.Parse("02:00:00"), 1);
            CreateResponse <ApiTweetServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.TweetDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiTweetServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Exemple #2
0
        public static void CopiarTweets(ITweetService tweetService, ITagService tagService, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret, string[] tags)
        {
            Tweets lista = new Tweets(consumerKey, consumerSecret, accessToken, accessTokenSecret);

            var listaEntidadeRequest = Mapper.Map <List <ITweet>, List <TweetRequest> >(lista.GetAll(tags).ToList());

            tweetService.Create(listaEntidadeRequest);
        }
Exemple #3
0
        public IActionResult Create(int userId, [FromBody] CreateTweetDto dto)
        {
            if (ModelState.IsValid)
            {
                var result = _tweetService.Create(userId, dto);
                return(Ok(result));
            }

            return(BadRequest());
        }
Exemple #4
0
        public async Task <IActionResult> Create([FromBody] Tweet tweet)
        {
            try {
                await _tweetService.Create(tweet);
            } catch (ArgumentException e) {
                _logger.LogError(e.Message);

                return(BadRequest());
            }

            return(Ok());
        }
Exemple #5
0
        public async Task <IActionResult> Create(TweetViewModel tweet)
        {
            if (ModelState.IsValid)
            {
                tweet.Author = await userService.FindByNameAsync(HttpContext.User.Identity.Name);

                tweet.AuthorId = tweet.Author.Id;
                tweet.Date     = DateTime.Now;
                tweetService.Create(tweet);
                return(RedirectToAction("Index", "Tweet"));
            }
            return(View("Create"));
        }
 public async Task Send(string userId, string user, string content, string created)
 {
     try
     {
         var model = new TweetViewModel
         {
             AuthorId = int.Parse(userId),
             Content  = content,
             Created  = DateTime.Parse(created)
         };
         service.Create(model);
         await this.Clients.All.SendAsync("Send", userId, user, content, created);
     }
     catch (Exception exception)
     {
     }
 }
Exemple #7
0
 public ActionResult Create(TweetViewModel model)
 {
     try
     {
         // TODO: Add insert logic here
         model.Created = DateTime.Now;
         var user = personService
                    .GetCurrentUserAsync(HttpContext).Result;
         model.AuthorId = user.Id;
         model.Author   = user;
         service.Create(model);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
        public IActionResult CreateTweet([FromBody] TweetCreateModel tweetCreate)
        {
            var tweet = _mapper.Map <Tweet>(tweetCreate);

            return(Ok(_tweetService.Create(tweet)));
        }
Exemple #9
0
 //[Authorize]
 public int Create([FromBody] TweetRequest request)
 {
     return(_service.Create(request));
 }