Ejemplo n.º 1
0
        public void ThrowIfInvalidEnum_Test()
        {
            // arrange
            var values = new List <(Expression <Func <PortState> > expression, bool shouldRaceNull, bool shouldRaceArgument)>
            {
                (null, true, false),
                (() => (PortState)10, false, true),
                (() => PortState.Open, false, false),
                (() => (PortState)1, false, false)
            };

            // act & assert
            foreach (var value in values)
            {
                if (value.shouldRaceNull)
                {
                    NAssert.Throws <ArgumentNullException>(() => CheckUtil.ThrowIfInvalidEnum(value.expression), "ArgumentNullException expected but not thrown.");
                }
                if (value.shouldRaceArgument)
                {
                    NAssert.Throws <ArgumentException>(() => CheckUtil.ThrowIfInvalidEnum(value.expression), "ArgumentException expected but not thrown.");
                }
                if (!value.shouldRaceNull && !value.shouldRaceArgument)
                {
                    NAssert.DoesNotThrow(() => CheckUtil.ThrowIfInvalidEnum(value.expression), "Unexpected exception.");
                }
            }
        }
Ejemplo n.º 2
0
        public void GetAltitudeUnit_Test()
        {
            // arrange
            var values = new List <(string locale, string result, Type exceptionType)>
            {
                ("", "", typeof(ArgumentException)),
                ("de", "", typeof(ArgumentException)),
                ("de-DE", "m", null),
                ("en-US", "ft", null),
                ("en-GB", "m", null)
            };

            // act && assert
            values.ForEach(
                v =>
            {
                if (v.exceptionType != null)
                {
                    NAssert.Throws(v.exceptionType, () => ConversionUtil.GetAltitudeUnit(v.locale), "Expected exception not thrown.");
                    return;
                }
                var result = ConversionUtil.GetAltitudeUnit(v.locale);
                Assert.AreEqual(v.result, result, "Resulting text does not match.");
            });
        }
Ejemplo n.º 3
0
        public void ThrowIfInvalidEnum_Callback_Test()
        {
            // arrange
            var values = new List <(Expression <Func <PortState> > expression, bool shouldRaceNull, bool shouldRaceArgument)>
            {
                (null, true, false),
                (() => (PortState)10, false, true),
                (() => PortState.Open, false, false),
                (() => (PortState)1, false, false)
            };
            var expectedCallbacks = values.Count(v => !v.shouldRaceNull && v.shouldRaceArgument);
            var actualCallbacks   = 0;

            // act && assert for exceptions
            foreach (var value in values)
            {
                if (value.shouldRaceNull)
                {
                    // should not race the callback
                    NAssert.Throws <ArgumentNullException>(() => CheckUtil.ThrowIfInvalidEnum(value.expression, ex => actualCallbacks++), "ArgumentNullException expected but not thrown.");
                }
                if (value.shouldRaceArgument)
                {
                    // should race the callback
                    NAssert.Throws <ArgumentException>(() => CheckUtil.ThrowIfInvalidEnum(value.expression, ex => actualCallbacks++), "ArgumentException expected but not thrown.");
                }
                if (!value.shouldRaceNull && !value.shouldRaceArgument)
                {
                    // should not race the callback
                    NAssert.DoesNotThrow(() => CheckUtil.ThrowIfInvalidEnum(value.expression, ex => actualCallbacks++), "Unexpected exception.");
                }
            }
            // assert for correct amount of callbacks called
            NAssert.AreEqual(expectedCallbacks, actualCallbacks, "Incorrect amount of callbacks was called.");
        }
Ejemplo n.º 4
0
        public void CreateParse()
        {
            var item = new SelectItem("colname as aliasname");

            Assert.AreEqual("colname", item.Field);
            Assert.AreEqual("aliasname", item.Alias);

            item = new SelectItem("colname");
            Assert.AreEqual("colname", item.Field);
            Assert.AreEqual(null, item.Alias);


            Assert.Throws <ArgumentException>(() =>
            {
                item = new SelectItem("colname aliasname");
            });

            Assert.Throws <ArgumentException>(() =>
            {
                item = new SelectItem("colname as an aliasname");
            });

            Assert.Throws <ArgumentException>(() =>
            {
                item = new SelectItem("colname = aliasname");
            });
        }
Ejemplo n.º 5
0
        public void CaseSensitivity()
        {
            IQ.Config.IgnoreCaseParameters = false;
            var sql = "select * FROM table where col = @Parm1";

            var pp = new ParameterParser(sql, "p1value");

            Assert.AreEqual(pp.Parameters[0].ParameterName, "@Parm1");
            Assert.AreEqual(pp.Parameters[0].Value, "p1value");

            Assert.Throws <ArgumentException>(() =>
            {
                pp = new ParameterParser(sql, "@parm1", 123);
            });

            Assert.Throws <ArgumentException>(() =>
            {
                pp = new ParameterParser(sql, new
                {
                    parm1 = 123
                });
            });

            IQ.Config.IgnoreCaseParameters = true;
            pp = new ParameterParser(sql, "@parm1", 123);
            Assert.AreEqual(pp.Parameters[0].ParameterName, "@Parm1");
            Assert.AreEqual(pp.Parameters[0].Value, 123);
        }
Ejemplo n.º 6
0
        public void Single()
        {
            var q = IQ.From <Dog>();

            var dog = q.Where(1).Single();

            Assert.AreEqual(dog.PK, 1);

            dog = null;
            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = q.Where("1=2").Single();
            }, "Single fails when no matches");

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = q.Where("pk<3").Single();
            }, "Single fails when 2 returned");

            Assert.AreEqual(null, dog);

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = q.Where("pk<10").Single();
            }, "Single throws when more than one is returned.");
        }
Ejemplo n.º 7
0
 public void Test_Invalid_Values()
 {
     #if NUNIT
     Assert.Throws <ArgumentOutOfRangeException>(() => GammaRelated.LogOfFactorial(-1));
     #else
     GammaRelated.LogOfFactorial(-1);
     #endif
 }
Ejemplo n.º 8
0
        public void First()
        {
            var dogList = IQ.From <Dog>("age>@age", 10).OrderBy("age");

            Assert.AreEqual(11, dogList.First().Age);

            Assert.Throws <InvalidOperationException>(() => {
                dogList   = IQ.From <Dog>("age=100");
                var first = dogList.First();
            });
        }
        public void CheckSPolynomDiv2()
        {
            SPolynom poly1 = new SPolynom(new double[] { 2, -4, 0, 4 });
            SPolynom poly2 = new SPolynom(new double[] { 4, 4, 4, 4, 22, 4, 44, 4 });

            Assert.Throws <DivideByZeroException>(
                () =>
            {
                var res = poly2 / poly1;
            });
        }
Ejemplo n.º 10
0
        public void NullValues()
        {
            ParameterParser pp = new ParameterParser("select * FROM table where col = @parm1", 1);

            Assert.AreEqual(1, pp.Parameters.Count);
            Assert.AreEqual(1, pp.Parameters[0].Value);
            // need 2 parms - null values after the first parameter are considered.
            Assert.Throws <ArgumentException>(() =>
            {
                pp = new ParameterParser("select * FROM animals where age = @parm1 and age = @parm2", 1);
            });
        }
Ejemplo n.º 11
0
        public void ExtraData()
        {
            string sql = "select * FROM table where col = @parm1, col2 = @parm2";

            Assert.Throws <ArgumentException>(() => {
                var pp = new ParameterParser(sql, new { parm2 = "p2value", parm1 = "p1value" }, null);
            });

            var pp2 = new ParameterParser(sql, new { parm2 = "p2value", parm1 = "p1value" });

            Assert.AreEqual(2, pp2.Parameters.Count);
        }
Ejemplo n.º 12
0
        public void Compound()
        {
            var baseQuery = IQ.From <Dog>();

            var dog = baseQuery.Take(5).Last();

            Assert.AreEqual(dog.PK, baseQuery.ElementAt(4).PK);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                dog = baseQuery.ElementAt(20);
            }, "Error thrown accessing nonexistent element");
        }
Ejemplo n.º 13
0
Archivo: From.cs Proyecto: vebin/IQMap
        public void CloseConnectionNeverReconnect()
        {
            var context = IQ.GetDbContext(CommandBehavior.CloseConnection, DbReconnect.NeverReconnect);

            var q = context.From <Dog>("age>2 and age<=4");

            Assert.AreEqual(2, q.Count());
            Assert.Throws <InvalidOperationException>(() =>
            {
                // connection closed
                Assert.AreEqual(2, q.Count());
            });
            context.Dispose();
        }
Ejemplo n.º 14
0
        public void LoadPk()
        {
            Cat obj = new Cat();

            Assert.Throws <InvalidOperationException>(() =>
            {
                obj.Load(99999);
            }, "Missing PK fails");

            obj.Load(2);

            Assert.AreEqual(2, obj.PK);
            Assert.AreEqual("Bulldog", obj.Breed);
        }
Ejemplo n.º 15
0
        public void LoadWhere()
        {
            Cat obj = new Cat();

            Assert.Throws <InvalidOperationException>(() =>
            {
                obj.Load("breed=@breed", "Terrier");
            }, "More than one match fails");

            obj.Load("pk=@pk", 2);

            Assert.AreEqual(2, obj.PK);
            Assert.AreEqual("Bulldog", obj.Breed);
        }
Ejemplo n.º 16
0
        public void SingleOrNew()
        {
            var q = IQ.From <Dog>();

            var dog = q.Where(1).SingleOrNew();

            Assert.AreEqual(dog.PK, 1);

            dog = q.Where("1=2").SingleOrNew();
            Assert.AreEqual(dog.PK, 0, "SingleOrNew returns a new element when no matches");

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = q.Where("pk<3").SingleOrNew();
            }, "Single fails when 2 returned");
        }
Ejemplo n.º 17
0
        public void Compound()
        {
            var baseQuery = IQ.From("select * FROM animals where pk < 10 order by PK");

            var dog = baseQuery.Take(5).Last();

            Assert.AreEqual(dog.Pk, baseQuery.ElementAt(4).Pk);

            Cat cat = baseQuery.As <Cat>().Reverse().ElementAt(2);

            Assert.AreEqual(7, cat.PK);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                cat = baseQuery.As <Cat>().ElementAt(20);
            }, "Error thrown accessing nonexistent element");
        }
Ejemplo n.º 18
0
        public void SingleOrDefault()
        {
            var context = IQ.GetDbContext();


            var dog = context.From <Dog>(1).SingleOrDefault();

            Assert.AreEqual(dog.PK, 1);

            dog = context.From <Dog>("1=2").SingleOrDefault();
            Assert.AreEqual(null, dog);

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = context.From <Dog>("pk<10").SingleOrDefault();
            }, "SingleOrDefault throws when more than one is returned.");
        }
Ejemplo n.º 19
0
Archivo: First.cs Proyecto: vebin/IQMap
        public void First()
        {
            var q = IQ.From <Dog>();

            var dog = q.OrderBy("PK").First();

            Assert.AreEqual(1, dog.PK);

            dog = q.OrderBy("PK").Where("PK<10").Reverse().First();
            Assert.AreEqual(9, dog.PK);

            dog = q.OrderBy("PK").Where("PK=3").First();
            Assert.AreEqual(3, dog.PK);

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog = q.Where("1=2").Single();
            }, "First fails when no matches");
        }
Ejemplo n.º 20
0
        public void MailMonitor_StartMonitorTask_SeenUidsManager_Write_ExceptionThrown()
        {
            var mockMailProvider    = new Mock <IMailProvider>();
            var mockMailAction      = new Mock <IMailAction>();
            var mockSeenUidsManager = new Mock <ISeenUidsManager>();

            mockMailProvider
            .Setup(x => x.GetAllMessages(ConfigEntity))
            .Returns(MailTransfer);
            mockSeenUidsManager
            .Setup(x => x.Write(It.IsAny <ConfigEntity>(), It.IsAny <List <string> >(), It.IsAny <bool>()))
            .Returns(false);

            var mailMonitor = new MailMonitor(mockMailProvider.Object, mockMailAction.Object, mockSeenUidsManager.Object);

            string message = "Ошибка при сохранении Uid прочитанных писем";
            var    ex      = Assert.Throws <ApplicationException>(() => mailMonitor.StartMonitorTask(ConfigEntity));

            StringAssert.Contains(message, ex.Message);
        }
Ejemplo n.º 21
0
        public void Add()
        {
            IOrderByClause clause = new OrderByClause("field1 desc, field2");
            var            item   = new OrderByItem("field3", SortOrder.Descending);

            clause.Add(item);

            Assert.AreEqual("field1 desc,field2,field3 desc", clause.ToString());

            // can't add existing field
            Assert.Throws <ArgumentException>(() =>
            {
                clause.Add("field2");
            });

            clause.AddAlways("field1", SortOrder.Ascending);
            Assert.AreEqual("field2,field3 desc,field1", clause.ToString());

            item.Reverse();
            Assert.AreEqual("field2,field3,field1", clause.ToString());
        }
Ejemplo n.º 22
0
        public void DeleteEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();

            dog.Name = "SomeDog";
            dog.Age  = 10;
            IQ.Save(dog, opts);

            var id = dog.PK;

            dog.Events.Clear();
            bool deleted = dog.Delete(opts);

            Assert.IsTrue(deleted);
            Assert.AreEqual(2, dog.Events.Count, "Two events on delete");

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Can't delete with zero-valued primary key");



            dog.Save(opts);
            Assert.AreEqual(id + 1, dog.PK, "ID incremented by one for a new save");

            dog.RejectNextEvent = IQEventType.BeforeDelete;
            deleted             = dog.Delete(opts);

            Assert.IsFalse(deleted, "Was not actually deleted");
            dog.RejectNextEvent = IQEventType.OnDelete;
            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Rejecting the after-delete event throws an exception");
        }
 public void SendAccountActivationEmail_ShouldThrowExceptionWhenEmailIsEmptyString()
 {
     // Assert
     Assert.Throws(typeof(ArgumentException), delegate { _email.SendAccountActivationEmail("", "", ""); });
 }
 public void SendAccountActivationEmail_ShouldThrowExceptionWhenEmailIsNull()
 {
     // Assert
     Assert.Throws(typeof(ArgumentNullException), delegate { _email.SendAccountActivationEmail(null, "", ""); });
 }
Ejemplo n.º 25
0
        public void GetPrimes_ParamNumberOfPrimesZero_Expected_ArgumentNullException()
        {
            var numberOfPrimes = 0;

            Assert.Throws(typeof(ArgumentNullException), () => _primeGenerator.GetPrimes(numberOfPrimes));
        }
 public void SendAccountActivationEmail_ShouldThrowExceptionWhenSecurityTokenIsNull()
 {
     // Assert
     Assert.Throws(typeof(ArgumentNullException), delegate { _email.SendAccountActivationEmail("*****@*****.**", null, ""); });
 }
 public void SendAccountActivationEmail_ShouldThrowExceptionWhenConfirmationUrlIsNull()
 {
     // Assert
     Assert.Throws(typeof(ArgumentNullException), delegate { _email.SendAccountActivationEmail("*****@*****.**", "", null); });
 }