コード例 #1
0
        public HttpResponseMessage CreateSplit(CreateSplitDTO dto)
        {
            if (dto.NewTopicId == dto.OldTopicId)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            var portalSettings = PortalSettings;
            var userInfo       = portalSettings.UserInfo;
            var forumUser      = new UserController().GetUser(portalSettings.PortalId, ActiveModule.ModuleID, userInfo.UserID);

            var fc = new ForumController();

            var forum_out = fc.Forums_Get(portalSettings.PortalId, ActiveModule.ModuleID, 0, forumUser.UserId, false, true, dto.OldTopicId);
            var forum_in  = fc.GetForum(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId);

            if (forum_out != null && forum_in != null)
            {
                var perm = false;

                if (forum_out == forum_in)
                {
                    perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles);
                }
                else
                {
                    perm = Permissions.HasPerm(forum_out.Security.View, forumUser.UserRoles) && Permissions.HasPerm(forum_in.Security.View, forumUser.UserRoles);
                }

                var modSplit = Permissions.HasPerm(forum_out.Security.ModSplit, forumUser.UserRoles);

                if (perm && modSplit)
                {
                    var tc = new TopicsController();

                    int topicId;

                    if (dto.NewTopicId < 1)
                    {
                        var subject      = Utilities.CleanString(portalSettings.PortalId, dto.Subject, false, EditorTypes.TEXTBOX, false, false, ActiveModule.ModuleID, string.Empty, false);
                        var replies      = dto.Replies.Split('|');
                        var rc           = new DotNetNuke.Modules.ActiveForums.DAL2.ReplyController();
                        var firstReply   = rc.Get(Convert.ToInt32(replies[0]));
                        var cc           = new ContentController();
                        var firstContent = cc.Get(firstReply.ContentId);
                        topicId = tc.Topic_QuickCreate(portalSettings.PortalId, ActiveModule.ModuleID, dto.NewForumId, subject, string.Empty, firstContent.AuthorId, firstContent.AuthorName, true, Request.GetIPAddress());
                        tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, true);
                    }
                    else
                    {
                        topicId = dto.NewTopicId;
                        tc.Replies_Split(dto.OldTopicId, topicId, dto.Replies, false);
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #2
0
        public async Task Content_GET_WithDbContext_Async()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <WanderListDbContext>()
                          .UseInMemoryDatabase(databaseName: "WanderList")
                          .Options;

            var logger = new Mock <ILogger <Content> >();

            using var context = new WanderListDbContext(options);

            var content1 = new Content()
            {
                ContentId = Guid.NewGuid(),
                Address   = "testing1",
                //Name = "tryme1"
            };

            var content2 = new Content()
            {
                ContentId = Guid.NewGuid(),
                Address   = "testing2",
                //Name = "tryme2"
            };

            var content3 = new Content()
            {
                ContentId = Guid.NewGuid(),
                Address   = "testing3",
                //Name = "tryme3"
            };

            context.Add(content1);
            context.Add(content2);
            context.Add(content3);
            context.SaveChanges();

            var controller = new ContentController(context, logger.Object);

            //Act
            var result = await controller.Get();

            //Assert
            // Verifying that ILogger is working is a bit of a rabbit hole.
            // For now it really isn't of interest... but it is technically possible
            var contentResult = Assert.IsAssignableFrom <IEnumerable <Content> >(result);

            Assert.NotNull(contentResult);

            Assert.Contains(content1, contentResult);
            Assert.Contains(content2, contentResult);
            Assert.Contains(content3, contentResult);
        }
コード例 #3
0
        public async Task GetReturnsOk()
        {
            var controller = new ContentController();

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            var response = await controller.Get(10, "en").ExecuteAsync(CancellationToken.None);

            var json = JsonConvert.DeserializeObject <dynamic>(await response.Content.ReadAsStringAsync());

            Assert.IsTrue(json["ContentId"] == 10);
        }
コード例 #4
0
        public async Task WhenValidParametersAreSupplied_ThenShouldReturnContentResult(
            [Frozen] Mock <IMediator> mediator,
            ContentController controller,
            GetContentQueryResult content,
            string type,
            string applicationId)
        {
            //arrange
            mediator.Setup(m => m.Send(It.Is <GetContentQuery>(q => q.Type == type && q.ApplicationId == applicationId), It.IsAny <CancellationToken>()))
            .ReturnsAsync(content);

            //act
            var query = new GetContentQuery
            {
                Type          = type,
                ApplicationId = applicationId
            };

            var result = await controller.Get(query, new CancellationToken());

            //assert
            result.Should().BeOfType <ContentResult>();
            ((ContentResult)result).Content.Should().Be(content.Content);
        }