public IActionResult CreateFeed([FromBody] FeedCreateOrUpdateModel feedModel) { var autorizedUserId = AuthorizedUserId; var collection = _repository.Collection.GetCollectionByIdAndUserId(feedModel.CollectionId, autorizedUserId); if (collection.IsNull()) { _logger.LogError(string.Format(Resource.LogErrorGetByIsNull, nameof(collection), nameof(feedModel.CollectionId), feedModel.CollectionId)); return(NotFound(new EntityGetModel <IEntity>(feedModel.CollectionId))); } var feed = feedModel.GetEntity(); var feedByHash = _repository.Feed.GetFeedByHash(feed.GetHashCode()); if (feedByHash.IsNull()) { _repository.Feed.CreateFeed(collection, feed); } else { _repository.CollectionFeed.CreateCollectionFeed(collection, feed = feedByHash); } return(CreatedAtRoute(nameof(GetFeedById), new { id = feedModel.Id }, new EntityGetModel <IEntity>(feed))); }
public void CreateFeed() { this.AddJWTAuth(); var model = new FeedCreateOrUpdateModel(); console.Write("Enter collection id: "); int id; while (!int.TryParse(console.ReadLine(), out id)) { } model.CollectionId = id; console.Write("Enter feed uri: "); model.Uri = console.ReadLine(); var response = HttpClient.PostAsJsonAsync("api/feed", model).Result; console.WriteLine(response.StatusCode); console.WriteLine(response.Content.ReadAsStringAsync().Result); CheckAuth(response); }
public void CreateFeed_FeedWithoutHash_ShouldCreateFeed() { // arrange var authorizedUser = _fixture.Fixture.Create <User>(); var feed = _fixture.Fixture.Create <Feed>(); var collection = _fixture.Fixture.Create <Collection>(); var model = new FeedCreateOrUpdateModel(feed); _fixture.SetAuthorizedUserId(authorizedUser.Id); _fixture.CollectionRepository.Setup(r => r.GetCollectionByIdAndUserId(model.CollectionId, authorizedUser.Id)).Returns(collection).Verifiable(); _fixture.FeedRepository.Setup(r => r.GetFeedByHash(feed.GetHashCode())).Returns((Feed)null).Verifiable(); _fixture.FeedRepository.Setup(r => r.CreateFeed(collection, feed)).Verifiable(); // act var act = (CreatedAtRouteResult)_fixture.Controller.CreateFeed(model); // assert Assert.NotNull(act); Assert.Equal((int)HttpStatusCode.Created, act.StatusCode); Assert.Equal(feed.Id, ((EntityGetModel <IEntity>)act.Value).Id); _fixture.CollectionRepository.VerifyAll(); _fixture.FeedRepository.VerifyAll(); }