Example #1
0
			public static VerseResponse ToVerseWithoutHtml (string verse, RootObject root)
			{
				var text = root.ResponseData.Search.Result.Passages [0].Text;
				var copyright = root.ResponseData.Search.Result.Passages [0].Copyright;

				var document = new HtmlDocument ();
				document.LoadHtml (text);

				var tags = new [] { "h1", "h2", "h3", "h4", "h5", "h6" };
				List<string> toRemove = tags.ToList ();
				var list = document.DocumentNode.Descendants ()
					.Where (n => toRemove.Contains (n.Name.ToLower ()))
					.ToList ();

				foreach (var item in list) {
					item.Remove ();
				}

				text = document.DocumentNode.InnerText;

				document.LoadHtml (copyright);
				copyright = document.DocumentNode.InnerText;

				return new VerseResponse { Reference = verse, Text = text, Copyright = copyright };
			}
        public void ContainsQueriedData()
        {
            int n = 20;
            IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
                select new TestObj
                {
                    Name = i.ToString()
                };

            var db = new TestDb(new SQLitePlatformWin32(), TestPath.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new[] {"0", "10", "20"};
            List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, tens.Count);

            var moreq = new[] {"0", "x", "99", "10", "20", "234324"};
            List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more.Count);

            // https://github.com/praeclarum/SQLite.Net/issues/28
            List<string> moreq2 = moreq.ToList();
            List<TestObj> more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more2.Count);
        }
 public void ArrayTests()
 {
     int[] ints = new[] {0, 1, 2, 3};
     var intList = ints.ToList();
     var expectedResult = new List<int> {0, 1, 2, 3};
     for (int i = 0; i < expectedResult.Count; i++)
     {
         Assert.AreEqual(intList[i], expectedResult[i]);
     }
 }
        public async Task GivenTwoBlackPairsInStore_WhenGetAllPairs_ThenTwoAreReturned()
        {
            var twoPairs = new[] { new SocksPair(SocksColour.Black), new SocksPair(SocksColour.Black), };
            twoPairs.ToList().ForEach(p => Session.Save(p));
            Session.Flush();

            var pairs = (await Client.GetAsync("api/drawer/socks")).BodyAs<IEnumerable<SocksPair>>();

            pairs.Count().ShouldBe(2);
            pairs.ShouldAllBe(p => p.Colour == SocksColour.Black);
        }
        public void Can_add_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Add(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
        public void Can_attach_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { Id = 44, PostId = 56 }, new Comment { Id = 45, PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { Id = 56, BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
            }
        }
        public void sort_application_files_last()
        {
            var configs = new[]
            {
                new FubuFile("a.txt", ContentFolder.Application),
                new FubuFile("b.txt", "Pak1"),
                new FubuFile("c.txt", "Pak2")
            };

            SharingConfigActivator.SortConfigsFromApplicationLast(configs.ToList())
                .ShouldHaveTheSameElementsAs(configs[1], configs[2], configs[0]);
        }
        public void Attaching_aggregate_with_no_key_set_adds_it_instead()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
        public void Can_add_two_aggregates_linked_down_the_tree()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.AddRange(blog, author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
        public void Can_attach_aggregate_with_linked_aggregate_not_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Detached, context.Entry(author).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[1]).State);
            }
        }
        public void Dependents_with_no_key_set_are_added()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { PostId = 56 }, new Comment { PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
        public async Task GivenOneBlackAndSixWhiteSocks_WhenPostWhite_ThenFailWithForbidden()
        {
            var allPairsInStore = new[]
                {
                    new SocksPair(SocksColour.Black),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                };
            allPairsInStore.ToList().ForEach(p => Session.Save(p));
            Session.Flush();

            var response = await Client.PostJsonAsync("api/drawer", new { colour = "white" });

            response.StatusCode.ShouldBe(HttpStatusCode.Forbidden);
            response.BodyAs<string>().ShouldContain("6");
        }
Example #13
0
        private void test()
        {
            var list = new SkipList();
            var toInsert = new[] { 7, 2, 9, 1, 10 };
            foreach (var value in toInsert)
            {
                list.Insert(value);
            }

            // test whether the elements were inserted
            var listValues = list.GetElements();
            var sortedList = toInsert.ToList();
            sortedList.Sort();
            Assert.That(listValues.ToList(), Is.EquivalentTo(sortedList));

            list.PrintConfiguration();

            // test the existence of different values
            var mapExistence = new Dictionary<int, bool>
                          {
                              { 0, false },
                              { 1, true },
                              { 2, true },
                              { 3, false },
                              { 4, false },
                              { 5, false },
                              { 6, false },
                              { 7, true },
                              { 8, false },
                              { 9, true },
                              { 10, true }
                          };
            foreach (var pair in mapExistence)
            {
                Assert.AreEqual(list.Exists(pair.Key), pair.Value);
            }

            // find closest elementvar mapExistence = new Dictionary<int, bool>
            var mapClosest = new Dictionary<int, int>
                          {
                              { 0, 1 },
                              { 1, 1 },
                              { 2, 2 },
                              { 3, 2 },
                              { 4, 2 },
                              { 5, 7 },
                              { 6, 7 },
                              { 7, 7 },
                              { 8, 7 },
                              { 9, 9 },
                              { 10, 10 }
                          };
            foreach (var pair in mapClosest)
            {
                Assert.AreEqual(list.FindClosestElement(pair.Key), pair.Value);
            }

            // find k-th largest element
            var mapKth = new Dictionary<int, int?>
                          {
                              { 1, 1 },
                              { 2, 2 },
                              { 3, 7 },
                              { 4, 9 },
                              { 5, 10 }
                          };
            foreach (var pair in mapKth)
            {
                Assert.AreEqual(list.FindKLargestElement(pair.Key), pair.Value);
            }

            // count elements in range
            var rangeList = new List<dynamic>
                {
                    new
                        {
                            Left = 0,
                            Right = 11,
                            Count = 5
                        },
                    new
                        {
                            Left = 1,
                            Right = 10,
                            Count = 5
                        },
                    new
                        {
                            Left = 2,
                            Right = 10,
                            Count = 4
                        },
                    new
                        {
                            Left = 3,
                            Right = 10,
                            Count = 3
                        },
                    new
                        {
                            Left = 7,
                            Right = 10,
                            Count = 3
                        },
                    new
                        {
                            Left = 8,
                            Right = 10,
                            Count = 2
                        },
                    new
                        {
                            Left = 9,
                            Right = 10,
                            Count = 2
                        },
                    new
                        {
                            Left = 10,
                            Right = 10,
                            Count = 1
                        },
                    new
                        {
                            Left = 10,
                            Right = 11,
                            Count = 1
                        },
                    new
                        {
                            Left = 11,
                            Right = 11,
                            Count = 0
                        },
                    new
                        {
                            Left = 1,
                            Right = 9,
                            Count = 4
                        },
                    new
                        {
                            Left = 1,
                            Right = 8,
                            Count = 3
                        },
                    new
                        {
                            Left = 1,
                            Right = 7,
                            Count = 3
                        },
                    new
                        {
                            Left = 1,
                            Right = 6,
                            Count = 2
                        },
                    new
                        {
                            Left = 1,
                            Right = 2,
                            Count = 2
                        },
                    new
                        {
                            Left = 1,
                            Right = 1,
                            Count = 1
                        },
                    new
                        {
                            Left = 3,
                            Right = 7,
                            Count = 1
                        },
                    new
                        {
                            Left = 3,
                            Right = 9,
                            Count = 2
                        },
                    new
                        {
                            Left = 1,
                            Right = 6,
                            Count = 2
                        },
                    new
                        {
                            Left = 3,
                            Right = 4,
                            Count = 0
                        }
                };

            foreach (var element in rangeList)
            {
               Assert.AreEqual(list.CountElementsInRange(element.Left, element.Right), element.Count);
            }

            // remove each element from the map
            foreach (var key in mapExistence.Keys)
            {
                list.Remove(key);
                Assert.IsFalse(list.Exists(key));
            }
        }
Example #14
0
			public static string ToVerseTextWithoutHtml (RootObject root)
			{
				var text = root.ResponseData.Search.Result.Passages [0].Text;
				var document = new HtmlDocument();
				document.LoadHtml (text);

				var tags = new [] { "h1", "h2", "h3", "h4", "h5", "h6" };
				List<string> toRemove = tags.ToList ();
				var list = document.DocumentNode.Descendants ()
					.Where (n => toRemove.Contains (n.Name.ToLower ()))
					.ToList ();

				foreach (var item in list) {
					item.Remove ();
				}

				return document.DocumentNode.InnerText.Replace ("\n", " ").Replace ("\r", " ");
			}
        public void Can_add_aggregate_with_other_linked_aggregate_also_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                {
                    new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                    new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                author.Comments = comments0.Concat(comments1).ToList();
                comments0[0].Post = posts[0];
                posts[0].Blog = blog;

                context.Add(author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }