예제 #1
0
        public async Task Can_report_progress_when_downloading_async()
        {
            var hold = AsyncServiceClient.BufferSize;
            AsyncServiceClient.BufferSize = 100;

            try
            {
                var asyncClient = new JsonServiceClient(ListeningOn);

                var progress = new List<string>();

                //Note: total = -1 when 'Transfer-Encoding: chunked'
                //Available in ASP.NET or in HttpListener when downloading responses with known lengths: 
                //E.g: Strings, Files, etc.
                asyncClient.OnDownloadProgress = (done, total) =>
                    progress.Add("{0}/{1} bytes downloaded".Fmt(done, total));

                var response = await asyncClient.GetAsync(new TestProgress());

                progress.Each(x => x.Print());

                Assert.That(response.Length, Is.GreaterThan(0));
                Assert.That(progress.Count, Is.GreaterThan(0));
                Assert.That(progress.First(), Is.EqualTo("100/1160 bytes downloaded"));
                Assert.That(progress.Last(), Is.EqualTo("1160/1160 bytes downloaded"));
            }
            finally
            {
                AsyncServiceClient.BufferSize = hold;
            }
        }         
예제 #2
0
        public BasicTester()
        {
            _hostRoot = Path.Combine(Directory.GetCurrentDirectory(), "Templates");
            _pak1 = Path.Combine(_hostRoot, "Pak1");
            _pak2 = Path.Combine(_hostRoot, "Pak2");

            _hostHomeView = new Template(Path.Combine(_hostRoot, "Home", "Home.spark"), _hostRoot, TemplateConstants.HostOrigin);
            _hostApplicationView = new Template(Path.Combine(_hostRoot, "Shared", "application.spark"), _hostRoot, TemplateConstants.HostOrigin);
            _hostFooterPartialView = new Template(Path.Combine(_hostRoot, "Shared", "_footer.spark"), _hostRoot, TemplateConstants.HostOrigin);

            _pak1HomeView = new Template(Path.Combine(_pak1, "Home", "Home.spark"), _hostRoot, "Pak1");
            _pak1NamePartialView = new Template(Path.Combine(_pak1, "Home", "_name.spark"), _hostRoot, "Pak1");

            _pak2HomeView = new Template(Path.Combine(_pak2, "Home", "Home.spark"), _hostRoot, "Pak2");
            _pak2ApplicationView = new Template(Path.Combine(_pak2, "Shared", "application.spark"), _hostRoot, "Pak2");
            _pak2ThemeView = new Template(Path.Combine(_pak2, "Shared", "theme.spark"), _hostRoot, "Pak2");

            var templates = new List<ITemplate>
            {
                _hostHomeView, _hostApplicationView, _hostFooterPartialView,
                _pak1HomeView, _pak1NamePartialView,
                _pak2HomeView, _pak2ApplicationView, _pak2ThemeView
            };

            var viewPathPolicy = new ViewPathPolicy<ITemplate>();
            templates.Each(viewPathPolicy.Apply);

            _viewFolder = new TemplateViewFolder(new TemplateRegistry<ITemplate>(templates));
        }
예제 #3
0
        public void Method_Scenario_Result()
        {
            var list = new List<string> {"Simon", "Andrew"};
            list.SortSelf().Each(Console.WriteLine);

            list.Each(Console.WriteLine);
        }
 public void invoke_action_on_each_enumerable_value()
 {
     IList<int> list = new List<int>{42,42};
     var result = new int[2];
     list.Each((item, index) => result[index] = item * index);
     result[0].ShouldEqual(0);
     result[1].ShouldEqual(42);
 }
예제 #5
0
        public void can_perform_action_on_each()
        {
            var assembly = System.Reflection.Assembly.GetAssembly(typeof (EnumerableSpecs));
            assembly.GetTypes().Each(t=>t.GetFields().Each(Console.WriteLine));

            var myString = String.Empty;
            "abcd".Each(a=>myString+=a);
            myString.ShouldEqual("abcd");
            var ints = new List<int> {1, 2, 3};
            ints.Each(Console.WriteLine);
        }
        private void verifyRoutes(BehaviorGraph graph)
        {
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 //"posts/sub/route", <-- I can't see how this route would ever have worked looking at the structure??
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes.Each(route => graph.Routes.ShouldContain(r => r.Pattern.Equals(route)));
        }
예제 #7
0
        public void ToCapitalCase()
        {
            var titlePairs = new List<Pair<string, string>>
            { // example words taken from Ruby on Rails inflector.rb
                new Pair<string, string> { First = "man from the boondocks", Second = "Man from the boondocks" },
                new Pair<string, string> { First = "x-men: the last stand", Second = "X-men: the last stand" }
            };

            titlePairs.Each(pair =>
            {
                Log.Info("{0} -> {1} = {2}?", pair.First, pair.First.ToCapitalCase(), pair.Second);
                Assert.That(pair.First.ToCapitalCase(), Is.EqualTo(pair.Second));
            });
        }
예제 #8
0
        private void verifyRoutes(BehaviorGraph graph)
        {
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes
                .Each(route => graph
                                   .Routes
                                   .ShouldContain(r => r.Pattern.Equals(route)));
        }
        public void should_include_handlers()
        {
            var graph = new FubuRegistry(x => x.ApplyHandlerConventions(typeof (Handlers.HandlersMarker))).BuildGraph();
            var routes = new List<string>
                             {
                                 "posts/create",
                                 "posts/complex-route",
                                 "some-crazy-url/as-a-subfolder",
                                 "posts/{Year}/{Month}/{Title}"
                             };

            routes
                .Each(route => graph
                                   .Routes
                                   .ShouldContain(r => r.Pattern.Equals(route)));
        }
        public void Can_hijack_all_Insert_Apis()
        {
            //Most INSERT Statements return void. To check each Insert uses the results filter (i.e. instead of the db)
            //we count the number of sql statements generated instead.

            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
            })
            {
                int i = 0;

                i++; db.Insert(new Person { Id = 7, FirstName = "Amy", LastName = "Winehouse", Age = 27 });
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));


                i++; db.InsertAll(new[] { new Person { Id = 10, FirstName = "Biggie", LastName = "Smalls", Age = 24 } });
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => ev.Insert(p => new { p.FirstName, p.Age }));
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i++; db.InsertOnly(new PersonWithAutoId { FirstName = "Amy", Age = 27 }, ev => db.From<PersonWithAutoId>().Insert(p => new { p.FirstName, p.Age }));
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());

            }
        }
        public void Can_trace_all_generated_sql()
        {
            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
                ResultsFn = (dbCmd, type) => new[] { new Person { Id = 1, FirstName = "Mocked", LastName = "Person", Age = 100 } },
                SingleResultFn = (dbCmd, type) => new Person { Id = 1, FirstName = "MockedSingle", LastName = "Person", Age = 100 },
                ScalarResultFn = (dbCmd, type) => 1000,
            })
            {
                Assert.That(db.Select<Person>(x => x.Age > 40)[0].FirstName, Is.EqualTo("Mocked"));

                Assert.That(db.Single<Person>(x => x.Age == 42).FirstName, Is.EqualTo("MockedSingle"));

                Assert.That(db.Scalar<Person, int>(x => Sql.Max(x.Age)), Is.EqualTo(1000));
                
                Assert.That(sqlStatements.Count, Is.EqualTo(3));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(3));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());
            }
        }
        public void Can_hijack_References_Apis()
        {
            var customer = new Customer
            {
                Id = 1,
                Name = "Customer 1",
                PrimaryAddress = new CustomerAddress
                {
                    AddressLine1 = "1 Humpty Street",
                    City = "Humpty Doo",
                    State = "Northern Territory",
                    Country = "Australia"
                },
                Orders = new[] { 
                    new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
                    new Order { LineItem = "Line 2", Qty = 2, Cost = 2.99m },
                }.ToList(),
            };

            var sqlStatements = new List<string>();
            using (new ResultsFilter
                {
                    SqlFilter = sql => sqlStatements.Add(sql),
                    SingleResult = customer,
                    RefSingleResultFn = (dbCmd, refType) => customer.PrimaryAddress,
                    RefResultsFn = (dbCmd, refType) => customer.Orders,
                })
            {
                int i = 0;

                i += 2; db.Save(customer);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 1; db.SaveReferences(customer, customer.PrimaryAddress);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 2; db.SaveReferences(customer, customer.Orders);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                i += 3; var dbCustomer = db.LoadSingleById<Customer>(customer.Id);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
            }
        }
        public void Should_render_the_view_and_have_valid_data_when_Valid_Slug_is_passed_in()
        {
            var testSlug = "My-Test-Slug";
            var id = Guid.NewGuid();
            var title = "My BlogPost Title";
            var bodyShort = "Body Short Text";
            var body = "This is the main body of a blogpost";
            var published = DateTime.Today;
            var modelTags = "help, test, sample, ";
            var objectTags = new List<Tag> {new Tag {Name = "help"}, new Tag {Name = "test"}, new Tag {Name = "sample"}};

            var post = new Post
                           {
                               ID = id,
                               Title = title,
                               BodyShort = bodyShort,
                               Body = body,
                               Published = published
                           };
            objectTags.Each(post.AddTag);

            var postList = new List<Post> { post }.AsQueryable();

            _repository.Expect(call => call.Query(new PostBySlug(testSlug))).IgnoreArguments().Return(postList);

            var outModel = _controller.Edit(new BlogPostEditViewModel { Slug = testSlug });

            outModel.ShouldBeOfType<BlogPostAddViewModel>();

            var actualResult = outModel as BlogPostAddViewModel;

            actualResult.ShouldNotBeNull();

            actualResult.Id.ShouldEqual(id.ToString());
            actualResult.Title.ShouldEqual(title);
            actualResult.BodyShort.ShouldEqual(bodyShort);
            actualResult.Body.ShouldEqual(body);
            actualResult.Published.ShouldEqual(published);
            actualResult.Tags.ShouldEqual(modelTags);
        }
예제 #14
0
        public void ToOrdinal()
        {
            var numbers = new List<Pair<int, string>>
            {
                new Pair<int, string> { First = 1, Second = "1st" },
                new Pair<int, string> { First = 2, Second = "2nd" },
                new Pair<int, string> { First = 1002, Second = "1002nd" },
                new Pair<int, string> { First = 1003, Second = "1003rd" },
                new Pair<int, string> { First = 10013, Second = "10013th" },
                new Pair<int, string> { First = 20026, Second = "20026th" }
            };

            numbers.Each(pair =>
            {
                Log.Info("{0} -> {1} = {2}?", pair.First, pair.First.ToOrdinal(), pair.Second);
                Assert.That(pair.First.ToOrdinal(), Is.EqualTo(pair.Second));
            });
        }
        public void ScanBadEscapedUnicode()
        {
            var jsonList = new List<string> { @"""\u005X""", @"""\u00X5""", @"""\u0X05""", @"""\uX005""", @"""\u500""", @"""\u05""", @"""\u5""", @"""\u""" };

            jsonList.Each(json =>
            {
                using (var lex = new JsonLexicalAnalyzer(json))
                {
                    Assert.That(JsonLexicalType.Error == lex.Scan());
                }
            });
        }
        public void Can_hijack_Save_Apis()
        {
            //Save Statements perform multiple queries. To check each Save uses the results filter (i.e. instead of the db)
            //we count the number of sql statements generated instead.

            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                SingleResult = new Person { Id = 1, FirstName = "Mocked", LastName = "Person", Age = 100 },
                SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
            })
            {
                int i = 0;

                //Force Insert by returning null for existingRow
                using (new OrmLiteResultsFilter {   
                    SqlFilter = sql => sqlStatements.Add(sql),
                    SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql))
                })
                {
                    i += 2; db.Save(new Person { Id = 11, FirstName = "Amy", LastName = "Winehouse", Age = 27 }); //1 Read + 1 Insert
                }

                i += 2; db.Save(new Person { Id = 11, FirstName = "Amy", LastName = "Winehouse", Age = 27 }); //1 Read + 1 Update
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i += 3; db.SaveAll(new[]{ new Person { Id = 14, FirstName = "Amy", LastName = "Winehouse", Age = 27 },
                                        new Person { Id = 15, FirstName = "Amy", LastName = "Winehouse", Age = 27 } }); //1 Read + 2 Update
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());
            }
        }
        public void Can_hijack_References_Apis()
        {
            var customer = new Customer
            {
                Id = 1,
                Name = "Customer 1",
                PrimaryAddress = new CustomerAddress
                {
                    AddressLine1 = "1 Humpty Street",
                    City = "Humpty Doo",
                    State = "Northern Territory",
                    Country = "Australia"
                },
                Orders = new[] { 
                    new Order { LineItem = "Line 1", Qty = 1, Cost = 1.99m },
                    new Order { LineItem = "Line 2", Qty = 2, Cost = 2.99m },
                }.ToList(),
            };

            var sqlStatements = new List<string>();
            var sqlCommandStatements = new List<SqlCommandDetails>();
            using (new OrmLiteResultsFilter
            {
                    SqlFilter = sql => sqlStatements.Add(sql),
                SqlCommandFilter = sql => sqlCommandStatements.Add(new SqlCommandDetails(sql)),
                    SingleResult = customer,
                    RefSingleResultFn = (dbCmd, refType) => customer.PrimaryAddress,
                    RefResultsFn = (dbCmd, refType) => customer.Orders,
                })
            {
                int i = 0;

                i += 2; db.Save(customer);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));

                SuppressIfOracle("This seems wrong here as the save actually goes through to the database in Oracle to get the next number from the sequence");

                i += 1; db.SaveReferences(customer, customer.PrimaryAddress);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i += 2; db.SaveReferences(customer, customer.Orders);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                i += 3; var dbCustomer = db.LoadSingleById<Customer>(customer.Id);
                Assert.That(sqlStatements.Count, Is.EqualTo(i));
                Assert.That(sqlCommandStatements.Count, Is.EqualTo(i));

                sqlStatements.Each(x => x.Print());
                sqlCommandStatements.Each(x => x.PrintDump());
            }
        }
예제 #18
0
파일: Load_Specs.cs 프로젝트: Nangal/Stact
		public void Should_perform_admirably()
		{
			var random = new Random();

			_count = 50000;

			_updateValues = Enumerable.Range(0, _count)
				.Select(x => random.Next(1, 1000))
				.Select(x => x > 960 ? 1000 : x)
				.Select(x => new UpdateValue(x, random.Next(1, 500000)/100m))
				.ToList();

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumerOf<UpdateValue>()
						.UsingInstance()
						.Of<TestInstance>()
						.DistributedBy(msg => msg.Id)
						.PersistUsingNHibernate()
						.UsingSessionProvider(m => SessionFactory.OpenSession())
						.OnChannel(m => m.UpdateValueChannel)
						.CreateNewInstanceBy(m => new TestInstance(m.Id));
				}))
			{
				var complete = new Future<int>();
				var latch = new CountdownLatch(_count, complete.Complete);

				_stopwatch = Stopwatch.StartNew();
				UpdateValue.SetReceivedCallback(x => latch.CountDown());

				_updateValues.Each(input.Send);

				complete.WaitUntilCompleted(2.Minutes()).ShouldBeTrue();

				_stopwatch.Stop();
			}
		}