コード例 #1
0
        public void TestGetAll()
        {
            var firstComment  = CommentBuilder.New().WithContent("FirstComment").Build();
            var secondComment = CommentBuilder.New().WithContent("SecondComment").Build();
            var thirdComment  = CommentBuilder.New().WithContent("ThirdComment").Build();

            var resultValidationFirst  = new CommentValidator().Validate(firstComment);
            var resultValidationSecond = new CommentValidator().Validate(secondComment);
            var resultValidationThird  = new CommentValidator().Validate(thirdComment);

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(120);
            memoryCache.Add("firstComment", firstComment, policy);
            memoryCache.Add("secondComment", secondComment, policy);
            memoryCache.Add("thirdComment", thirdComment, policy);
            Assert.IsTrue(3 == memoryCache.GetCount());

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(firstComment);
            new CreateComment().CreateNewRegister(secondComment);
            new CreateComment().CreateNewRegister(thirdComment);
            List <Comment> listComments = new GetComment().GetAllRegister();

            Assert.IsTrue(3 == listComments.Count);
        }
コード例 #2
0
        public async Task PostWithOneComment_GetPostComments_ReturnOne()
        {
            //Assert
            var commentRepository = DatabaseHelper.GetCommentRepository("Get_Comment_Controller");
            var commentController = new CommentsController(commentRepository);
            var postBuilder       = new PostBuilder();
            var commentBuilder    = new CommentBuilder();
            var post    = postBuilder.Build();
            var comment = commentBuilder.Build();

            comment.PostId = post.Id;

            //Act
            commentRepository.Add(comment);
            commentRepository.Save();

            //Assert
            var apiResponse = await commentController.GetComments(post.Id);

            var okResponse = apiResponse as OkObjectResult;

            Assert.NotNull(okResponse);

            var objectResponse = okResponse.Value as List <Comment>;

            Assert.Single(objectResponse);
        }
コード例 #3
0
        public void TestUpdate()
        {
            var comment = CommentBuilder.New().Build();

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(120);
            memoryCache.Add("commentUpdate", comment, policy);
            Comment commentGet = (Comment)memoryCache["commentUpdate"];

            Assert.AreEqual(comment.ToString(), commentGet.ToString());

            var secondComment = CommentBuilder.New().WithContent("AnotherContent").Build();

            memoryCache.Set("commentUpdate", secondComment, policy);
            commentGet = (Comment)memoryCache["commentUpdate"];
            Assert.IsTrue(comment.Content.ToString() != commentGet.Content.ToString());

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            var commentCopia = new GetComment().GetRegisterById(comment.Id);
            var thirdComment = CommentBuilder.New().WithId(commentCopia.Id).WithContent("SecondContent").Build();

            new UpdateComment().UpdateRegister(thirdComment);
            Assert.IsTrue(thirdComment.Content.ToString() != comment.Content.ToString());
        }
コード例 #4
0
        public void Comment_EditingWithValidDataWithinDeadline_Successfully()
        {
            // Arrange
            var target                 = new CommentBuilder().SetupValidComment().Build();
            var originalId             = target.Id;
            var originalUserId         = target.UserId;
            var originalCreatedOn      = target.CreatedOn;
            var originalParentQuestion = target.ParentQuestion;
            var originalParentAnswer   = target.ParentAnswer;

            var userId  = new Guid("00000000-0000-0000-0000-000000000002");
            var newBody = "NewBodyNormal";
            var limits  = new LimitsBuilder().Build();

            // Act
            target.Edit(target.User, newBody, limits);

            // Assert
            Assert.Equal(originalId, target.Id);
            Assert.Equal(originalUserId, target.UserId);
            Assert.Equal(originalCreatedOn, target.CreatedOn);
            Assert.Equal(originalParentQuestion, target.ParentQuestion);
            Assert.Equal(originalParentAnswer, target.ParentAnswer);
            Assert.Equal(newBody, target.Body);
        }
コード例 #5
0
ファイル: WorkerRole.cs プロジェクト: cjbanna/setlistbot
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.TraceInformation("Working");

                Setlistbot.Setlistbot bot = new Setlistbot.Setlistbot();
                // TODO: Interfaces could be refactored to use dependency injection.
                IBotSettings settings = new BotSettings
                {
                    Username    = CloudConfigurationManager.GetSetting(SettingsConstants.Username),
                    Password    = CloudConfigurationManager.GetSetting(SettingsConstants.Password),
                    Key         = CloudConfigurationManager.GetSetting(SettingsConstants.Key),
                    Secret      = CloudConfigurationManager.GetSetting(SettingsConstants.Secret),
                    Subreddit   = CloudConfigurationManager.GetSetting(SettingsConstants.Subreddit),
                    MaxComments = int.Parse(CloudConfigurationManager.GetSetting(SettingsConstants.MaxComments)),
                    MaxSetlists = int.Parse(CloudConfigurationManager.GetSetting(SettingsConstants.MaxSetlists))
                };
                ISetlistAgent   setlistAgent   = new PhishinWebAgent();
                ICommentBuilder commentBuilder = new CommentBuilder(settings.MaxSetlists);
                // Use subreddit as partition key
                ICommentRepository commentRepository = new CommentRepository(settings.Subreddit);
                bot.Run(settings, setlistAgent, commentBuilder, commentRepository);

                await Task.Delay(10000);
            }
        }
コード例 #6
0
ファイル: NewsController.cs プロジェクト: Ptize/NewsPortal
 public NewsController(INewsStorage newsStorage, NewsBuilder newsBuilder, CommentBuilder commentBuilder, ICommentStorage commentStorage)
 {
     _newsStorage    = newsStorage;
     _newsBuilder    = newsBuilder;
     _commentBuilder = commentBuilder;
     _commentStorage = commentStorage;
 }
コード例 #7
0
        public void GetByIdReturnsBadRequest()
        {
            var comment = CommentBuilder.New().Build();

            var result = controller.Get(comment.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
コード例 #8
0
        public static void ShouldMatchStructure <T>(this T comment, Action <CommentBuilder> builderAction)
            where T : Comment, new()
        {
            var builder = new CommentBuilder();

            builderAction(builder);

            builder.VerifyExpectations(comment);
        }
コード例 #9
0
ファイル: CommentBuilderTests.cs プロジェクト: vcsb/tfs-merge
        public void GetComment_Basic()
        {
            // "{0} {1} > {2}, {3}: {4}"
            string comment  = CommentBuilder.GetComment(_someComment, _changesetId, _ownerLong, _source, _target, MergeOptionsEx.None);
            string expected = $"{_source} {_changesetId} > {_target}, {_ownerShort}: {_someComment}";

            PrintResults(null, expected, comment);
            comment.Should().Be(expected);
        }
コード例 #10
0
        private void InitializeTestData(out Comment comment)
        {
            var commentBuilder = new CommentBuilder();

            comment = commentBuilder.WithId(new Guid("fec459ec-ede8-4ab9-b0e2-b3819f0a09b9")).WithName("CommentAuthor1")
                      .WithBody("Comment body1")
                      .WithGameId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8"))
                      .Build();
        }
コード例 #11
0
        public void TestCreateWithId()
        {
            var comment = CommentBuilder.New().WithId(new Guid()).Build();

            Assert.True(comment.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"));
            Assert.True(comment.Autor.Id != Guid.Empty && comment.Autor.Id != null);
            Assert.True(comment.Content == "TestContent");
            Assert.True(comment.PublicationId != null && comment.PublicationId != Guid.Empty);
        }
コード例 #12
0
        public void PutReturnsBadRequest_CommentNotExistOnDatabase()
        {
            var comment = CommentBuilder.New().Build();

            new CreateComment().CreateNewRegister(comment);

            var result = controller.Put(Guid.NewGuid(), "Conteudo");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
コード例 #13
0
        public void PutReturnsBadRequest_CommentInvalid()
        {
            var comment = CommentBuilder.New().Build();

            creator.CreateNewRegister(comment);

            var result = controller.Put(comment.Id, "");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
コード例 #14
0
        public void GetByIdReturnsOk()
        {
            var comment = CommentBuilder.New().Build();

            creator.CreateNewRegister(comment);

            var result = controller.Get(comment.Id);

            Assert.IsType <OkObjectResult>(result.Result);
        }
コード例 #15
0
        public void Comment_EditingWithInvalidData_FailsValidation(string userId, string body)
        {
            // Arrange
            var target = new CommentBuilder().SetupValidComment().Build();
            var limits = new LimitsBuilder().Build();
            var user   = new UserBuilder().BuildUser(new Guid(userId)).Build();

            // Act, Assert
            Assert.Throws <BusinessException>(() =>
                                              target.Edit(user, body, limits));
        }
コード例 #16
0
        public void TestValidationCommentWithInvalidTopic()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var badComment1 = CommentBuilder.New().WithContent("  ").Build();

            var resultValidation2 = new CommentValidator().Validate(badComment1);

            Assert.False(resultValidation2.IsValid);
        }
コード例 #17
0
        public void TestValidationCommentWithValidResult()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var okComment = CommentBuilder.New().Build();

            var resultValidation1 = new CommentValidator().Validate(okComment);

            Assert.True(resultValidation1.IsValid);
        }
コード例 #18
0
        public void TestEntityDelete()
        {
            var comment = CommentBuilder.New().Build();

            var mockTeste = new Mock <IDeleteDB <Comment> >();

            var commentRepository = new CommentRepository(mockTeste.Object);

            commentRepository.Delete(comment);

            mockTeste.Verify(x => x.DeleteRegister(It.IsAny <Comment>()));
        }
コード例 #19
0
        public void TestValidationCommentWithInvalidPublicationId()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var badComment1 = CommentBuilder.New().WithPublicationId(Guid.Parse("00000000-0000-0000-0000-000000000000")).Build();

            var resultValidation2 = new CommentValidator().Validate(badComment1);

            Assert.False(resultValidation2.IsValid);
        }
コード例 #20
0
        public void Voteable_CanApplyVoteToComment_Successfully()
        {
            // Arrange
            var target = new CommentBuilder().SetupValidComment().Build();
            var vote   = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            // Act
            target.ApplyVote(vote);

            // Assert
            Assert.Equal(1, target.VotesSum);
            Assert.Contains(vote, target.Votes);
        }
コード例 #21
0
        /// <summary>
        /// Parses and constructs a <see cref="DocumentationComment" /> from the given fragment of XML.
        /// </summary>
        /// <param name="xml">The fragment of XML to parse.</param>
        /// <returns>A DocumentationComment instance.</returns>
        public static DocumentationComment FromXmlFragment(string xml)
        {
            var result = s_cacheLastXmlFragmentParse;

            if (result == null || result.FullXmlFragment != xml)
            {
                // Cache miss
                result = CommentBuilder.Parse(xml);
                s_cacheLastXmlFragmentParse = result;
            }

            return(result);
        }
コード例 #22
0
ファイル: CommentBuilderTests.cs プロジェクト: vcsb/tfs-merge
        public void GetComment_MergeRange_Basic_OneOwner()
        {
            var idAndOwnerOfChanges = new List <Tuple <int, string> >();

            idAndOwnerOfChanges.Add(Tuple.Create(_changesetId, _ownerLong));
            idAndOwnerOfChanges.Add(Tuple.Create(_changesetId + 1, _ownerLong));
            idAndOwnerOfChanges.Add(Tuple.Create(_changesetId + 2, _ownerLong));

            string comment  = CommentBuilder.GetCombinedMergeCheckinComment(_source, _target, idAndOwnerOfChanges, MergeOptionsEx.None);
            string expected = $"{_source} {_changesetId}-{_changesetId + 2} > {_target}, {_ownerShort}: ";

            PrintResults(null, expected, comment);
            comment.Should().Be(expected);
        }
コード例 #23
0
        private void InitializeTestData(out Game game, out Comment comment)
        {
            var gameBuilder    = new GameBuilder();
            var commentBuilder = new CommentBuilder();

            game = gameBuilder.WithId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8")).WithKey("c21")
                   .WithName("Cry Souls").WithDescription("Cry Souls desc").WithUnitsInStock(10).WithPrice(10)
                   .WithPublisher("Unknown").Build();

            comment = commentBuilder.WithId(new Guid("fec459ec-ede8-4ab9-b0e2-b3819f0a09b9")).WithName("CommentAuthor1")
                      .WithBody("Comment body1")
                      .WithGameId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8"))
                      .Build();
        }
コード例 #24
0
        public void TestValidationCommentExist()
        {
            var okComment = CommentBuilder.New().Build();

            new CreateComment().CreateNewRegister(okComment);

            var badComment = CommentBuilder.New().WithContent("SomeRandomContent").Build();

            var resultValidation1 = new CommentExistValidator().Validate(okComment.Id);
            var resultValidation2 = new CommentExistValidator().Validate(badComment.Id);

            Assert.True(resultValidation1.IsValid);
            Assert.False(resultValidation2.IsValid);
        }
コード例 #25
0
ファイル: CommentBuilderTests.cs プロジェクト: vcsb/tfs-merge
        public void GetComment_ReplacePreviousPrefix_WasRangeWithOneOwner()
        {
            string commentWithOldPrefix = $"{_source} {_changesetId}-{_changesetId + 1} > {_target}, {_ownerShort}: {_someComment}";

            const string newSource = "NewSource";
            const string newTarget = "NewTarget";
            const int    newId     = _changesetId + 10;

            string comment  = CommentBuilder.GetComment(commentWithOldPrefix, newId, _ownerLong, newSource, newTarget, MergeOptionsEx.None);
            string expected = $"{newSource} {newId} > {newTarget}, {_ownerShort}: {_someComment}";

            PrintResults(commentWithOldPrefix, expected, comment);
            comment.Should().Be(expected);
        }
コード例 #26
0
        public void Commentable_CommentOutOfOrder_Throws()
        {
            // Arrange
            var target        = new Commentable();
            var firstComment  = new CommentBuilder().SetupValidComment(1).Build();
            var secondComment = new CommentBuilder().SetupValidComment(2).Build();
            var targetComment = new CommentBuilder().SetupValidComment(2).Build();  // Repeat the order number.

            target.Comment(firstComment);
            target.Comment(secondComment);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.Comment(targetComment));
        }
コード例 #27
0
 /// <summary>
 /// Write comments if not empty
 /// </summary>
 private void CreateComments(DocDescription description, string originalJavaName)
 {
     if (description == null)
     {
         if (!string.IsNullOrEmpty(originalJavaName))
         {
             var builder = new CommentBuilder();
             builder.JavaName.Write(originalJavaName);
             builder.WriteTo(writer, indent);
         }
         return;
     }
     description.WriteAsCode(writer, indent, resolver, originalJavaName);
 }
コード例 #28
0
ファイル: CommentBuilderTests.cs プロジェクト: vcsb/tfs-merge
        public void GetComment_ReplacePreviousPrefix_NonCaseSensitive()
        {
            string commentWithOldPrefix = $"{_source.ToLowerInvariant()} {_changesetId} > {_target.ToLowerInvariant()}, {_ownerShort.ToLowerInvariant()}: {_someComment}";

            const string newSource  = "NewSource";
            const string newTarget  = "NewTarget";
            const int    newId      = _changesetId + 1;
            const string mergeOwner = "IShould NotOwnThis";

            string comment  = CommentBuilder.GetComment(commentWithOldPrefix, newId, mergeOwner, newSource, newTarget, MergeOptionsEx.None);
            string expected = $"{newSource} {newId} > {newTarget}, {_ownerShort.ToLowerInvariant()}: {_someComment}";

            PrintResults(commentWithOldPrefix, expected, comment);
            comment.Should().Be(expected);
        }
コード例 #29
0
        public void TestCreate()
        {
            var comment = CommentBuilder.New().Build();

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
            Assert.IsTrue(memoryCache.Add("comment", comment, policy));

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            var idGet = new GetComment().GetRegisterById(comment.Id);

            Assert.IsNotNull(idGet);
        }
コード例 #30
0
        public void TestCreateWithoutId()
        {
            var comment = CommentBuilder.New()
                          .WithId(new Guid())
                          .WithAutor(UserBuilder.New().Build())
                          .WithContent("Content")
                          .WithPublicationId(new Guid())
                          .Build();

            new CreateComment().CreateNewRegister(comment);

            Assert.True(comment.Id != Guid.Empty && comment.Id != null);
            Assert.True(comment.Autor.Id != Guid.Empty && comment.Autor.Id != null);
            Assert.True(comment.Content == "Content");
            Assert.True(comment.PublicationId == Guid.Parse("00000000-0000-0000-0000-000000000000"));
        }
コード例 #31
0
 private static void ParseCallback(XmlReader reader, CommentBuilder builder)
 {
     builder.ParseCallback(reader);
 }