Пример #1
0
 public void Then_dispose_browser_and_webserver_followed_by_container()
 {
     Received.InOrder(() => {
         WebDriver.Received().Close();
         WebServer.Received().Stop();
         ContainerDisposal.Received().Dispose();
     });
 }
Пример #2
0
        public void FindFunc_Spec_for_limit()
        {
            describe["given test entry tree"] = () =>
            {
                // ReSharper disable TooWideLocalVariableScope
                DirEntry de2a;
                DirEntry de2b;
                DirEntry de2c;
                DirEntry de3a = null;
                DirEntry de4a = null;
                // ReSharper restore TooWideLocalVariableScope
                RootEntry   re          = null;
                FindOptions findOptions = null;
                Func <CommonEntry, DirEntry, bool> matcherAll = null;

                before = () =>
                {
                    // NOTE: test tree entry entry  is de2c,de2a,de2b,de3a,de4a
                    re = RootEntryTestBase.NewTestRootEntry(out de2a, out de2b, out de2c, out de3a, out de4a);
                    re.SetInMemoryFields();
                    matcherAll = Substitute.For <Func <CommonEntry, DirEntry, bool> >();
                    matcherAll(null, null).ReturnsForAnyArgs(true);
                    findOptions = new FindOptions();
                };

                describe["with FindOptions matching all entries"] = () =>
                {
                    TraverseFunc visitorFunc = null;

                    before = () =>
                    {
                        visitorFunc = Substitute.For <TraverseFunc>();
                        visitorFunc(null, null).ReturnsForAnyArgs(x => true);
                        findOptions.Pattern        = string.Empty;
                        findOptions.PatternMatcher = matcherAll;
                        findOptions.VisitorFunc    = visitorFunc;
                    };

                    describe["given find limit 2"] = () =>
                    {
                        before = () =>
                        {
                            findOptions.LimitResultCount = 2;
                            findOptions.Find(new[] { re });
                        };

                        specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null);

                        specify = () => findOptions.ProgressCount.should_be(2);
                    };

                    describe["given find limit 4"] = () =>
                    {
                        before = () =>
                        {
                            findOptions.LimitResultCount = 4;
                            findOptions.Find(new[] { re });
                        };

                        specify = () => visitorFunc.ReceivedWithAnyArgs(4).Invoke(null, null);

                        specify = () => findOptions.ProgressCount.should_be(4);
                    };

                    describe["given large limit"] = () =>
                    {
                        before = () =>
                        {
                            findOptions.LimitResultCount = int.MaxValue;
                        };

                        describe["will find all"] = () =>
                        {
                            before = () => findOptions.Find(new[] { re });

                            specify = () => visitorFunc.ReceivedWithAnyArgs(5).Invoke(null, null);

                            specify = () => findOptions.ProgressCount.should_be(5);
                        };

                        describe["and given SkipCount 5"] = () =>
                        {
                            before = () =>
                            {
                                findOptions.SkipCount = 5;
                                findOptions.Find(new[] { re });
                            };

                            specify = () => visitorFunc.ReceivedWithAnyArgs(0).Invoke(null, null);

                            specify = () => findOptions.ProgressCount.should_be(5);
                        };

                        describe["and given SkipCount 6"] = () =>
                        {
                            before = () =>
                            {
                                findOptions.SkipCount = 6;
                                findOptions.Find(new[] { re });
                            };

                            specify = () => visitorFunc.ReceivedWithAnyArgs(0).Invoke(null, null);

                            specify = () => findOptions.ProgressCount.should_be(5);
                        };
                    };

                    describe["When find limit 2, pattern 'a'"] = () =>
                    {
                        before = () =>
                        {
                            findOptions.Pattern          = "a";
                            findOptions.LimitResultCount = 2;
                            findOptions.Find(new[] { re });
                        };

                        specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null);

                        specify = () => findOptions.ProgressCount.should_be(4);
                    };

                    describe["When find limit 2, pattern 'a' with Skip count 2"] = () =>
                    {
                        before = () =>
                        {
                            findOptions.LimitResultCount = 2;
                            findOptions.SkipCount        = 2;
                            findOptions.Pattern          = "a";
                            findOptions.Find(new[] { re });
                        };

                        specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null);

                        specify = () => findOptions.ProgressCount.Is(5);

                        it["found received in expected order"] =
                            () => Received.InOrder(() =>
                        {
                            visitorFunc.Received().Invoke(Arg.Any <CommonEntry>(), de3a);
                            visitorFunc.Received().Invoke(Arg.Any <CommonEntry>(), de4a);
                        });
                    };
                };
            };
            // TODO - capture SkipCount and interface and pass it back later ? [ProgressCount from findOptions]
            //        maybe this involves holding onto FindOptions on serverside in Web ?
            // TODO - if SkipCount >= Limit then dont do any work return empty.
        }