public void Add(string bookName, string isbn13, string isbn10, string author, string genre, string publisher, string published, string listPrice, string coverLink, OnError <String> onError, OnSuccess onSucess) { string error = ""; BookItem book = new BookItem(); if (bookName.Length == 0) { error += "Book Name is mandatory field\n"; } book.Name = bookName; book.ISBN13 = isbn13; if (!CheckExtension.CheckISBN13(isbn13)) { error += "Wrong ISBN-13 Code. No spaces, letters, punctuations. ISBN must have 13 numbers\n"; } book.ISBN10 = isbn10; if (!CheckExtension.CheckISBN10(isbn10)) { error += "Wrong ISBN-10 Code. No spaces, letters, punctuations. ISBN must have 10 numbers\n"; } if (author.Length == 0) { error += "Author is mandatory field\n"; } book.Author = author; if (genre.Length == 0) { error += "Genre is mandatory field\n"; } book.Genre = genre; book.Publisher = publisher; if (!CheckExtension.CheckPublished(published)) { error += "Wrong Published Date format. Example: 2018\n"; } else { book.Published = int.Parse(published); } if (!CheckExtension.CheckListPrice(listPrice)) { error += "Wrong ListPrice format\n"; } else { double.TryParse(listPrice, out double x); book.ListPrice = x; } book.CoverLink = coverLink; if (error.Length == 0) { SQLConnection.AddNewItem(book); onSucess(); } else { onError(error); } }
public void Limit_ThrowException(int length) { Action act = () => CheckExtension.Limit(length); // Assert act .Should().Throw <Exception>() .WithMessage("*the decimal place limit cannot be negative*"); }
public void CheckLstPrice_WithValidInput_ReturnTrue() { //Arrange string price = "0.3"; //Act bool result = CheckExtension.CheckListPrice(price); //Assert Assert.IsTrue(result); }
public void CheckLstPrice_WithWrongInput_ReturnFalse2() { //Arrange string price = ".99"; //Act bool result = CheckExtension.CheckListPrice(price); //Assert Assert.IsFalse(result); }
public void CheckPublishedDate_WithWrongInput_ReturnFalse2() { //Arrange string date = "301"; //Act bool result = CheckExtension.CheckPublished(date); //Assert Assert.IsFalse(result); }
public void CheckISBN13_WithWrongInput_ReturnFalse() { //Arrange string ISBN13 = "0123456789"; //Act bool result = CheckExtension.CheckISBN13(ISBN13); //Assert Assert.IsFalse(result); }
public void CheckISBN13_WithValidInput_ReturnTrue() { //Arrange string ISBN13 = "9780142437230"; //Act bool result = CheckExtension.CheckISBN13(ISBN13); //Assert Assert.IsTrue(result); }
public void CheckISBN10_WithWrongInput_ReturnFalse() { //Arrange string ISBN10 = "123456"; //Act bool result = CheckExtension.CheckISBN10(ISBN10); //Assert Assert.IsFalse(result); }
public void CheckISBN10_WithNoInput_ReturnTrue() { //Arrange string ISBN10 = ""; //Act bool result = CheckExtension.CheckISBN10(ISBN10); //Assert Assert.IsTrue(result); }
public void CheckPublishedDate_WithValidInput_ReturnTrue() { //Arrange string date = "2018"; User user = new User(); AddBookForm addBook = new AddBookForm(user); //Act bool result = CheckExtension.CheckPublished(date); //Assert Assert.IsTrue(result); }
public void TestFormatRandom() { Setup(); var format = new ITraqResultXmlFormatRandomReader(); format.Open(@TestContext.CurrentContext.TestDirectory + "/../../../data//ITraqResult.xml"); CheckExtension.CheckEquals(t2, format.Read("S2", 355)); CheckExtension.CheckEquals(t1, format.Read("S1", 255)); Assert.AreEqual(1281, format.ReadXmlBytes("S1", 255).Length); Assert.AreEqual(1386, format.ReadXmlBytes("S2", 355).Length); }
public void RunFormat(IITraqResultFileFormat format) { Setup(); var tmpFilename = @TestContext.CurrentContext.TestDirectory + "/../../../data//temp.xml"; format.WriteToFile(tmpFilename, tr); FileAssert.AreEqual(@TestContext.CurrentContext.TestDirectory + "/../../../data//ITraqResult.xml", tmpFilename); var newtr = format.ReadFromFile(tmpFilename); CheckExtension.CheckEquals(tr, newtr); format.ReadPeaks = false; var newstr2 = format.ReadFromFile(tmpFilename); Assert.IsEmpty(newstr2[0].RawPeaks); Assert.IsEmpty(newstr2[0].PeakInIsolationWindow); Assert.IsEmpty(newstr2[1].RawPeaks); Assert.IsEmpty(newstr2[1].PeakInIsolationWindow); format.Accept = (m => 355 == m.Scan.Scan); var newstr3 = format.ReadFromFile(tmpFilename); Assert.AreEqual(1, newstr3.Count); Assert.AreEqual(355, newstr3[0].Scan.Scan); var lines = File.ReadAllText(tmpFilename); ITraqResultXmlFormatReader reader = new ITraqResultXmlFormatReader(); reader.OpenByContent(lines); var item = reader.Next(); CheckExtension.CheckEquals(tr[0], item); item = reader.Next(); CheckExtension.CheckEquals(tr[1], item); File.Delete(tmpFilename); if (File.Exists(tmpFilename + ".index")) { File.Delete(tmpFilename + ".index"); } }
public void TestReadWrite() { List <FileIndexItem> items = new List <FileIndexItem>(); items.Add(new FileIndexItem(12, 54, "TEST1")); items.Add(new FileIndexItem(122, 776, "TEST2")); items.Add(new FileIndexItem(12483, 39484, "TEST3")); items.Add(new FileIndexItem(121111111111111, 38948392309484, "TEST4")); var format = new FileIndexFormat(); var tmpFilename = TestContext.CurrentContext.TestDirectory + "/../../../data//fif.txt"; format.WriteToFile(tmpFilename, items); var newitems = format.ReadFromFile(tmpFilename); CheckExtension.CheckEquals(items, newitems); File.Delete(tmpFilename); }
public void Limit_NotThrow(int length) { Action act = () => CheckExtension.Limit(length); act.Should().NotThrow(); }
public double DoubleFromTo(double min = 0, double max = 1, int limit = 10) { max.BeGreaterThan(min); CheckExtension.Limit(limit); return(bogus.Value.DoubleFromTo(min, max, limit)); }