public Work Insert(
            string start,
            string end,
            string?since,
            Id author,
            uint additions,
            Id rating,
            string?link,
            DateTimeOffset createdAt
            )
        {
            var work = new FakeWork(
                new DefaultId(Guid.NewGuid()),
                additions,
                Author(author),
                Rating(rating),
                start,
                end,
                since,
                createdAt,
                link
                );

            _works.Add(work);

            return(work);
        }
        public void PrintsEveryAuthorOnCallingTop()
        {
            var organization = "organization";
            var author1      = new FakeAuthor(organization, "repo", "email1");
            var author2      = new FakeAuthor(organization, "repo", "email1");
            var authors      = new List <Author> {
                author1, author2
            };
            var work  = new FakeWork(1u, author1);
            var works = new List <Work> {
                work
            };
            var rating1 = new FakeRating(100, work, author1);
            var rating2 = new FakeRating(150, work, author2);
            var ratings = new List <Rating> {
                rating1, rating2
            };
            var database = new FakeDatabase(
                new FakeDbInstance(),
                new FakeEntities(
                    new FakeWorks(ratings, works, authors),
                    new FakeRatings(ratings, works, authors),
                    new FakeAuthors(authors)
                    )
                );

            var lines = new List <string>();

            new ConsoleApplication(database, new EloFormula()).Top(new FakeOutput(lines), organization, "repo");

            var headers = 2;

            Assert.Equal(authors.Count, lines.Count - headers);
        }
 public static void Example3()
 {
     // using timed task runner with a bunch of variously typed parameters
     var timedProcess =
         new UsingParams.TimedProcess(300,
                                      p => FakeWork.LotsOfParameters(
                                          (string)p[0],
                                          (DateTime)p[1],
                                          (int)p[2]),
                                      "test",
                                      DateTime.Now,
                                      123
                                      );
     var timedProcess2 =
         new UsingGenerics.TimedProcess <LotsOfParameters>(
             300,
             p => FakeWork.LotsOfParameters(
                 p.Name,
                 p.Date,
                 p.Count),
             new LotsOfParameters()
     {
         Name  = "test",
         Date  = DateTime.Now,
         Count = 123
     }
             );
 }
Esempio n. 4
0
        public void InsertsNewAuthorNewRatingWhenDeleteManyOldVictims()
        {
            var organization = "organization";
            var repository   = "repository";
            var author       = new FakeAuthor(organization, repository, "new author");
            var victim1      = new FakeAuthor(organization, repository, "old first victim");
            var victim2      = new FakeAuthor(organization, repository, "old second victim");
            var work1        = new FakeWork(3, victim1);
            var work2        = new FakeWork(4, victim2);
            var newWork      = new FakeWork(0u, author);
            var ratings      = new List <Rating>
            {
                new FakeRating(50, work1, victim1),
                new FakeRating(40, work2, victim2)
            };
            var formula   = new FakeFormula(10, 1);
            var deletion1 = new DefaultDeletion(victim1.Email(), 2);
            var deletion2 = new DefaultDeletion(victim2.Email(), 3);


            new DefaultEntityFactory(
                new FakeEntities(
                    new List <Work> {
                work1, work2, newWork
            },
                    new List <Author>(),
                    ratings
                    ),
                formula
                )
            .InsertRatings(
                organization,
                repository,
                author.Email(),
                new[] { deletion1, deletion2 },
                newWork.Id(),
                DateTimeOffset.UtcNow
                );

            bool RatingOfAuthor(Rating r)
            {
                return(r.Author().Email().Equals(author !.Email()));
            }

            Assert.Equal(
                formula.WinnerNewRating(
                    formula.DefaultRating(),
                    new[]
            {
                new DefaultMatch(formula.DefaultRating(), deletion1.Counted()),
                new DefaultMatch(formula.DefaultRating(), deletion2.Counted())
            }
                    ),
                ratings.Single(RatingOfAuthor).Value()
                );
        }
Esempio n. 5
0
        public void InsertsOldAuthorNewRatingWhenDeleteOneNewVictim()
        {
            var organization = "organization";
            var repository   = "repository";
            var author       = new FakeAuthor(organization, repository, "old author");
            var victim       = "single new victim";
            var work         = new FakeWork(10u, author);
            var rating       = new FakeRating(1500d, work, author);
            var ratings      = new List <Rating> {
                rating
            };
            var formula  = new FakeFormula(10, 1);
            var deletion = new DefaultDeletion(victim, 2);
            var newWork  = new FakeWork(0u, author);

            new DefaultEntityFactory(
                new FakeEntities(
                    new List <Work> {
                work, newWork
            },
                    new List <Author> {
                author
            },
                    ratings
                    ),
                formula
                )
            .InsertRatings(
                organization,
                repository,
                author.Email(),
                new[] { deletion },
                newWork.Id(),
                DateTimeOffset.UtcNow
                );

            bool RatingOfAuthor(Rating r)
            {
                return(r.Author().Email().Equals(author !.Email()));
            }

            Assert.Equal(
                formula.WinnerNewRating(
                    rating.Value(),
                    new[]
            {
                new DefaultMatch(formula.DefaultRating(), deletion.Counted())
            }
                    ),
                ratings.Last(RatingOfAuthor).Value()
                );
        }
 public static void Example2()
 {
     // using timed task runner with a single typed parameter
     var timedProcess =
         new UsingParams.TimedProcess(300,
                                      p => FakeWork.SingleParameter((string)p[0]),
                                      "test"
                                      );
     var timedProcess2 =
         new UsingGenerics.TimedProcess <StringParameter>(
             300,
             p => FakeWork.SingleParameter(p.Name),
             new StringParameter()
     {
         Name = "test"
     }
             );
 }
Esempio n. 7
0
        public void InsertsOldVictimNewRating()
        {
            var organization = "organization";
            var repository   = "repository";
            var author       = new FakeAuthor(organization, repository, "new author");
            var victim       = new FakeAuthor(organization, repository, "old single victim");
            var work         = new FakeWork(3, victim);
            var newWork      = new FakeWork(0u, author);
            var ratings      = new List <Rating> {
                new FakeRating(50, work, victim)
            };
            var formula  = new FakeFormula(10, 1);
            var deletion = new DefaultDeletion(victim.Email(), 2);

            new DefaultEntityFactory(
                new FakeEntities(
                    new List <Work> {
                work, newWork
            },
                    new List <Author>(),
                    ratings
                    ),
                formula
                )
            .InsertRatings(organization, repository, author.Email(), new[] { deletion }, newWork.Id(), DateTimeOffset.UtcNow);

            bool RatingOfVictim(Rating r)
            {
                return(r.Author().Email().Equals(victim !.Email()));
            }

            Assert.Equal(
                formula.LoserNewRating(
                    formula.DefaultRating(),
                    new DefaultMatch(formula.DefaultRating(), deletion.Counted())
                    ),
                ratings.Last(RatingOfVictim).Value()
                );
        }
Esempio n. 8
0
        public void InsertsNewWorkWithUsedRating()
        {
            var organization = "organization";
            var repository   = "repository";
            var author       = new FakeAuthor(organization, repository, "the author");
            var work         = new FakeWork(10u, author);
            var rating       = new FakeRating(1500d, work, author);
            var works        = new List <Work> {
                work
            };

            new DefaultEntityFactory(
                new FakeEntities(
                    works,
                    new List <Author> {
                author
            },
                    new List <Rating> {
                rating
            }
                    ),
                new FakeFormula()
                )
            .InsertedWork(
                organization,
                repository,
                "start",
                "end",
                null,
                author.Email(),
                0u,
                null,
                DateTimeOffset.UtcNow);

            Assert.Equal(rating, works.Last().UsedRating());
        }