|
| 1 | +using System; |
| 2 | +using System.Text; |
| 3 | +using System.Collections.Generic; |
| 4 | + |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace ChanceNET.Tests |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Summary description for SerializationTests |
| 11 | + /// </summary> |
| 12 | + [TestFixture] |
| 13 | + public class Tests |
| 14 | + { |
| 15 | + Chance chance = new Chance(); |
| 16 | + |
| 17 | + static IEnumerable<int> LoopTestSource() |
| 18 | + { |
| 19 | + for (int i = 0; i < 10000; i++) |
| 20 | + { |
| 21 | + yield return i; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + [Test, TestCaseSource("LoopTestSource")] |
| 26 | + public void LocationTests(int i) |
| 27 | + { |
| 28 | + Location loc = chance.Location(); |
| 29 | + |
| 30 | + Assert.IsTrue(loc.Latitude != 0 && loc.Latitude >= -90 && loc.Latitude <= 90); |
| 31 | + Assert.IsTrue(loc.Longitude != 0 && loc.Longitude >= -180 && loc.Longitude <= 180); |
| 32 | + |
| 33 | + double distance = loc.DistanceTo(loc); |
| 34 | + |
| 35 | + Assert.AreEqual(0, distance); |
| 36 | + |
| 37 | + Location other = chance.Location(loc, 1000); |
| 38 | + Assert.IsTrue(loc.DistanceTo(other) < 1000); |
| 39 | + } |
| 40 | + |
| 41 | + [Test, TestCaseSource("LoopTestSource")] |
| 42 | + public void SerializationTests(int i) |
| 43 | + { |
| 44 | + Book b = chance.Object<Book>(); |
| 45 | + |
| 46 | + Assert.IsTrue(b.Year > 0); |
| 47 | + Assert.IsTrue(b.Price >= 0 && b.Price < 100); |
| 48 | + Assert.IsTrue(b.Release != default(DateTime)); |
| 49 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Title)); |
| 50 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Guid)); |
| 51 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.CoverColor)); |
| 52 | + Assert.IsTrue(b.CoverColor.StartsWith("#")); |
| 53 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Author.Email)); |
| 54 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Author.FirstName)); |
| 55 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Author.FullName())); |
| 56 | + Assert.IsFalse(string.IsNullOrWhiteSpace(b.Author.LastName)); |
| 57 | + Assert.IsTrue(b.Location.Latitude != 0 && b.Location.Latitude >= -90 && b.Location.Latitude <= 90); |
| 58 | + Assert.IsTrue(b.Location.Longitude != 0 && b.Location.Longitude >= -180 && b.Location.Longitude <= 180); |
| 59 | + Assert.IsTrue(Uri.IsWellFormedUriString(b.Website, UriKind.Absolute)); |
| 60 | + } |
| 61 | + |
| 62 | + [TearDown] |
| 63 | + public void Reset() |
| 64 | + { |
| 65 | + chance = chance.New(); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments