public void GivenStoredList_WhenGettingSummary_ShouldReturnList()
 {
     var service = CreateService();
     SeznamList list = new SeznamList("Id", "Test", false, string.Empty);
     SeznamList result = service.CreateList(list);
     
     var summary = service.GetSummary(list.UserId);
     Assert.That(summary, Is.Not.Null);
     Assert.That(summary.PersonalLists, Is.Not.Null);
     Assert.That(summary.PersonalLists, Is.Not.Empty);
     Assert.That(summary.PersonalLists, Contains.Item(result));
 }
        public void ShouldBeAbleToCreateNewList()
        {
            var service = CreateService();
            SeznamList list = new SeznamList("Id", "Test", false, string.Empty);
            SeznamList result = service.CreateList(list);

            using (var session = DocumentStore.OpenSession())
            {
                var user = session.Query<SeznamList>().Customize(c => c.WaitForNonStaleResultsAsOfNow()).Single();
                //var user = session.Load<SeznamList>(result.UserId);
                Assert.That(user, Is.Not.Null);
                Assert.That(user, Is.EqualTo(result));
            }

        }
 public void GivenTwoStoredLists_WhenGettingSummary_ShouldReturnBothLists()
 {
     var service = CreateService();
     var userId = "Id";
     var list1 = new SeznamList(userId, "Test", false, string.Empty);
     var list2 = new SeznamList(userId, "Test2", true, "John, Meyer, Ciber");
     using (var session = DocumentStore.OpenSession())
     {
         session.Store(list1);
         session.Store(list2);
         session.SaveChanges();
     }
     
     var summary = service.GetSummary(list1.UserId);
     Assert.That(summary, Is.Not.Null);
     Assert.That(summary.PersonalLists, 
         Is.Not.Null.
         And.Not.Empty.
         And.Contains(list1).
         And.Contains(list2));
 }
Beispiel #4
0
        public SeznamList CreateList(SeznamList list)
        {
            var created = Repository.StoreSafe(list, l => l.UserId == list.UserId && l.Name == list.Name);

            return created;
        }
Beispiel #5
0
 public bool Equals(SeznamList other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Id, Id) && Equals(other.Name, Name) && other.Items.SequenceEqual(Items) && other.Shared.Equals(Shared) && other.Users.SequenceEqual(Users) && Equals(other.UserId, UserId);
 }
 public ListCreatedMessage(SeznamList list)
 {
     List = list;
 }
 public SharedListCreatedMessage(SeznamList list, string userName)
 {
     List = list;
     Username = userName;
 }
        public void GivenListAlreadyExists_WhenCreatingList_ShouldThrow()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Test", false, string.Empty);
            using(var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            Assert.Throws<DataExistsException>(() => service.CreateList(list));
        }
        public void GivenListAndItemPresent_WhenDeletingItem_ShouldDeleteItem()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Name", false);
            var item = list.AddItem("item", 2);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            service.DeleteItem(list.Id, item.Name);

            using (var session = DocumentStore.OpenSession())
            {
                var l = session.Load<SeznamList>(list.Id);
                Assert.That(l.Items.Any(i => i.Name == item.Name), Is.False);
            }
        }
        public void GivenIsSharedWith_WhenGettingSummary_ShouldReturnSharedList()
        {
            var service = CreateService();
            var list = new SeznamList("User1", "Name", true, "User2");
            list.AddItem("item", 2);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            var summary = service.GetSummary("User2");

            Assert.That(summary, Is.Not.Null);
            Assert.That(summary.SharedLists, Contains.Item(list));
        }
        public void GivenOneListPresent_WhenCreatingListWithSameName_ShouldThrow()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Name", false);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            Assert.Throws<DataExistsException>(() => service.CreateList(list));
        }
        public void GivenOneListPresent_WhenCreatingList_ShouldNotThrow()
        {
            var service = CreateService();
            var list1 = new SeznamList("Id", "Name", false);
            var list2 = new SeznamList("Id2", "Name2", false);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list1);
                session.SaveChanges();
            }

            var item = service.CreateList(list2);

            using (var session = DocumentStore.OpenSession())
            {
                var l = session.Load<SeznamList>(item.Id);
                Assert.That(l, Is.EqualTo(item));
            }
        }
        public void GivenListAndItemPresent_WhenTogglingItem_ShouldToggleItem()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Name", true);
            var item = list.AddItem("Name", 0);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            var toggleData = service.TogglePersonalItem(list.Id, item.Name, true);

            Assert.That(toggleData.Item.Completed, Is.Not.EqualTo(item.Completed));
        }
        public void GivenListAndItemWithSameNamePresent_WhenCreatingListItem_ShouldThrow()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Name", true);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            service.CreateListItem(list.Id, "Test", 0);

            Assert.Throws<ListItemExistsException>(() => service.CreateListItem(list.Id, "Test", 0));
        }
        public void GivenListPresent_WhenCreatingListItem_ShouldCreateItem()
        {
            var service = CreateService();
            var list = new SeznamList("Id", "Name", true);
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(list);
                session.SaveChanges();
            }

            var item = service.CreateListItem(list.Id, "Test", 0);

            using (var session = DocumentStore.OpenSession())
            {
                var l = session.Load<SeznamList>(list.Id);
                Assert.That(l, Is.Not.Null);
                Assert.That(l.Items, Is.Not.Null.And.Not.Empty);
            }
        }