Exemple #1
0
        public void Test(string original, string expected, string defaults, string overrides)
        {
            Config c    = new Config();
            var    defs = new Dictionary <string, ResizeSettings>();

            defs.Add("p", new ResizeSettings(defaults));
            var sets = new Dictionary <string, ResizeSettings>();

            sets.Add("p", new ResizeSettings(overrides));
            new Presets(defs, sets, false).Install(c);

            var e = new UrlEventArgs("/image.jpg", new ResizeSettings(original));

            c.Pipeline.FireRewritingEvents(null, null, e);
            Dictionary <string, string> expectedDict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var ex = new ResizeSettings(expected);

            foreach (string k in ex.Keys)
            {
                expectedDict[k] = ex[k];
            }
            Dictionary <string, string> dict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string k in e.QueryString.Keys)
            {
                dict[k] = e.QueryString[k];
            }

            Assert.AreElementsEqualIgnoringOrder <KeyValuePair <string, string> >(expectedDict, dict);
        }
        public void FacetQuery()
        {
            var connection = new MSolrConnection();

            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", "" },
                    { "rows", SolrQueryExecuter <TestDocumentWithUniqueKey> .ConstDefaultRows.ToString() },
                    { "facet", "true" },
                    { "facet.query", "id:1" },
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            };

            var querySerializer      = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
            var parser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            parser.parse &= x => x.Stub();
            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(parser, connection, querySerializer, facetQuerySerializer, null);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.Query(new SolrQuery(""), new QueryOptions {
                Facet = new FacetParameters {
                    Queries = new ISolrFacetQuery[] {
                        new SolrFacetQuery(new SolrQuery("id:1")),
                    },
                }
            });

            Assert.AreEqual(1, connection.get.Calls);
        }
        public void RunMultipleCulture()
        {
            var run      = Runner.GetPrimaryTestStepRun(typeof(MultipleCultureSample), "Test");
            var cultures = GetLogs(run.Children);

            Assert.AreElementsEqualIgnoringOrder(new[] { "en-US", "en-GB", "fr-FR" }, cultures, (x, y) => y.StartsWith(x));
        }
        public void RunMultipleCultureWithThreads([Column("Test1", "Test2")] string methodName) // Issue 572 (http://code.google.com/p/mb-unit/issues/detail?id=572)
        {
            var runs     = Runner.GetTestStepRuns(typeof(MultipleCultureWithThreadsSample), methodName);
            var cultures = GetLogs(runs).Where(x => Regex.IsMatch(x, @"^\w{2}-\w{2}"));

            Assert.AreElementsEqualIgnoringOrder(new[] { "en-US", "en-US", "fr-FR", "fr-FR" }, cultures, (x, y) => y.StartsWith(x));
        }
 private void Then_the_contact_book_should_contains_all_other_contacts(ScenarioContext ctx)
 {
     Assert.AreElementsEqualIgnoringOrder(
         ctx.ContactBook.Contacts.ToArray(),
         ctx.AddedContacts.Except(ctx.RemovedContacts).ToArray(),
         "All contacts that has not been explicitly removed should be still present in contact book");
 }
        /// <summary>
        /// Verify the expectations on a message type.
        /// </summary>
        /// <param name="type">The message type to assert on.</param>
        private static void TestType(Type type)
        {
            // get the fields of the type
            FieldInfo[] fields = type.GetFields();

            // all fields must be public readonly
            Assert.IsTrue(fields.All(f => f.IsPublic && f.IsInitOnly),
                          "All fields must be marked public readonly. Not conforming:  {0}",
                          fields.Where(f => !(f.IsPublic && f.IsInitOnly)).Select(f => f.Name).ToArray());

            // get the constructors of the type
            ConstructorInfo[] constructors = type.GetConstructors();

            // the type must have exactly one constructor
            Assert.Count(1, constructors, "The message type has {0} constructors and must have exactly 1", constructors.Count());
            ConstructorInfo constructor = constructors.Single();

            // get the parameters of the constructor
            ParameterInfo[] parameters = constructor.GetParameters();

            // the parameter count must be exactly as the field count
            Assert.Count(fields.Count(), parameters,
                         "The constructor parameter {0} count must be the same as the field count {1} .", parameters.Count(), fields.Count());

            // get the names of the fields
            IEnumerable <string> fieldNames = fields.Select(f => f.Name.ToLowerInvariant());

            // get the names of the constructor parameters
            IEnumerable <string> paramNames = parameters.Select(p => p.Name.ToLowerInvariant());

            // assert they are the same
            Assert.AreElementsEqualIgnoringOrder(fieldNames, paramNames);
        }
Exemple #7
0
        public void RegisteredTest()
        {
            var expected = new[] { "Backup" };
            var actual   = tr.GetRegisteredTasks();

            Assert.AreElementsEqualIgnoringOrder(expected, actual);
        }
Exemple #8
0
        public void Populates_within_constructor_ok()
        {
            var collection = new InvalidValuesClass <int>(typeof(ArgumentException), new[] { 123, 456, 789 });

            Assert.AreEqual(typeof(ArgumentException), collection.ExpectedExceptionType);
            Assert.AreElementsEqualIgnoringOrder(new[] { 123, 456, 789 }, collection);
        }
        public void QueryWithPagination()
        {
            const string qstring    = "id:123";
            const int    start      = 10;
            const int    rows       = 20;
            var          connection = new MSolrConnection();

            connection.get += (url, param) => {
                Assert.AreEqual("/select", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", qstring },
                    { "start", start.ToString() },
                    { "rows", rows.ToString() },
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            };

            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => qstring;

            var resultParser = new MSolrAbstractResponseParser <TestDocumentWithUniqueKey>();

            resultParser.parse &= x => x.Stub();

            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, null, null);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.Query(new SolrQuery(qstring), new QueryOptions {
                Start = start, Rows = rows
            });

            Assert.AreEqual(1, connection.get.Calls);
        }
 private void Then_all_contacts_should_be_available_in_the_contact_book(ScenarioContext ctx)
 {
     Assert.AreElementsEqualIgnoringOrder(
         ctx.AddedContacts,
         ctx.ContactBook.Contacts.ToArray(),
         "Contacts should be added to contact book");
 }
Exemple #11
0
        public void TestModifiySettings(string original, string expected, string defaults, string overrides)
        {
            var defs = new Dictionary <string, ResizeSettings>();

            defs.Add("p", new ResizeSettings(defaults));
            var sets = new Dictionary <string, ResizeSettings>();

            sets.Add("p", new ResizeSettings(overrides));

            ResizeSettings result = new Presets(defs, sets, false).Modify(new ResizeSettings(original));

            Dictionary <string, string> expectedDict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var ex = new ResizeSettings(expected);

            foreach (string k in ex.Keys)
            {
                expectedDict[k] = ex[k];
            }
            Dictionary <string, string> dict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string k in result.Keys)
            {
                dict[k] = result[k];
            }

            Assert.AreElementsEqualIgnoringOrder <KeyValuePair <string, string> >(expectedDict, dict);
        }
        public void EnumData(string testMethod, string[] expectedTestLogOutput)
        {
            var run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(EnumDataSample).GetMethod(testMethod)));

            Assert.AreElementsEqualIgnoringOrder(expectedTestLogOutput,
                                                 run.Children.Select(x => x.TestLog.GetStream(MarkupStreamNames.Default).ToString()),
                                                 (x, y) => y.Contains(x));
        }
Exemple #13
0
        public void RunDataDrivenTests(string fullName, string[] expectedTestLogOutput)
        {
            TestStepRun run = Runner.GetPrimaryTestStepRun(r => r.Step.FullName.EndsWith(fullName));

            Assert.AreElementsEqualIgnoringOrder(expectedTestLogOutput,
                                                 run.Children.Select(x => x.TestLog.GetStream(MarkupStreamNames.Default).ToString()),
                                                 (x, y) => y.Contains(x));
        }
        public void PopulatesWithListInitializerSyntax()
        {
            var collection = new DistinctInstanceCollection <int> {
                123, 456, 789
            };

            Assert.AreElementsEqualIgnoringOrder(new[] { 123, 456, 789 }, collection);
        }
        public void PopulatesExplicitelyTheCollection()
        {
            var collection = new DistinctInstanceCollection <int>();

            collection.Add(123);
            collection.Add(456);
            collection.Add(789);
            Assert.AreElementsEqualIgnoringOrder(new[] { 123, 456, 789 }, collection);
        }
Exemple #16
0
 protected void AssertDiff(DiffSet actual, params Diff[] expected)
 {
     Assert.AreEqual(expected.Length == 0, actual.IsEmpty);
     Assert.AreElementsEqualIgnoringOrder(expected, actual,
                                          new StructuralEqualityComparer <Diff>
     {
         x => x.Type,
         x => x.Path.ToString(),
     });
 }
        public void Test()
        {
            var run       = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(ImpersonateAttributeSample).GetMethod("Test")));
            var userNames = GetLogs(run.Children)
                            .Select(x => Regex.Match(x, @"User = \w+\\(?<UserName>\w+)"))
                            .Where(m => m.Success)
                            .Select(m => m.Groups["UserName"].Value);

            Assert.AreElementsEqualIgnoringOrder(new[] { "TestUser", "AnotherTestUser" }, userNames);
        }
Exemple #18
0
        public void Populates_explicitely_the_collection_ok()
        {
            var collection = new InvalidValuesClass <int>(typeof(ArgumentException));

            collection.Add(123);
            collection.Add(456);
            collection.Add(789);
            Assert.AreEqual(typeof(ArgumentException), collection.ExpectedExceptionType);
            Assert.AreElementsEqualIgnoringOrder(new[] { 123, 456, 789 }, collection);
        }
        public void PairwiseJoin()
        {
            var actual = DataGenerators.Join(new[] { "A", "B" }, new[] { 1, 2 }, new[] { 5.0, 9.0 }, JoinStrategy.Pairwise);

            Assert.AreElementsEqualIgnoringOrder(new[]
            {
                new Triple <string, int, double>("A", 1, 9.0),
                new Triple <string, int, double>("B", 2, 9.0),
                new Triple <string, int, double>("A", 2, 5.0),
                new Triple <string, int, double>("B", 1, 5.0),
            }, actual);
        }
        public void SequentialJoin()
        {
            var actual = DataGenerators.Join(new[] { "A", "B", "C", "D" }, new[] { 1, 2, 3, 4 }, JoinStrategy.Sequential);

            Assert.AreElementsEqualIgnoringOrder(new[]
            {
                new Pair <string, int>("A", 1),
                new Pair <string, int>("B", 2),
                new Pair <string, int>("C", 3),
                new Pair <string, int>("D", 4),
            }, actual);
        }
        public void TestSelectFrom()
        {
            var globalAsaxMethods = new AnalysisDataResolver()
                                    .Resolve(typeof(GlobalAsaxStub))
                                    .GetMethods();

            var selectedMethods = new GlobalAsaxMethodsSelectionStrategy()
                                  .SelectFrom(globalAsaxMethods, null)
                                  .ToArray();

            Assert.AreElementsEqualIgnoringOrder(globalAsaxMethods, selectedMethods);
        }
Exemple #22
0
        public void Consuming_should_be_thread_safe()
        {
            var t1 = new Thread(Publish100Messages);
            var t2 = new Thread(Consume100Messages);

            t1.Start();
            t2.Start();

            Assert.IsTrue(consumer.WaitUntilDelivery(1000));
            Assert.AreEqual(200, consumer.Received.Count);
            Assert.AreElementsEqualIgnoringOrder(Enumerable.Range(0, 200), consumer.Received.Select(r => r.Value));
        }
        public void Adds_classes_Ok()
        {
            var collection = new InvalidValuesClassCollection <int>();

            collection.Add(typeof(ArgumentOutOfRangeException), 1, 2, 3);
            collection.Add(new InvalidValuesClass <int>(typeof(ArgumentException))
            {
                4, 5, 6
            });
            collection.Add(typeof(InvalidOperationException), 7, 8, 9);
            Assert.Count(3, collection);
            Assert.AreElementsEqualIgnoringOrder(new[] { typeof(ArgumentOutOfRangeException), typeof(ArgumentException), typeof(InvalidOperationException) }, collection.Select(x => x.ExpectedExceptionType));
        }
Exemple #24
0
        public void ExecuteWithAllParameters()
        {
            var parameters = new ExtractParameters(null, "1", "text.doc");
            var conn       = new MSolrConnection();

            conn.postStream += (url, type, stream, kvs) => {
                Assert.AreEqual("/update/extract", url);
                Assert.AreEqual("application/word-document", type);

                var p = new[] {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                    KV.Create("literal.field1", "value1"),
                    KV.Create("literal.field2", "value2"),
                    KV.Create("stream.type", "application/word-document"),
                    KV.Create("commit", "true"),
                    KV.Create("uprefix", "pref"),
                    KV.Create("defaultField", "field1"),
                    KV.Create("extractOnly", "true"),
                    KV.Create("extractFormat", "text"),
                    KV.Create("capture", "html"),
                    KV.Create("captureAttr", "true"),
                    KV.Create("xpath", "body"),
                    KV.Create("lowernames", "true")
                };

                Assert.AreElementsEqualIgnoringOrder(p, kvs);
                return("");
            };

            var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc")
            {
                AutoCommit        = true,
                Capture           = "html",
                CaptureAttributes = true,
                DefaultField      = "field1",
                ExtractOnly       = true,
                ExtractFormat     = ExtractFormat.Text,
                Fields            = new[] {
                    new ExtractField("field1", "value1"),
                    new ExtractField("field2", "value2")
                },
                LowerNames = true,
                XPath      = "body",
                Prefix     = "pref",
                StreamType = "application/word-document"
            });

            cmd.Execute(conn);
            Assert.AreEqual(1, conn.postStream.Calls);
        }
 public void AreElementsEqualIgnoringOrder_fails_when_excess_or_missing_elements()
 {
     AssertionFailure[] failures = Capture(()
                                           => Assert.AreElementsEqualIgnoringOrder(new[] { 1, 2, 3, 2, 3, 1 }, new List <int> {
         4, 2, 1, 1, 4, 1, 4
     }));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected elements to be equal but possibly in a different order.", failures[0].Description);
     Assert.AreEqual("Equal Elements", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("[1, 1, 2]", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Excess Elements", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("[1, 4, 4, 4]", failures[0].LabeledValues[1].FormattedValue.ToString());
     Assert.AreEqual("Missing Elements", failures[0].LabeledValues[2].Label);
     Assert.AreEqual("[2, 3, 3]", failures[0].LabeledValues[2].FormattedValue.ToString());
 }
        public void GetSchemaCommand()
        {
            var conn = new Mocks.MSolrConnection();

            conn.get += (url, kvs) => {
                Assert.AreEqual("/admin/file", url);
                var expectedKVs = new[] { KV.Create("file", "schema.xml") };
                Assert.AreElementsEqualIgnoringOrder(expectedKVs, kvs);
                return("");
            };
            var cmd = new GetSchemaCommand();

            cmd.Execute(conn);
            Assert.AreEqual(1, conn.get.Calls);
        }
Exemple #27
0
        public void Run()
        {
            TestStepRun testRun = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(NonEquatableStubSample).GetMethod("Test")));

            Assert.AreEqual(TestOutcome.Passed, testRun.Result.Outcome);
            IList <TestStepRun> steps = testRun.Children;

            Assert.AreElementsEqualIgnoringOrder(new[]
            {
                "CustomEqualityComparer: x = 123, y = 456",
                "CustomEqualityComparer: x = 123, y = 123",
                "CustomEqualityComparer: x = 456, y = 123"
            }, steps.Select(x => x.TestLog.ToString()),
                                                 (x, y) => y.Contains(x));
        }
Exemple #28
0
        public void ResetTest()
        {
            tr.Reset();
            var initRegged = tr.GetRegisteredTasks();
            var task       = new TestTask();

            tr.Register(task);
            var newRegged = tr.GetRegisteredTasks();

            Assert.AreElementsNotEqual(initRegged, newRegged);
            tr.Reset();
            var resetRegged = tr.GetRegisteredTasks();

            Assert.AreElementsNotEqual(resetRegged, newRegged);
            Assert.AreElementsEqualIgnoringOrder(initRegged, resetRegged);
        }
Exemple #29
0
        public void TestGetBaseAndImplementedMethods()
        {
            const string TestMethodName = "TestMethod";
            var          resolver       = new AnalysisDataResolver();

            var methods = Inheritance.GetBaseAndImplementedMethods(
                resolver.Resolve(typeof(TestInheritedClass).GetMethod(TestMethodName))
                );

            Assert.AreElementsEqualIgnoringOrder(
                methods.ToArray(), new[] {
                resolver.Resolve(typeof(TestInterface).GetMethod(TestMethodName)),
                resolver.Resolve(typeof(TestBaseClass).GetMethod(TestMethodName))
            }
                );
        }
Exemple #30
0
        public void CanStoreAndQuery()
        {
            Ambient.Data.DeleteAll();

            Ambient.Data.Store(new Item {
                Name = "A", Value = 1
            });
            Ambient.Data.Store(new Item {
                Name = "B", Value = 2
            });

            IList <Item> items = Ambient.Data.Query <Item>();

            Assert.AreElementsEqualIgnoringOrder(new[] { new Item {
                                                             Name = "A", Value = 1
                                                         }, new Item {
                                                             Name = "B", Value = 2
                                                         } }, items);
        }