Esempio n. 1
0
        public void ReadXml_From_DataSet_File_Loads_Tables()
        {
            //expectations
            _mockDbCommandBuilder.BuildCommands(_mockSchemaFileStream);
            DataSet dummyDS = new DataSet();

            dummyDS.ReadXmlSchema(ReadOnlyStreamFromFilename(GetXmlSchemaFilename()));
            SetupResult.For(_mockDbCommandBuilder.GetSchema()).Return(dummyDS);
            _mocker.ReplayAll();

            _nDbUnitTestStub.ReadXmlSchema(GetXmlSchemaFilename());
            _nDbUnitTestStub.ReadXml(GetXmlFilename());
            DataSet copyOfDataSet = _nDbUnitTestStub.TestDataSet;

            IList <string> schemaTables = new List <string>();

            foreach (DataTable dataTable in copyOfDataSet.Tables)
            {
                schemaTables.Add(dataTable.TableName);

                Console.WriteLine(String.Format("Table '{0}' found in dataset", dataTable.TableName));
            }

            Assert.AreEqual(EXPECTED_COUNT_OF_COMMANDS, copyOfDataSet.Tables.Count, string.Format("Should be {0} Tables in dataset", EXPECTED_COUNT_OF_COMMANDS));
            Assert.That(ExpectedDataSetTableNames, AssertIs.EquivalentTo(schemaTables));
        }
        public void ShouldNotThrowIfElementBecomesStale()
        {
            Mock <IAllDriver> driver = new Mock <IAllDriver>();

            Mock <IAllElement> elem1 = new Mock <IAllElement>();
            Mock <IAllElement> elem2 = new Mock <IAllElement>();
            Mock <IAllElement> elem3 = new Mock <IAllElement>();
            Mock <IAllElement> elem4 = new Mock <IAllElement>();
            var elems12 = new List <IWebElement>()
            {
                elem1.Object, elem2.Object
            }.AsReadOnly();
            var elems34 = new List <IWebElement>()
            {
                elem3.Object, elem4.Object
            }.AsReadOnly();

            driver.Setup(_ => _.FindElements(by.Mechanism, by.Criteria)).Returns(elems12);
            elem1.Setup(_ => _.FindElements(by2)).Throws(new StaleElementReferenceException());
            elem2.Setup(_ => _.FindElements(by2)).Returns(elems34);

            ByChained byChained = new ByChained(by, by2);

            Assert.That(byChained.FindElements(driver.Object), Is.EquivalentTo(elems34));
            driver.Verify(_ => _.FindElements(by.Mechanism, by.Criteria), Times.Once);
            elem1.Verify(_ => _.FindElements(by2), Times.Once);
            elem2.Verify(_ => _.FindElements(by2), Times.Once);
        }
        public void TestNameValueCollection()
        {
            var target = new NameValueCollection();

            target.Add(String.Empty, "Empty-1");
            target.Add(String.Empty, "Empty-2");
            target.Add("1", "1-1");
            target.Add("1", "1-2");
            target.Add("1", "1-3");
            target.Add("null", null);               // This value will not be packed.
            target.Add("Empty", String.Empty);
            target.Add("2", "2");
            var serializer = this.CreateTarget <NameValueCollection>(this.GetSerializationContext());

            using (var stream = new MemoryStream())
            {
                serializer.Pack(stream, target);
                stream.Position = 0;
                NameValueCollection result = serializer.Unpack(stream);
                Assert.That(result.GetValues(String.Empty), Is.EquivalentTo(new[] { "Empty-1", "Empty-2" }));
                Assert.That(result.GetValues("1"), Is.EquivalentTo(new[] { "1-1", "1-2", "1-3" }));
                Assert.That(result.GetValues("null"), Is.Null);
                Assert.That(result.GetValues("Empty"), Is.EquivalentTo(new string[] { String.Empty }));
                Assert.That(result.GetValues("2"), Is.EquivalentTo(new string[] { "2" }));
                // null only value is not packed.
                Assert.That(result.Count, Is.EqualTo(target.Count - 1));
            }
        }
Esempio n. 4
0
        public static bool ShouldEqual(this AuthenticatedUser actual, AuthenticatedUser expected)
        {
            Assert.That(actual.UserName, Is.EqualTo(expected.UserName));
            Assert.That(actual.AuthenticationProviders, Is.EquivalentTo(expected.AuthenticationProviders)
                        .Using((IEqualityComparer <AuthenticationProvider>) new ValueEqualityComparer()));

            return(true);
        }
Esempio n. 5
0
        public void StepExclusive(float min, float max, int stepCount, params float[] expectedResults)
        {
            var steps = Bloop.StepExclusive(min, max, stepCount);

            AssertAll.Of(
                () => Assert.That(steps, Is.EqualTo(expectedResults)),
                () => Assert.That(steps, Is.EquivalentTo(expectedResults))
                );
        }
Esempio n. 6
0
        public void EquivalencyWithMismatchedOrder()
        {
            var backwardsWeekend = new EnumSet <DayOfWeek>(DayOfWeek.Sunday, DayOfWeek.Saturday);

            AssertAll.Of(
                backwardsWeekend,
                Is.Not.EqualTo(GetWeekend()),
                Is.EquivalentTo(GetWeekend())
                );
        }
Esempio n. 7
0
        public void OfAllValues_WithDuplicates()
        {
            var values         = Enum.GetValues(typeof(EnumWithDuplicates));
            var distinctValues = values.Cast <EnumWithDuplicates>().Distinct();

            var ofAllValues = EnumSet.OfAllValues <EnumWithDuplicates>();

            AssertAll.Of(
                ofAllValues,
                Has.Count.EqualTo(3),
                Is.EquivalentTo(distinctValues),
                Is.Not.EqualTo(values)
                );
        }
        public void TestIDictionaryValueType_Success()
        {
            var serializer = this.CreateTarget <DictionaryValueType <int, int> >(GetSerializationContext());

            using (var stream = new MemoryStream())
            {
                var value = new DictionaryValueType <int, int>(3)
                {
                    { 1, 1 }, { 2, 2 }, { 3, 3 }
                };
                serializer.Pack(stream, value);
                stream.Position = 0;
                var result = serializer.Unpack(stream);
                Assert.That(result.ToArray(), Is.EquivalentTo(Enumerable.Range(1, 3).Select(i => new KeyValuePair <int, int>(i, i)).ToArray()));
            }
        }
Esempio n. 9
0
        public void ParseTokensTests()
        {
            var @is = new Is();
            new[]
                {
                    TestData.Create("  ", new Token[0]),
                    TestData.Create("'Hello'", new Token[] {new StringLiteralToken("Hello")}),
                    TestData.Create("\"Hello\"", new Token[] {new StringLiteralToken("Hello")}),

                    TestData.Create("15", new Token[] {new NumberLiteralToken(15)}),
                    TestData.Create("1.4", new Token[] {new NumberLiteralToken(1.4)}),

                    TestData.Create("select", new Token[] {new KeywordToken(Keyword.Select)}),
                    TestData.Create("SELECT", new Token[] {new KeywordToken(Keyword.Select)}),
                    TestData.Create("select from", new Token[] {new KeywordToken(Keyword.Select), new KeywordToken(Keyword.From)}),

                    TestData.Create("hello", new Token[] {new IdentifierToken("hello")}),
                    TestData.Create("a1", new Token[] {new IdentifierToken("a1")}),
                    TestData.Create("_a", new Token[] {new IdentifierToken("_a")}),
                }.AssertDataDrivenTest(
                    s => new QueryTokenizer().ParseTokens(s),
                    _ => Is.Not.Null,
                    expected => @is.EquivalentTo(expected, new TokenComparer()));
        }
Esempio n. 10
0
 /// <summary>
 /// Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.
 /// </summary>
 /// <param name="expected">The first IEnumerable of objects to be considered</param>
 /// <param name="actual">The second IEnumerable of objects to be considered</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public static void AreEquivalent(IEnumerable expected, IEnumerable actual, string message, params object[] args)
 {
     Assert.That(actual, Is.EquivalentTo(expected), message, args);
 }