Exemple #1
0
        public void ToHoursTest()
        {
            var value = RandomValueEx.GetRandomInt32(1, 100);

            var expected = TimeSpan.FromHours(value);
            var actual   = value.ToHours();

            actual
            .Should()
            .Be(expected);
        }
Exemple #2
0
        public void MatchTimeoutTest()
        {
            const String emaiLpattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
            var          text         = RandomValueEx.GetRandomStrings(50000)
                                        .StringJoin();

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Action test = () => text.Match(emaiLpattern, RegexOptions.Compiled, 3.ToMilliseconds());

            Assert.Throws <RegexMatchTimeoutException>(test);
        }
        public void NotAnyTest1()
        {
            var list = new List <String>();

            Assert.True(list.NotAny(x => true));
            Assert.True(list.NotAny(x => false));

            list.Add(RandomValueEx.GetRandomString());
            Assert.False(list.NotAny(x => true));
            Assert.True(list.NotAny(x => false));
        }
        public void IsNotMatchTest2TimeoutCheck()
        {
            const String emaiLpattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
            var          validEmail   = RandomValueEx.GetRandomStrings(10000)
                                        .StringJoin(Environment.NewLine);

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Action test = () => validEmail.IsNotMatch(emaiLpattern, RegexOptions.Multiline, 3.ToMilliseconds());

            test.ShouldThrow <RegexMatchTimeoutException>();
        }
        public void TryParsInt16OverloadFormatProviderNullTest()
        {
            var         expected = RandomValueEx.GetRandomInt16();
            CultureInfo culture  = null;
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => expected.ToString(CultureInfo.InvariantCulture)
                          // ReSharper disable once UnusedVariable
                          .TryParsInt16(NumberStyles.Any, culture, out Int16 result);

            test.ShouldThrow <ArgumentNullException>();
        }
        public void SafeToInt16OverloadNullWithDefaultTest()
        {
            String value    = null;
            var    expected = RandomValueEx.GetRandomInt16();
            // ReSharper disable once ExpressionIsAlwaysNull
            var actual = value.SafeToInt16(NumberStyles.Any, CultureInfo.InvariantCulture, expected);

            actual
            .Should()
            .Be(expected);
        }
        public void SafeToInt16NullDefaultTest()
        {
            String value    = null;
            var    expected = RandomValueEx.GetRandomInt16();
            // ReSharper disable once ExpressionIsAlwaysNull
            var actual = value.SafeToInt16(expected);

            actual
            .Should()
            .Be(expected);
        }
        public void CtorTest()
        {
            var expectedName        = RandomValueEx.GetRandomString();
            var expectedDescription = RandomValueEx.GetRandomString();
            var target = new ExpressionInstanceFactory(x => "", expectedName, expectedDescription);

            target.FactoryName.Should()
            .Be(expectedName);
            target.FactoryDescription.Should()
            .Be(expectedDescription);
        }
Exemple #9
0
        public void SwapTest()
        {
            var value0 = new List <String>();
            var value1 = new List <String> {
                RandomValueEx.GetRandomString()
            };

            this.Swap(ref value0, ref value1);
            Assert.Single(value0);
            Assert.Empty(value1);
        }
        public void CtorTest()
        {
            var expectedName        = RandomValueEx.GetRandomString();
            var expectedDescription = RandomValueEx.GetRandomString();
            var target = new ExpressionMemberSelectionRule(x => true, MemberSelectionMode.Include, expectedName, expectedDescription);

            target.RuleName.Should()
            .Be(expectedName);
            target.RuleDescription.Should()
            .Be(expectedDescription);
        }
Exemple #11
0
        public void ToMillisecondsTest()
        {
            var value = RandomValueEx.GetRandomInt32( 1, 100 );

            var expected = TimeSpan.FromMilliseconds( value );
            var actual = ( (Int64) value ).ToMilliseconds();

            actual
                .Should()
                .Be( expected );
        }
Exemple #12
0
        public void ToInt16OverloadTest()
        {
            var culture = new CultureInfo("de-CH");
            var value   = RandomValueEx.GetRandomInt16();
            var actual  = value.ToString(culture)
                          .ToInt16(culture);

            actual
            .Should()
            .Be(value);
        }
Exemple #13
0
        private static void WaitForMessageTest()
        {
            var brokerUri = "tcp://" + Host + ":" + Port;
            var factory   = new ConnectionFactory(brokerUri, new StompConnectionSettings {
                UserName = User, Password = Password
            });

            // Create connection for both requests and responses
            var connection = factory.CreateConnection();

            connection.Start();

            // Create session for both requests and responses
            var session = connection.CreateSession(AcknowledgementMode.IndividualAcknowledge);

            IDestination destinationQueue = session.GetQueue(Destination);
            var          producer         = session.CreateProducer(destinationQueue);

            producer.DeliveryMode = MessageDeliveryMode.Persistent;

            IDestination sourceQueue = session.GetQueue(Destination);
            var          consumer    = session.CreateConsumer(sourceQueue);

            const Int32 messageCount = 10;

            // Receive messages
            for (var i = 0; i < messageCount; i++)
            {
                var thread = new Thread(() =>
                {
                    var msg = consumer.Receive();
                    Console.WriteLine($"Thread {Thread.CurrentThread.Name} received a message");
                    msg.Acknowledge();
                })
                {
                    Name = $"Thread {i}"
                };
                thread.Start();
            }

            // Send messages
            for (var i = 0; i < messageCount; i++)
            {
                new Thread(() =>
                {
                    var message             = session.CreateTextMessage(RandomValueEx.GetRandomString());
                    message.Headers["test"] = "test";
                    producer.Send(message);
                }).Start();
            }

            Thread.Sleep(10.ToSeconds());
            connection.Close();
        }
Exemple #14
0
        public void FTest1()
        {
            const String format = "Test: {0}, {1}";
            var          value  = RandomValueEx.GetRandomString();
            var          value1 = RandomValueEx.GetRandomString();

            var expected = $"Test: {value}, {value1}";
            var actual   = format.F(value, value1);

            Assert.Equal(expected, actual);
        }
Exemple #15
0
        public void ExecuteIfAnyTrueTest2NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => ActionEx.ExecuteIfAnyTrue(null,
                                                          RandomValueEx.GetRandomString(),
                                                          RandomValueEx.GetRandomString(),
                                                          null,
                                                          false,
                                                          true);

            Assert.Throws <ArgumentNullException>(test);
        }
        public void CtorTest()
        {
            var expected            = RandomValueEx.GetRandomEnum <MemberSelectionMode>();
            var expectedName        = RandomValueEx.GetRandomString();
            var expectedDescription = RandomValueEx.GetRandomString();
            var target = new AllMemberSelectionRule(expected, expectedName, expectedDescription);

            target.RuleName.Should()
            .Be(expectedName);
            target.RuleDescription.Should()
            .Be(expectedDescription);
        }
Exemple #17
0
        public void GetRandomDateTimeTest()
        {
            var min = DateTime.Now.Subtract(1.ToDays());

            for (var i = 0; i < 10000; i++)
            {
                var max = DateTime.Now.AddDays(i);

                var actual = RandomValueEx.GetRandomDateTime(min, max);
                Assert.True(actual >= min && actual <= max);
            }
        }
Exemple #18
0
        public void PathCombineTest()
        {
            List <String> list = null;

            Assert.False(list.AnyAndNotNull());

            list = new List <String>();
            Assert.False(list.AnyAndNotNull());

            list.Add(RandomValueEx.GetRandomString());
            Assert.True(list.AnyAndNotNull());
        }
        public void IsDefaultTest()
        {
            var value = default(String);
            // ReSharper disable once ExpressionIsAlwaysNull
            var actual = value.IsDefault();

            Assert.True(actual);

            value  = RandomValueEx.GetRandomString();
            actual = value.IsDefault();
            Assert.False(actual);
        }
        public void IsNullOrEmptyTest()
        {
            List <String> list = null;

            Assert.True(list.IsNullOrEmpty());

            list = new List <String>();
            Assert.True(list.IsNullOrEmpty());

            list.Add(RandomValueEx.GetRandomString());
            Assert.False(list.IsNullOrEmpty());
        }
        public void ManyTest()
        {
            var list = new List <String>();

            Assert.False(list.Many());

            list = RandomValueEx.GetRandomStrings(1);
            Assert.False(list.Many());

            list = RandomValueEx.GetRandomStrings(10);
            Assert.True(list.Many());
        }
        public void ExecuteIfTrueTest8NullCheck()
        {
            Action <String, String, String> trueAction = null;
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => trueAction.ExecuteIfTrue(RandomValueEx.GetRandomString(),
                                                         RandomValueEx.GetRandomString(),
                                                         RandomValueEx.GetRandomString(),
                                                         true,
                                                         true);

            test.ShouldThrow <ArgumentNullException>();
        }
        public void ExecuteIfTrueTest1()
        {
            var parameter = RandomValueEx.GetRandomString();

            // Case 1
            var trueActionExecuted  = false;
            var falseActionExecuted = false;

            ActionEx.ExecuteIfTrue(x => trueActionExecuted = x == parameter, parameter, null, true, true);

            Assert.True(trueActionExecuted);
            Assert.False(falseActionExecuted);

            // Case 2
            // ReSharper disable once HeuristicUnreachableCode
            trueActionExecuted = false;
            ActionEx.ExecuteIfTrue(x => trueActionExecuted = x == parameter,
                                   parameter,
                                   x => falseActionExecuted = x == parameter,
                                   true,
                                   true);

            Assert.True(trueActionExecuted);
            Assert.False(falseActionExecuted);

            // Case 3
            trueActionExecuted  = false;
            falseActionExecuted = false;
            ActionEx.ExecuteIfTrue(x => trueActionExecuted = x == parameter,
                                   parameter,
                                   x => falseActionExecuted = x == parameter,
                                   true,
                                   false);

            Assert.False(trueActionExecuted);
            Assert.True(falseActionExecuted);

            // Case 4
            trueActionExecuted  = false;
            falseActionExecuted = false;
            ActionEx.ExecuteIfTrue(x => trueActionExecuted = x == parameter, parameter, null, true, false);

            Assert.False(trueActionExecuted);
            Assert.False(falseActionExecuted);

            // Case 5
            trueActionExecuted  = false;
            falseActionExecuted = false;
            ActionEx.ExecuteIfTrue(x => trueActionExecuted = x == parameter, parameter, null, true, false);

            Assert.False(trueActionExecuted);
            Assert.False(falseActionExecuted);
        }
        public void ExecuteIfTrueTest2NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => ActionEx.ExecuteIfTrue(null,
                                                       RandomValueEx.GetRandomString(),
                                                       RandomValueEx.GetRandomString(),
                                                       null,
                                                       true,
                                                       true);

            test.ShouldThrow <ArgumentNullException>();
        }
        public void ExecuteIfAnyFalseTest6()
        {
            var parameter = RandomValueEx.GetRandomString();

            // Case 1
            var falseActionExecuted = false;

            ActionEx.ExecuteIfAnyFalse(
                p1 => falseActionExecuted = p1 == parameter,
                parameter,
                false,
                true);

            Assert.True(falseActionExecuted);

            // Case 2
            falseActionExecuted = false;
            ActionEx.ExecuteIfAnyFalse(
                p1 => falseActionExecuted = p1 == parameter,
                parameter,
                false,
                true);

            Assert.True(falseActionExecuted);

            // Case 3
            falseActionExecuted = false;
            ActionEx.ExecuteIfAnyFalse(
                p1 => falseActionExecuted = p1 == parameter,
                parameter,
                true,
                true);

            Assert.False(falseActionExecuted);

            // Case 4
            falseActionExecuted = false;
            ActionEx.ExecuteIfAnyFalse(
                p1 => falseActionExecuted = p1 == parameter,
                parameter,
                true,
                true);

            Assert.False(falseActionExecuted);

            // Case 5
            falseActionExecuted = false;
            Action <String> action = x => { };

            action.ExecuteIfAnyFalse(parameter, true, true);

            Assert.False(falseActionExecuted);
        }
Exemple #26
0
        public void GetAllKeysAsListTest()
        {
            var dictionary = new Dictionary <String, String>
            {
                { RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() },
                { RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() }
            };

            var allKeys = dictionary.GetAllKeysAsList();

            Assert.True(dictionary.All(x => allKeys.Contains(x.Key)));
        }
Exemple #27
0
        public void ExecuteIfAnyTrueTest6()
        {
            var parameter = RandomValueEx.GetRandomString();

            // Case 1
            var trueActionExecuted = false;

            ActionEx.ExecuteIfAnyTrue(
                p1 => trueActionExecuted = p1 == parameter,
                parameter,
                false,
                true);

            Assert.True(trueActionExecuted);

            // Case 2
            trueActionExecuted = false;
            ActionEx.ExecuteIfAnyTrue(
                p1 => trueActionExecuted = p1 == parameter,
                parameter,
                false,
                true);

            Assert.True(trueActionExecuted);

            // Case 3
            trueActionExecuted = false;
            ActionEx.ExecuteIfAnyTrue(
                p1 => trueActionExecuted = p1 == parameter,
                parameter,
                false,
                false);

            Assert.False(trueActionExecuted);

            // Case 4
            trueActionExecuted = false;
            ActionEx.ExecuteIfAnyTrue(
                p1 => trueActionExecuted = p1 == parameter,
                parameter,
                false,
                false);

            Assert.False(trueActionExecuted);

            // Case 5
            trueActionExecuted = false;
            Action <String> action = x => { };

            action.ExecuteIfAnyTrue(parameter, false, false);

            Assert.False(trueActionExecuted);
        }
Exemple #28
0
        public void CompareOrdinalIgnoreNullTest1()
        {
            String left  = null;
            var    right = RandomValueEx.GetRandomString();

            // ReSharper disable once ExpressionIsAlwaysNull
            var actual = left.CompareOrdinalIgnoreCase(right);

            actual
            .Should()
            .BeFalse();
        }
Exemple #29
0
        public void ExecuteIfAnyTrueTest8NullCheck()
        {
            Action <String, String, String> action = null;
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => action.ExecuteIfAnyTrue(RandomValueEx.GetRandomString(),
                                                        RandomValueEx.GetRandomString(),
                                                        RandomValueEx.GetRandomString(),
                                                        false,
                                                        true);

            Assert.Throws <ArgumentNullException>(test);
        }
        public void MinimumOfTest1()
        {
            var list = new List <String>();

            Assert.False(list.MinimumOf(1));
            Assert.True(list.MinimumOf(0));

            list = RandomValueEx.GetRandomStrings(10);
            Assert.True(list.MinimumOf(9));
            Assert.True(list.MinimumOf(10));
            Assert.False(list.MinimumOf(11));
        }