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."); } } }
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."); }); }
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."); }
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"); }); }
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); }
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."); }
public void Test_Invalid_Values() { #if NUNIT Assert.Throws <ArgumentOutOfRangeException>(() => GammaRelated.LogOfFactorial(-1)); #else GammaRelated.LogOfFactorial(-1); #endif }
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; }); }
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); }); }
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); }
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"); }
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(); }
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); }
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); }
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"); }
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"); }
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."); }
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"); }
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); }
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()); }
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, "", ""); }); }
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); }); }