Example #1
0
        public void DoesntInsertsNewAuthorNewRatingWhenHeDeletedHimself()
        {
            var ratings      = new List <Rating>();
            var organization = "organization";
            var repository   = "repository";
            var author       = new FakeAuthor(organization, repository, "author");
            var formula      = new FakeFormula(10, 1);
            var deletion     = new DefaultDeletion("AUTHOR", 2);

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

            Assert.Empty(ratings);
        }
Example #2
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()
                );
        }
Example #3
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()
                );
        }
Example #4
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()
                );
        }