public void FindNothing()
        {
            var res = OptionsMapper.Map("dsajasjaa");

            res.Sage.Should().BeFalse();
            res.NoNoko.Should().BeFalse();
        }
        public void FindNoko()
        {
            var res = OptionsMapper.Map("qqqnonokoqqq");

            res.Sage.Should().BeFalse();
            res.NoNoko.Should().BeTrue();
        }
        public void FindSAGE()
        {
            var res = OptionsMapper.Map("aaaaSAGEaaa");

            res.Sage.Should().BeTrue();
            res.NoNoko.Should().BeFalse();
        }
        public void Map_DependencyMap_Test()
        {
            // Arrange
            var dummyRoleMapper    = new RoleMapper();
            var dummyUserMapper    = new UserMapper(dummyRoleMapper);
            var dummyOptionMapper  = new OptionsMapper();
            var dummySectionMapper = new SectionMapper();

            IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper,
                                                    dummySectionMapper, new CookieParser());

            var script = new Script
            {
                Options = new Options
                {
                    AnnouncerName = "test"
                },
                Operator = new User
                {
                    UserId = 1
                },
                Prompter = new User
                {
                    UserId = 1
                }
            };

            var expected = new ComparableTransferScript
            {
                Options = new TransferOptions
                {
                    AnnouncerName = "test"
                },
                Operator = new TransferUser
                {
                    UserId = 1
                },
                Prompter = new TransferUser
                {
                    UserId = 1
                }
            };

            //Act:
            var actual = mapper.Map(script);

            //Assert
            Assert.That(actual.Options.AnnouncerName,
                        Is.EqualTo(expected.Options.AnnouncerName));

            Assert.That(actual.Operator.UserId,
                        Is.EqualTo(expected.Operator.UserId));

            Assert.That(actual.Prompter.UserId,
                        Is.EqualTo(expected.Prompter.UserId));
        }
Exemple #5
0
        public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken)
        {
            var ip     = this.getIp.GetIp(this.Request);
            var ipHash = this.ipHasher.Hash(ip);

            var key = $"{nameof(this.Post)}.{nameof(this.Post.File)}";

            this.bannedImageLogger.Log(this.ModelState[key], ip, ipHash);

            var t = await this.threadService.GetThread(this.Post.ThreadId, Constants.PageSize, cancellationToken).ConfigureAwait(false);

            return(await t.Match(async thread =>
            {
                if (!this.ModelState.IsValid)
                {
                    this.IsAdmin = this.isAdmin.IsAdmin(this.HttpContext);
                    this.Thread = thread;
                    return this.Page().ToIAR();
                }
                else
                {
                    var trip = tripCodeHasher.Hash(StringFuncs.MapString(this.Post.Name, "anonymous"));
                    var options = OptionsMapper.Map(this.Post.Options);
                    var postId = Guid.NewGuid();
                    var f = uploadMapper.Map(this.Post.File, postId);
                    var result = await this.postService.Add(postId, this.Post.ThreadId, trip, this.Post.Comment, options.Sage,
                                                            ipHash, f, cancellationToken);
                    return result.Match(
                        _ =>
                    {
                        this.cookieStorage.SetNameCookie(this.Response, this.Post.Name);
                        if (options.NoNoko)
                        {
                            return this.RedirectToPage <BoardModel>(new { boardKey = thread.Board.BoardKey });
                        }
                        else
                        {
                            return this.RedirectToPage <ThreadModel>(new { boardKey = thread.Board.BoardKey, threadId = this.Post.ThreadId }).ToIAR();
                        }
                    },
                        _ => this.RedirectToPage <BannedModel>().ToIAR(),
                        _ =>
                    {
                        this.ModelState.AddModelError(string.Empty, "Image count exceeded");
                        return Page().ToIAR();
                    },
                        _ =>
                    {
                        this.ModelState.AddModelError(string.Empty, "Post count exceeded");
                        return Page().ToIAR();
                    });
                }
            }, () => this.NotFound().ToIART()));
        }
        public void Map_toDomain_Test()
        {
            //Arange
            var dummyRoleMapper    = new RoleMapper();
            var dummyUserMapper    = new UserMapper(dummyRoleMapper);
            var dummyOptionMapper  = new OptionsMapper();
            var dummySectionMapper = new SectionMapper();

            IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper,
                                                    dummySectionMapper, new CookieParser());

            var script = new TransferScript
            {
                EntityState    = EntityState.Unchanged,
                OperatorId     = 99,
                ScriptId       = 99,
                Title          = "test",
                CreatedDate    = new DateTime(1, 1, 1),
                LastEditedDate = new DateTime(1, 1, 1),
                OptionsId      = 99,
                PrompterId     = 99,
                Options        = null,
                Operator       = null,
                Prompter       = null
            };

            var expected = new ComparableScript
            {
                EntityState    = EntityState.Unchanged,
                OperatorId     = 99,
                ScriptId       = 99,
                Title          = "test",
                CreatedDate    = new DateTime(1, 1, 1),
                LastEditedDate = new DateTime(1, 1, 1),
                OptionsId      = 99,
                PrompterId     = 99,
                Options        = null,
                Operator       = null,
                Prompter       = null
            };

            //Act
            var actual = mapper.Map(script);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(actual.Options, Is.Null);
            Assert.That(actual.Operator, Is.Null);
            Assert.That(actual.Prompter, Is.Null);
        }
        public void Map_NullScript_ReturnsNull_Test()
        {
            //Arange
            var dummyRoleMapper    = new RoleMapper();
            var dummyUserMapper    = new UserMapper(dummyRoleMapper);
            var dummyOptionMapper  = new OptionsMapper();
            var dummySectionMapper = new SectionMapper();

            IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper,
                                                    dummySectionMapper, new CookieParser());

            //Assert
            Assert.That(mapper.Map(script: null), Is.Null);
        }
Exemple #8
0
        public async Task <IActionResult> OnPostAsync(string boardKey, string filter, CancellationToken cancellationToken, int pageNumber = 1)
        {
            var ip     = this.getIp.GetIp(this.Request);
            var ipHash = this.ipHasher.Hash(ip);

            this.bannedImageLogger.Log(this.ModelState[nameof(this.Thread.File)], ip, ipHash);

            var filterOption = NullableMapper.ToOption(filter);

            var t = await this.threadService.GetOrderedThreads(boardKey, filterOption, Constants.PageSize, pageNumber, cancellationToken);

            return(await t.Match(async threads =>
            {
                if (!ModelState.IsValid)
                {
                    this.Threads = threads;
                    return Page().ToIAR();
                }

                var threadId = Guid.NewGuid();
                var postId = Guid.NewGuid();
                var trip = tripCodeHasher.Hash(StringFuncs.MapString(this.Thread.Name, "anonymous"));
                var options = OptionsMapper.Map(this.Thread.Options);
                var f = uploadMapper.Map(this.Thread.File, postId);

                var result = await this.postService.AddThread(postId, threadId, this.Thread.BoardId, this.Thread.Subject ?? string.Empty, trip, this.Thread.Comment, options.Sage, ipHash, f, cancellationToken);

                return result.Match(
                    _ =>
                {
                    this.cookieStorage.SetNameCookie(this.Response, this.Thread.Name);
                    if (options.NoNoko)
                    {
                        return this.RedirectToPage <BoardModel>(new { boardKey = boardKey }).ToIAR();
                    }
                    else
                    {
                        return this.RedirectToPage <ThreadModel>(new { threadId = threadId }).ToIAR();
                    }
                },
                    _ => this.RedirectToPage <BannedModel>().ToIAR());
            }, () => this.NotFound().ToIART()));
        }