public void Selects_ok()
        {
            var input  = new[] { "1", "2", "3" };
            var output = GenericCollectionUtils.Select(input, x => Int32.Parse(x));

            Assert.AreElementsEqual(new[] { 1, 2, 3 }, output);
        }
Beispiel #2
0
        public void GetItemsDelegatesToTheStrategy()
        {
            MergedDataSet dataSet = new MergedDataSet();

            IDataSet provider = Mocks.Stub <IDataSet>();

            dataSet.AddDataSet(provider);

            IMergeStrategy strategy = Mocks.StrictMock <IMergeStrategy>();

            dataSet.Strategy = strategy;

            IEnumerable <IDataItem> results = Mocks.Stub <IEnumerable <IDataItem> >();

            DataBinding[] bindings = new DataBinding[0];

            using (Mocks.Record())
            {
                Expect.Call(strategy.Merge(null, null, false)).IgnoreArguments().Do((MergeDelegate) delegate(IList <IDataProvider> mergeProviders, ICollection <DataBinding> mergeBindings,
                                                                                                             bool includeDynamicItems)
                {
                    Assert.IsTrue(includeDynamicItems);

                    Assert.AreElementsEqual(new IDataProvider[] { provider }, mergeProviders);
                    Assert.AreSame(bindings, mergeBindings);
                    return(results);
                });
            }

            using (Mocks.Playback())
            {
                Assert.AreSame(results, dataSet.GetItems(bindings, true));
            }
        }
Beispiel #3
0
        public void RulesConstructor_WhenSuccessful_InitializesProperties()
        {
            var filterRules = new[] { new FilterRule <object>(FilterRuleType.Exclusion, new AnyFilter <object>()), new FilterRule <object>(FilterRuleType.Inclusion, new NoneFilter <object>()) };
            var filterSet   = new FilterSet <object>(filterRules);

            Assert.AreElementsEqual(filterRules, filterSet.Rules);
        }
        public void GenerateSequence(string testMethod, decimal[] expectedOutput)
        {
            var run = Runner.GetPrimaryTestStepRun(CodeReference.CreateFromMember(typeof(SequentiaNumbersSample).GetMethod(testMethod)));

            string[] lines = run.Children.Select(x => x.TestLog.GetStream(MarkupStreamNames.Default).ToString()).ToArray();
            Assert.AreElementsEqual(expectedOutput, lines.Select(x => Decimal.Parse(Regex.Match(x, @"\[(?<value>-?(\d*\.)?\d+)\]").Groups["value"].Value)));
        }
        public void CanConvertVectorToArray()
        {
            var vector = CreateVector(Data);
            var array  = vector.ToArray();

            Assert.AreElementsEqual(vector, array);
        }
        public void Messages_sent_while_link_is_down_should_be_received_later()
        {
            Start(Consumer);

            if (!consumerReady.WaitOne(5000))
            {
                Assert.Fail("Consumer did not start in time");
            }

            Start(Publisher);

            for (var i = 0; i < 10; i++)
            {
                Publish(i);

                if (i == 5)
                {
                    StopFederationProxy();
                    Thread.Sleep(100); // without this sleep at times the test fails because of message 6 not being received
                }
            }

            Thread.Sleep(2000);

            StartFederationProxy();

            Thread.Sleep(5000); // leave some time to plugin to redeliver messages

            SpinWait.SpinUntil(() => result.Count == 10, 2000);

            Publish(-1);

            Assert.AreElementsEqual(Enumerable.Range(0, 10), result);
        }
Beispiel #7
0
        public void Nack_with_requeue()
        {
            numberOfExpectedMessages = 11;

            ulong toRedeliverSince = 0;

            onReceived = (model, deliveryTag) =>
            {
                if (received.Count == 1)
                {
                    toRedeliverSince = deliveryTag;
                }

                if (received.Count == 10)
                {
                    model.BasicNack(toRedeliverSince, false, true);
                }
            };

            Start(() => Consumer(false));

            Thread.Sleep(100);

            Start(Producer);

            SpinWait.SpinUntil(ReceivedAllMessages, 2000);

            Assert.AreElementsEqual(expectedMessages.Concat(new[] { 0 }), received);
        }
        public void When_consumer_model_is_closed_unexpectedly_it_should_be_restored_and_receive_all_messages_in_sequence()
        {
            for (int i = 0; i < 100; i++)
            {
                Bus.Publish(new MyMessage {
                    Value = i
                });
            }

            Assert.IsTrue(consumer.WaitForDelivery(2 * ConsumerDelayMs * 10, 90));

            Bus.Consumer.Model.Close();

            consumer.WaitForDelivery(2 * ConsumerDelayMs * 90, 50);

            for (int i = 100; i < 150; i++)
            {
                Bus.Publish(new MyMessage {
                    Value = i
                });
            }

            consumer.WaitForDelivery(2 * ConsumerDelayMs * 50);

            Assert.AreElementsEqual(Enumerable.Range(0, 150), consumer.Received.Select(r => r.Value));
        }
Beispiel #9
0
 private void Then_contact_book_does_not_contain_removed_contact_any_more(ScenarioContext ctx)
 {
     Assert.AreElementsEqual(
         Enumerable.Empty <Contact>(),
         ctx.ContactBook.Contacts.Where(c => ctx.RemovedContacts.Contains(c)).ToArray(),
         "Contact book should not contain removed books");
 }
Beispiel #10
0
        public void Nack_with_multiple_and_requeue_requeues_nacked_messages_in_the_order_they_were_published()
        {
            numberOfExpectedMessages = 15;

            ulong toRedeliverSince = 0;

            onReceived = (model, deliveryTag) =>
            {
                if (received.Count == 5)
                {
                    toRedeliverSince = deliveryTag;
                }

                if (received.Count == 10)
                {
                    model.BasicNack(toRedeliverSince, true, true);
                }
            };

            Start(() => Consumer(false));

            Thread.Sleep(100);

            Start(Producer);

            SpinWait.SpinUntil(ReceivedAllMessages, 2000);

            Assert.AreElementsEqual(expectedMessages.Concat(new[] { 0, 1, 2, 3, 4 }), received);
        }
Beispiel #11
0
        public void CopyToTest()
        {
            var destination = new KeyValuePair <string, int> [1];

            testObject.CopyTo(destination, 0);
            Assert.AreElementsEqual(destination, testObject);
        }
Beispiel #12
0
        public void KeyedPairs_Failure_LeftLongerThanRight()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "b" }
            },
                    new Dictionary <int, string> {
                { 2, "b" }
            },
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Expected the left and right dictionaries to have the same number of items.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left Dictionary Count", "2"),
                new AssertionFailure.LabeledValue("Right Dictionary Count", "1"),
                new AssertionFailure.LabeledValue("Left Dictionary", "[1: \"a\", 2: \"b\"]"),
                new AssertionFailure.LabeledValue("Right Dictionary", "[2: \"b\"]")
            }, failures[0].LabeledValues);

            Assert.Count(0, failures[0].InnerFailures);
        }
Beispiel #13
0
        public void KeyedPairs_Failure_AtIndex()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "b" }
            },
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "c" }
            },
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Assertion failed on two pairs with a particular key in both dictionaries.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Key", "2"),
                new AssertionFailure.LabeledValue("Left Dictionary", "[1: \"a\", 2: \"b\"]"),
                new AssertionFailure.LabeledValue("Right Dictionary", "[1: \"a\", 2: \"c\"]")
            }, failures[0].LabeledValues);

            Assert.Count(1, failures[0].InnerFailures);
        }
        public void When_client_link_goes_down_and_restores_it_should_receive_all_messages_in_sequence()
        {
            for (int i = 0; i < 100; i++)
            {
                Bus.Publish(new MyMessage {
                    Value = i
                });
            }

            Assert.IsTrue(consumer.WaitForDelivery(2 * ConsumerDelayMs * 10, 90));

            StopAlternativePortProxy();
            Thread.Sleep(100);
            StartAlternativePortProxy();

            consumer.WaitForDelivery((int)(SecondaryBus.ConnectionAttemptInterval.TotalMilliseconds + 2 * ConsumerDelayMs * 90), 50);

            for (int i = 100; i < 150; i++)
            {
                Bus.Publish(new MyMessage {
                    Value = i
                });
            }

            consumer.WaitForDelivery((int)(SecondaryBus.ConnectionAttemptInterval.TotalMilliseconds + 2 * ConsumerDelayMs * 50));

            Assert.AreElementsEqual(Enumerable.Range(0, 150), consumer.Received.Select(r => r.Value));
        }
        public void GetNavigatorChildren()
        {
            TestStepRunNode tree = BuildFakeTree();
            IEnumerable <TestStepRunNode> nodes = tree.GetNavigatorChildren();

            Assert.AreElementsEqual(new[] { "321", "323", "324", "332" }, nodes.Select(x => x.Run.Step.Id));
        }
        public void LoadTabDelimitedFile()
        {
            List <string> dataoutput = EmitDynamicToDataTableToListOfStringsVanillaTest(
                FlatFileToDataTableBuilder.BuildFromTabFile(@"..\Framework\Data\DataObjects\TestXlsData.txt"));

            Assert.AreElementsEqual(TestDataSet1, dataoutput);
        }
        public void GetSelfAndAncestorIds()
        {
            TestStepRunNode tree     = BuildFakeTree();
            var             child321 = tree.Children[2].Children[1].Children[0];

            Assert.AreElementsEqual(new[] { "Test-321", "Test-32", "Test-3", "Test-Root" }, child321.GetSelfAndAncestorIds());
        }
Beispiel #18
0
        public void ShouldCopyMetadataWhenRequested()
        {
            CopyMetadataPlugin plugin = new CopyMetadataPlugin();

            using (ImageState state = CreateImageState(true))
            {
                RequestedAction requestedAction = CallProcessFinalBitmap(plugin, state);
                Assert.AreEqual(RequestedAction.None, requestedAction);

                Assert.IsNotEmpty(state.destBitmap.PropertyIdList);
                Assert.IsNotEmpty(state.destBitmap.PropertyItems);

                // Ensure that all the properties came from the original image...
                foreach (PropertyItem prop in state.destBitmap.PropertyItems)
                {
                    PropertyItem sourceProp = state.sourceBitmap.PropertyItems.SingleOrDefault(p => p.Id == prop.Id);
                    Assert.IsNotNull(sourceProp, "destBitmap ended up with a property that sourceBitmap didn't have!");

                    Assert.AreEqual(sourceProp.Len, prop.Len);
                    Assert.AreEqual(sourceProp.Type, prop.Type);
                    Assert.AreEqual(sourceProp.Len, prop.Len);
                    Assert.AreElementsEqual(sourceProp.Value, prop.Value);
                }
            }
        }
Beispiel #19
0
        public void AddingDataSetsUpdatesTheColumnCountAndDataSetsCollection()
        {
            MergedDataSet dataSet = new MergedDataSet();

            IDataSet dataSetWithTwoColumns   = Mocks.StrictMock <IDataSet>();
            IDataSet dataSetWithThreeColumns = Mocks.StrictMock <IDataSet>();

            using (Mocks.Record())
            {
                SetupResult.For(dataSetWithTwoColumns.ColumnCount).Return(2);

                SetupResult.For(dataSetWithThreeColumns.ColumnCount).Return(3);
            }

            using (Mocks.Playback())
            {
                Assert.AreEqual(0, dataSet.ColumnCount);
                Assert.AreElementsEqual(new IDataSet[] { }, dataSet.DataSets);

                dataSet.AddDataSet(dataSetWithTwoColumns);

                Assert.AreEqual(2, dataSet.ColumnCount);
                Assert.AreElementsEqual(new IDataSet[] { dataSetWithTwoColumns }, dataSet.DataSets);

                dataSet.AddDataSet(dataSetWithThreeColumns);

                Assert.AreEqual(3, dataSet.ColumnCount);
                Assert.AreElementsEqual(new IDataSet[] { dataSetWithTwoColumns, dataSetWithThreeColumns }, dataSet.DataSets);
            }
        }
Beispiel #20
0
        public void DeserializeAllSetupDataWithPropertyBuilderAndEmptyBuildParameters()
        {
            // <NStub.CSharp.ObjectGeneration.Builders.DefaultMethodEraser><EmptyBuildParameters>
            var    expectedBuilderType   = typeof(PropertyBuilder);
            var    expectedParameterType = typeof(EmptyBuildParameters);
            var    expectedEnabled       = true;
            string buildParametersXmlId  = "BuildParameters";
            var    xml = TestDataProvider.BuildParametersMinimal(buildParametersXmlId, expectedBuilderType, expectedParameterType, expectedEnabled);

            Expect.Call(handler.Type).Return(expectedBuilderType).Repeat.Any();
            Expect.Call(handler.IsMultiBuilder).Return(false).Repeat.Any();
            //Expect.Call(handler.ParameterDataType).Return(typeof(string)).Repeat.Any();
            Expect.Call(handler.ParameterDataType).Return(expectedParameterType).Repeat.Any();
            mocks.ReplayAll();
            var result   = testObject.DeserializeAllSetupData(xml, properties, new[] { handler });
            var expected = new EmptyBuildParameters();

            expected.Enabled = expectedEnabled;
            //Assert.AreElementsEqual(new[] { expected }, result,
            //  (x, y) => x.Enabled == y.Enabled && x.GetType() == y.GetType());
            Assert.AreElementsEqual(new[] { expected }, result);

            Assert.AreEqual(1, properties.EntryCount);

            // ensure there is a global entry for the PropertyBuilder containing an EmptyBuildParameters instance.
            Assert.Contains(properties.General, new KeyValuePair <string, IBuilderData>(expectedBuilderType.FullName, expected));

            mocks.VerifyAll();
        }
Beispiel #21
0
        private Test CreateCopyToTest()
        {
            return(new TestCase("CopyTo", () =>
            {
                AssertDistinctIntancesNotEmpty();
                var collection = GetSafeDefaultInstance();
                var handler = new CollectionHandler <TCollection, TItem>(collection, Context);
                var initialContent = new ReadOnlyCollection <TItem>(new List <TItem>(collection));

                foreach (var item in DistinctInstances)
                {
                    if (!IsReadOnly && !initialContent.Contains(item))
                    {
                        handler.AddSingleItemOk(item);
                    }
                }

                const int extension = 5;
                int count = collection.Count;
                var target = new TItem[count + extension];
                AssertCopyToThrowException(() => collection.CopyTo(null, 0), "when called with a null argument.", "Argument Name", "array");
                AssertCopyToThrowException(() => collection.CopyTo(target, -1), "when called with a negative index.", "Argument Name", "arrayIndex");

                for (int i = 0; i <= extension; i++)
                {
                    AssertCopyToNotThrowException(() => collection.CopyTo(target, i), "Expected the method to not throw an exception.");
                    var clone = new TItem[count];
                    Array.Copy(target, i, clone, 0, count);
                    Assert.AreElementsEqual(collection, clone);
                }

                AssertCopyToThrowException(() => collection.CopyTo(target, extension + 1), "when called with a too large array index.", "Argument Name", "arrayIndex");
            }));
        }
Beispiel #22
0
        public void ByteArrayContruction(byte[] hashBytes)
        {
            var hash      = new Hash256(hashBytes);
            var roundTrip = hash.Bytes;

            Assert.AreElementsEqual(hashBytes, roundTrip);
        }
Beispiel #23
0
        public void DefaultConstruction()
        {
            var hash = new Hash256();

            Assert.AreEqual(Hash256.Empty, hash);
            Assert.AreElementsEqual(Hash256.Empty.Bytes, hash.Bytes);
        }
        public void Using_the_same_seed_should_generate_the_same_sequence_from_regex()
        {
            var sequence1 = GetActualValues("RandomRegexWithSeed1");
            var sequence2 = GetActualValues("RandomRegexWithSeed2");

            Assert.AreElementsEqual(sequence1, sequence2);
        }
        public void TransitiveConversion()
        {
            int[]    sourceValue = new int[] { 1, 2, 3 };
            string[] targetValue = (string[])Converter.Convert(sourceValue, typeof(string[]));

            Assert.AreElementsEqual(new string[] { "1", "2", "3" }, targetValue);
        }
Beispiel #26
0
        public void Should_generate_sequential_numbers_for_same_message_type()
        {
            var expectedSequence = new[] { 1u, 2u, 3u };

            var result = expectedSequence.Select(i => sut.Next(typeof(MyMessage)));

            Assert.AreElementsEqual(expectedSequence, result);
        }
        public void TryDecodeWithCheck([Bind(2)] byte[] expected, [Bind(0)] string encoded)
        {
            byte[] plaintext;
            var    success = Base58Convert.DecodeWithCheck(encoded, out plaintext);

            Assert.IsTrue(success);
            Assert.AreElementsEqual(expected, plaintext);
        }
        public void CanConvertArrayToSparseVector()
        {
            var array  = new[] { 0.0, 1.0, 2.0, 3.0, 4.0 };
            var vector = new SparseVector(array);

            Assert.IsInstanceOfType(typeof(SparseVector), vector);
            Assert.AreElementsEqual(array, array);
        }
        public void CanConvertSparseVectorToArray()
        {
            var vector = new SparseVector(Data);
            var array  = vector.ToArray();

            Assert.IsInstanceOfType(typeof(double[]), array);
            Assert.AreElementsEqual(vector, array);
        }
        public void AssertEquality(object other)
        {
            Assert.IsNotNull(other);
            Assert.IsInstanceOfType <IDictionaryProperty>(other);
            IDictionaryProperty target = other as IDictionaryProperty;

            Assert.AreElementsEqual(this.Value, target.Value);
        }