예제 #1
0
        public async Task Create_ServiceError_BadRequest()
        {
            // Setup
            var id    = "some_id";
            var input = new CreatePublicationModel
            {
                Content = "some content"
            };

            var publication = new Publication(id, input.Content, Enumerable.Empty <string>(), null, DateTimeOffset.Now, DateTimeOffset.Now);

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.UpdateAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(DomainResult.Error("Some error"));

            serviceMock
            .Setup(s => s.GetByIdAsync(id))
            .ReturnsAsync(publication);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"/publications/{id}/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #2
0
        public Publication AddPublication(CreatePublicationModel model)
        {
            var           authordNames = model.Authors.Split(", ");
            List <Author> authors      = new List <Author>();

            foreach (var name in authordNames)
            {
                var author = new Author {
                    Name = name
                };
                _unitOfWork.AuthorRepository.Create(author);
                authors.Add(author);
            }
            var publ = new Publication
            {
                Date    = model.Date,
                Authors = authors.ToList(),
                Status  = model.Status,
                Topic   = model.Topic,
                Type    = model.Type
            };

            var res = _unitOfWork.PublicationRepository.Create(publ);

            return(res);
        }
예제 #3
0
        public void PublicationServiceTest_AddPublication()
        {
            using (var mack = AutoMock.GetLoose())
            {
                //Arrange
                var model = new CreatePublicationModel
                {
                    Date    = new DateTime(2019, 1, 1),
                    Authors = "Bogdan Volodymyr Andrainna Bogdan Volodymyr",
                    Status  = "closed",
                    Topic   = "Report",
                };

                mack.Mock <IPublicationService>()
                .Setup(x => x.AddPublication(model))
                .Returns(addpublication(model));
                //Act
                var cls = mack.Create <IPublicationService>();

                var expected = addpublication(model);

                var actual = cls.AddPublication(model);
                //Assert
                Assert.AreEqual(expected.Id, actual.Id);
            };
        }
예제 #4
0
        public async Task <NewsFeedPublication> CreateAsync(string content, string author)
        {
            var model  = new CreatePublicationModel(content, author);
            var entity = await publicationsApi.CreateAsync(model);

            return(new NewsFeedPublication(entity.Id, entity.Content, new CommentsShort(Enumerable.Empty <PublicationComment>(), 0),
                                           new ReactionShort(new Dictionary <ReactionType, int>(), new UserReaction(new ReactionType()))));
        }
예제 #5
0
        public async Task Create_ServiceError_BadRequest()
        {
            // Setup
            var input = new CreatePublicationModel
            {
                Content = "some content"
            };

            var serviceMock = new Mock <IPublicationService>();

            serviceMock
            .Setup(s => s.CreateAsync(It.IsAny <string>(), It.IsAny <UserInfo>()))
            .ReturnsAsync((DomainResult.Error("Some error"), default));
        public async Task <ActionResult <Publication> > CreateAsync([FromBody] CreatePublicationModel model)
        {
            var author = await userProvider.GetByIdAsync(model.AuthorId);

            var(result, id) = await publicationService.CreateAsync(model.Content, author);

            if (!result.Successed)
            {
                return(BadRequest(result.ToProblemDetails()));
            }

            return(Created(Url.Action("GetById", new { id }), await publicationService.GetByIdAsync(id)));
        }
예제 #7
0
        public async Task <IActionResult> SavePublication([FromForm] CreatePublicationModel model)
        {
            var currentUser = await _userServ.GetUserAsync(User);

            if (model.Authors.IndexOf(currentUser.Name) == -1)
            {
                model.Authors += ", " + currentUser.Name;
            }
            model.Date = DateTime.Now;
            _serv.AddPublication(model);

            return(RedirectToAction("Create"));
        }
예제 #8
0
        public async Task <NewsFeedPublication> PublishAsync(string content, string userId)
        {
            var model  = new CreatePublicationModel(content, userId);
            var entity = await publicationsApi.CreateAsync(model);

            return(new NewsFeedPublication(
                       entity.Id,
                       entity.Content,
                       entity.CreatedOn,
                       entity.UpdatedOn,
                       new CommentsShort(Enumerable.Empty <PublicationComment>(), 0),
                       new ReactionShort(new Dictionary <ReactionType, int>(), null),
                       ToUser(entity.Author)));
        }
        public ActionResult CreatePublication(CreatePublicationModel publicationView)
        {
            Publication publication = new Publication();

            publication.ToCreatePublicationModel(publicationView);
            if (db.Publications.Where(m => m.Id == publicationView.Id).FirstOrDefault() == null)
            {
                publication = db.Publications.Add(publication);
                db.SaveChanges();
            }
            else
            {
                publication = db.Publications.Where(m => m.Id == publicationView.Id).FirstOrDefault();
                publication.ToCreatePublicationModel(publicationView);

                publication.IsApprovedByAdmin = false;
                publication.IsActive          = false;
                db.Entry(publication).State   = EntityState.Modified;
                db.SaveChanges();
            }
            int count;

            try
            {
                count = Directory.EnumerateFiles(Server.MapPath("~/Images/Publication/" + publication.Id + "/")).Count() + 1;
            }
            catch
            {
                count = 1;
            }
            foreach (var file in publicationView.Files)
            {
                if (file != null)
                {
                    try
                    {
                        System.IO.File.WriteAllBytes(Server.MapPath("~/Images/Publication/" + publication.Id + "/" + count + ".jpg"), ImageTransformation.Transform(file));
                    }
                    catch (IOException e)
                    {
                        Directory.CreateDirectory(Server.MapPath("~") + "/Images/Publication/" + publication.Id);
                        System.IO.File.WriteAllBytes(Server.MapPath("~/Images/Publication/" + publication.Id + "/" + count + ".jpg"), ImageTransformation.Transform(file));
                    }
                    count++;
                }
            }
            return(RedirectToAction("MyPublications"));
        }
예제 #10
0
        public async Task Create_EmptyContent_BadRequest()
        {
            // Setup
            var input = new CreatePublicationModel
            {
                Content = null
            };

            var serviceMock = new Mock <IPublicationService>();

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(provider => serviceMock.Object);
            });

            // Act
            var response = await client.PostAsync("/publications/", input.AsJsonContent());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
예제 #11
0
        public Publication addpublication(CreatePublicationModel model)
        {
            var           authorNames = model.Authors.Split(" ");
            List <Author> authors     = new List <Author>();

            foreach (var name in authorNames)
            {
                var author = new Author {
                    Name = name
                };
                authors.Add(author);
            }
            var publ = new Publication
            {
                Date    = model.Date,
                Authors = authors.ToArray(),
                Status  = model.Status,
                Topic   = model.Topic,
            };

            return(publ);
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="createPublicationModel"> (optional)</param>
        /// <returns>Task of Publication</returns>
        public async System.Threading.Tasks.Task <Publication> PublicationsCreateAsync(CreatePublicationModel createPublicationModel = default(CreatePublicationModel))
        {
            GhostNetwork.Publications.Client.ApiResponse <Publication> localVarResponse = await PublicationsCreateAsyncWithHttpInfo(createPublicationModel);

            return(localVarResponse.Data);
        }
예제 #13
0
        public Publication AddPublication(CreatePublicationModel pb)
        {
            var res = _publServ.AddPublication(pb);

            return(res);
        }
예제 #14
0
        public void ToCreatePublicationModel(CreatePublicationModel model)
        {
            Id             = model.Id;
            PropertyTypeId = model.PropertyTypeId;
            if (model.BalconyTypeId == 0)
            {
                BalconyTypeId = 1;
            }
            else
            {
                BalconyTypeId = model.BalconyTypeId;
            }

            if (model.BathroomTypeId == 0)
            {
                BathroomTypeId = 1;
            }
            else
            {
                BathroomTypeId = model.BathroomTypeId;
            }

            if (model.BlockOfFlatsTypeId == 0)
            {
                BlockOfFlatsTypeId = 1;
            }
            else
            {
                BlockOfFlatsTypeId = model.BathroomTypeId;
            }

            if (model.WallMaterialId == 0)
            {
                WallMaterialId = 1;
            }
            else
            {
                WallMaterialId = model.WallMaterialId;
            }

            if (model.UserId == 0)
            {
                UserId = 1;
            }
            else
            {
                UserId = model.UserId;
            }
            IsRent             = model.IsRent;
            IsPassageRoom      = model.IsPassageRoom;
            IsOneDayRent       = model.IsOneDayRent;
            IsFurnitureExist   = model.IsFurnitureExist;
            Floor              = model.Floor;
            Address            = model.Address;
            Coordinates        = model.Coordinates;
            Cost               = model.Cost;
            Description        = model.Description;
            TotalArea          = model.TotalArea;
            LivingArea         = model.LivingArea;
            KitchenArea        = model.KitchenArea;
            PropertyArea       = model.PropertyArea;
            YearOfConstruction = model.YearOfConstruction;
            CanExchange        = model.CanExchange;
            RoomAmount         = model.RoomAmount;
            OfferingRoomAmount = model.OfferingRoomAmount;
            IsSubwayNear       = model.IsSubwayNear;
            PostTime           = DateTime.Now;
        }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="createPublicationModel"> (optional)</param>
 /// <returns>Publication</returns>
 public Publication PublicationsCreate(CreatePublicationModel createPublicationModel = default(CreatePublicationModel))
 {
     GhostNetwork.Publications.Client.ApiResponse <Publication> localVarResponse = PublicationsCreateWithHttpInfo(createPublicationModel);
     return(localVarResponse.Data);
 }
예제 #16
0
        public async Task CreateAsync(string content, string author)
        {
            var model = new CreatePublicationModel(content, author);

            await publicationsApi.PublicationsCreateAsync(model);
        }
예제 #17
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="createPublicationModel"> (optional)</param>
        /// <returns>Task of ApiResponse (Publication)</returns>
        public async System.Threading.Tasks.Task <GhostNetwork.Publications.Client.ApiResponse <Publication> > PublicationsCreateAsyncWithHttpInfo(CreatePublicationModel createPublicationModel = default(CreatePublicationModel))
        {
            GhostNetwork.Publications.Client.RequestOptions localVarRequestOptions = new GhostNetwork.Publications.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json",
                "text/json",
                "application/_*+json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };

            foreach (var _contentType in _contentTypes)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType);
            }

            foreach (var _accept in _accepts)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", _accept);
            }

            localVarRequestOptions.Data = createPublicationModel;


            // make the HTTP request

            var localVarResponse = await this.AsynchronousClient.PostAsync <Publication>("/Publications", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("PublicationsCreate", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="GhostNetwork.Publications.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="createPublicationModel"> (optional)</param>
        /// <returns>ApiResponse of Publication</returns>
        public GhostNetwork.Publications.Client.ApiResponse <Publication> PublicationsCreateWithHttpInfo(CreatePublicationModel createPublicationModel = default(CreatePublicationModel))
        {
            GhostNetwork.Publications.Client.RequestOptions localVarRequestOptions = new GhostNetwork.Publications.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json",
                "text/json",
                "application/_*+json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };

            var localVarContentType = GhostNetwork.Publications.Client.ClientUtils.SelectHeaderContentType(_contentTypes);

            if (localVarContentType != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
            }

            var localVarAccept = GhostNetwork.Publications.Client.ClientUtils.SelectHeaderAccept(_accepts);

            if (localVarAccept != null)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
            }

            localVarRequestOptions.Data = createPublicationModel;


            // make the HTTP request
            var localVarResponse = this.Client.Post <Publication>("/Publications", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("PublicationsCreate", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }