Example #1
0
 public void CanAddBeek()
 {
     var beek = new BaseBeek(BeekTypes.ShortStory);
     beekRepos.AddBeek(beek);
     Assert.IsTrue(beekRepos.GetBeek().Contains(beek));
     beekRepos.RemoveBeek(beek);
 }
Example #2
0
 public void CanAddGenreExactlyOnce()
 {
     BaseBeek beek = new BaseBeek(BeekTypes.ShortStory);
     FantasyGenre fantasy = new FantasyGenre();
     beek.AddGenre(fantasy);
     Assert.IsTrue(beek.Genres.Where(g => g.Equals(fantasy)).Count() == 1);
     // Should be ignored as it is already added
     beek.AddGenre(fantasy);
     Assert.IsTrue(beek.Genres.Where(g => g.Equals(fantasy)).Count() == 1);
 }
Example #3
0
 public int AddBeek(BaseBeek beek)
 {
     lock (beekLock)
     {
         beek.Id = GetBeek().Select(b => b.Id).DefaultIfEmpty(-1).Max() + 1;
         client.Store(beek);
         client.Commit();
     }
     return beek.Id;
 }
Example #4
0
        public void CanDisinvolveUser()
        {
            BaseBeek story = new BaseBeek(BeekTypes.ShortStory);
            IUser writer = GenerateWriters().First();

            // Removing without adding first should not throw an exception
            story.DisInvolveUser(writer, Contributions.Writer);
            // Removing should remove the writer
            story.InvolveUser(writer, Contributions.Writer);
            story.DisInvolveUser(writer, Contributions.Writer);
            Assert.IsFalse(story.IsUserInvolvedAs(writer, Contributions.Writer));
            // Removing inexisting writers should not throw an exception
            story.DisInvolveUser(writer, Contributions.Writer);
            Assert.IsFalse(story.IsUserInvolvedAs(writer, Contributions.Writer));
            // Removing a user from one role, should not remove him from his other roles
            writer.AddContribution(Contributions.Illustrator);
            story.InvolveUser(writer, Contributions.Writer);
            story.InvolveUser(writer, Contributions.Illustrator);
            story.DisInvolveUser(writer, Contributions.Writer);
            Assert.IsTrue(story.IsUserInvolvedAs(writer, Contributions.Illustrator));
            Assert.IsFalse(story.IsUserInvolvedAs(writer, Contributions.Writer));
        }
Example #5
0
        public void CanAddToCollection()
        {
            BaseBeek vol1 = new BaseBeek(BeekTypes.ShortStory);
            BaseBeek vol2 = new BaseBeek(BeekTypes.ShortStory);
            BaseBeek vol3 = new BaseBeek(BeekTypes.ShortStory);
            BaseBeek vol3Bis = new BaseBeek(BeekTypes.ShortStory);
            BaseBeek vol3B = new BaseBeek(BeekTypes.ShortStory);

            BeekCollection collection = new BeekCollection();
            vol1.AddToCollection(collection, 1, null);
            vol2.AddToCollection(collection, 2, null);
            vol3.AddToCollection(collection, 3, null);
            Assert.IsTrue(collection.Count == 3);
            Assert.IsTrue(vol1.Collection == collection);
            Assert.IsTrue(vol1.VolumeNumber == 1);
            Assert.IsTrue(vol1.TotalVolumes == 3);

            vol3Bis.AddToCollection(collection, 3, null);
            Assert.IsTrue(vol1.TotalVolumes == 3);

            vol3B.AddToCollection(collection, 3, 'B');
            Assert.IsTrue(vol1.TotalVolumes == 4);
        }
Example #6
0
 public void IsRelatedWorks()
 {
     BaseBeek original = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek copy = new BaseBeek(BeekTypes.ShortStory);
     copy.RelateTo(original, BeekRelationTypes.Original);
     Assert.IsTrue(copy.IsBeekRelatedToMeAs(original, BeekRelationTypes.Original));
 }
Example #7
0
 public void IsGenreDetectsGenre()
 {
     BaseBeek beek = new BaseBeek(BeekTypes.ShortStory);
     var autoBiography = new AutoBiographyGenre();
     beek.AddGenre(autoBiography);
     Assert.IsTrue(beek.IsGenre(autoBiography));
 }
Example #8
0
 public void UpdateBeek(BaseBeek b)
 {
     lock (beekLock)
     {
         client.Store(b);
         client.Commit();
     }
 }
Example #9
0
 public void RelateTo(BaseBeek relatedBeek, BeekRelationTypes otherIsWhatOfMe)
 {
     if (relatedBeek.Equals(this))
     {
         throw new ArgumentException("Cannot relate a beek to itself", "relatedBeek");
     }
     lock (relations)
     {
         if (!IsBeekRelatedToMeAs(relatedBeek, otherIsWhatOfMe))
         {
             relations.Add(new KeyValuePair<BaseBeek, BeekRelationTypes>(relatedBeek, otherIsWhatOfMe));
         }
     }
 }
Example #10
0
        private IEnumerable<BaseBeek> ParseToBeek(XDocument doc)
        {
            foreach (XElement bookData in doc.Descendants("BookData"))
            {
                IsbnDbBeek isbnDbBeek = new IsbnDbBeek(bookData);

                BaseBeek beek = new BaseBeek(BeekTypes.LongStory)
                {
                    Title = isbnDbBeek.Title,
                    Isbn = isbnDbBeek.Isbn
                };

                if (isbnDbBeek.Authors.Any())
                {
                    //For users that don't exist yet, we'll create them..
                    accountService.CreateUsersInBatch(
                        isbnDbBeek.Authors.Where(name => !accountService.DoesUserExist(name)), Contributions.Writer, Sources.IsbnDb);

                    //now add al those users!
                    IEnumerable<UserSearchbag> bags =
                        isbnDbBeek.Authors.Select(authorName => new UserSearchbag { UserNameContains = authorName });
                    var users = accountSearchService.SearchUsers(bags);
                    Parallel.ForEach(users, user => user.AddContribution(Contributions.Writer));
                    beek.InvolveUsers(users, Contributions.Writer);
                }
                yield return beek;
            }
        }
Example #11
0
 public void CanRemoveFromCollection()
 {
     BaseBeek vol1 = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek vol2a = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek vol2b = new BaseBeek(BeekTypes.ShortStory);
     BeekCollection collection = new BeekCollection();
     vol1.AddToCollection(collection, 1, null);
     vol2a.AddToCollection(collection, 2, 'a');
     vol2b.AddToCollection(collection, 2, 'b');
     Assert.IsTrue(vol1.Collection.Contains(vol2b));
     vol2b.RemoveFromCollection();
     Assert.IsFalse(vol1.Collection.Contains(vol2b));
     Assert.IsTrue(vol2b.VolumeNumber == 0);
 }
Example #12
0
 public void CanRelateExactlyOnceToOriginalPerType()
 {
     BaseBeek original = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek copy = new BaseBeek(BeekTypes.ShortStory);
     copy.RelateTo(original, BeekRelationTypes.Original);
     Assert.IsTrue(copy.Relations.Contains(new KeyValuePair<BaseBeek, BeekRelationTypes>(original, BeekRelationTypes.Original)));
     // Second time should be ignored as there is already one
     copy.RelateTo(original, BeekRelationTypes.Original);
     Assert.IsTrue(
         copy.Relations.Where(r=>r.Key == original && r.Value == BeekRelationTypes.Original).Count()==1);
 }
Example #13
0
        public void CanInvolveUsers()
        {
            BaseBeek story = new BaseBeek(BeekTypes.ShortStory);
            List<IUser> writers = GenerateWriters().ToList();

            story.InvolveUsers(writers, Contributions.Writer);
            CollectionAssert.AreEquivalent(story.GetInvolvedUsersForContribution(Contributions.Writer).ToArray(), writers.ToArray());
            // Duplicates should be ignored
            story.InvolveUsers(writers, Contributions.Writer);
            CollectionAssert.AreEquivalent(story.GetInvolvedUsersForContribution(Contributions.Writer).ToArray(), writers.ToArray());
        }
Example #14
0
        public void CanInvolveUser()
        {
            BaseBeek story = new BaseBeek(BeekTypes.ShortStory);
            IUser writer = GenerateWriters().First();

            story.InvolveUser(writer, Contributions.Writer);

            Assert.IsTrue(story.IsUserInvolvedAs(writer, Contributions.Writer));
            // Duplicates should be ignored
            story.InvolveUser(writer, Contributions.Writer);
            Assert.IsTrue(story.Involvements.Where(i => i.Key.Equals(writer) && i.Value.Equals(Contributions.Writer)).Count() == 1);
        }
Example #15
0
 public void UpdateBeek(BaseBeek b)
 {
     throw new System.NotImplementedException();
 }
Example #16
0
 public int AddBeek(BaseBeek b)
 {
     beeks.Add(b);
     return beeks.Count();
 }
Example #17
0
 public void CanRemoveGenre()
 {
     BaseBeek beek = new BaseBeek(BeekTypes.ShortStory);
     var biography = new BiographyGenre();
     var autoBiography = new AutoBiographyGenre();
     biography.AddSubGenre(autoBiography);
     beek.AddGenre(autoBiography);
     Assert.IsTrue(beek.IsGenre(autoBiography));
     beek.RemoveGenre(autoBiography);
     Assert.IsFalse(beek.IsGenre(autoBiography));
 }
Example #18
0
 public void CantAddNonWriterToWriters()
 {
     BaseBeek story = new BaseBeek(BeekTypes.ShortStory);
     IUser notWriter = GenerateUsers().First();
     Assert.IsFalse(notWriter.IsContributingAs(Contributions.Writer));
     story.InvolveUser(notWriter, Contributions.Writer);
 }
Example #19
0
        public void CanUpdateBeek()
        {
            const string before = "before update";
            const string after = "after update";
            var beek = new BaseBeek(BeekTypes.LongStory){Title = before};
            beekRepos.AddBeek(beek);
            beek.Title = after;
            beekRepos.UpdateBeek(beek);

            Assert.IsFalse(beekRepos.GetBeek().Any(b=>(b.Title ?? string.Empty).Equals(before)));
            Assert.IsTrue(beekRepos.GetBeek().Any(b =>(b.Title ?? string.Empty).Equals(after)));
        }
Example #20
0
 public void CanUnRelate()
 {
     BaseBeek original = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek copy = new BaseBeek(BeekTypes.ShortStory);
     copy.RelateTo(original, BeekRelationTypes.Original);
     copy.RelateTo(original, BeekRelationTypes.Original);
     Assert.IsTrue(copy.IsBeekRelatedToMeAs(original, BeekRelationTypes.Original));
     copy.UnrelateTo(original, BeekRelationTypes.Original);
     Assert.IsFalse(copy.IsBeekRelatedToMeAs(original, BeekRelationTypes.Original));
 }
Example #21
0
 public bool IsBeekRelatedToMeAs(BaseBeek relatedBeek, BeekRelationTypes relationType)
 {
     return relations.Any(r => r.Key.Equals(relatedBeek) && r.Value.Equals(relationType));
 }
Example #22
0
 public void GetRelatedBeek()
 {
     BaseBeek original = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek copy = new BaseBeek(BeekTypes.ShortStory);
     BaseBeek copy2 = new BaseBeek(BeekTypes.ShortStory);
     original.RelateTo(copy, BeekRelationTypes.Republishment);
     original.RelateTo(copy2, BeekRelationTypes.Republishment);
     Assert.IsTrue(original.GetRelatedBeekForRelationType(BeekRelationTypes.Republishment).Count() == 2);
 }
Example #23
0
 public void UnrelateTo(BaseBeek relatedBeek, BeekRelationTypes relationType)
 {
     lock (relations)
     {
         relations = relations.Where(r => !(r.Key.Equals(relatedBeek) && r.Value.Equals(relationType))).ToList();
     }
 }
Example #24
0
 public void RemoveBeek(BaseBeek b)
 {
     lock (beekLock)
     {
         client.Delete(b);
         client.Commit();
     }
 }