public void ReductionWorks(int iterations, double maxIncrementsPerIteration) { var incrementer = new Incrementer(); for (int i = 0; i < iterations; i++) { incrementer.AddIncrements(Brandom.Gen.NextDouble() * maxIncrementsPerIteration); } var exactBeforeReduction = incrementer.ExactIncrements; var fullBeforeReduction = incrementer.FullIncrements; var partialBeforeReduction = incrementer.PartialIncrements; Assert.That(exactBeforeReduction - fullBeforeReduction, Is.EqualTo(partialBeforeReduction), $"Before {nameof(incrementer.Reduce)}: {nameof(incrementer.ExactIncrements)} - {nameof(incrementer.FullIncrements)} == {nameof(incrementer.PartialIncrements)}"); var reductionAmount = incrementer.Reduce(); AssertAll.Of( $"After calling {nameof(incrementer.Reduce)}", () => Assert.That(reductionAmount, Is.EqualTo(fullBeforeReduction), $"{nameof(incrementer.Reduce)} should have returned the previous {nameof(incrementer.FullIncrements)}"), () => Assert.That(incrementer.ExactIncrements, Is.EqualTo(partialBeforeReduction), $"{nameof(incrementer.ExactIncrements)} should equal the previous {nameof(incrementer.PartialIncrements)}"), () => Assert.That(incrementer.ExactIncrements, Is.Positive.And.LessThan(1), $"1 > {nameof(incrementer.ExactIncrements)} >= 0") ); }
public static void CompareResponseDataForWholeAddress(Address responsedAddress) { Address address = CreateValidTestDataObject(); AssertAll.Succeed( () => Assert.AreEqual(address.ErrorCode, responsedAddress.ErrorCode), () => Assert.AreEqual(address.ErrorMessage, responsedAddress.ErrorMessage), () => Assert.AreEqual(address.AddressLine1, responsedAddress.AddressLine1), () => Assert.AreEqual(address.AddressLine2, responsedAddress.AddressLine2), () => Assert.AreEqual(address.Number, responsedAddress.Number), () => Assert.AreEqual(address.PreDir, responsedAddress.PreDir), () => Assert.AreEqual(address.Street, responsedAddress.Street), () => Assert.AreEqual(address.Suffix, responsedAddress.Suffix), () => Assert.AreEqual(address.PostDir, responsedAddress.PostDir), () => Assert.AreEqual(address.Sec, responsedAddress.Sec), () => Assert.AreEqual(address.City, responsedAddress.City), () => Assert.AreEqual(address.State, responsedAddress.State), () => Assert.AreEqual(address.Zip, responsedAddress.Zip), () => Assert.AreEqual(address.Zip4, responsedAddress.Zip4), () => Assert.AreEqual(address.County, responsedAddress.County), () => Assert.AreEqual(address.StateFP, responsedAddress.StateFP), () => Assert.AreEqual(address.CountyFP, responsedAddress.CountyFP), () => Assert.AreEqual(address.CensusTract, responsedAddress.CensusTract), () => Assert.AreEqual(address.CensusBlock, responsedAddress.CensusBlock), () => Assert.AreEqual(address.Latitude, responsedAddress.Latitude), () => Assert.AreEqual(address.Longitude, responsedAddress.Longitude), () => Assert.AreEqual(address.GeoPrecision, responsedAddress.GeoPrecision), () => Assert.AreEqual(address.TimeZoneOffset, responsedAddress.TimeZoneOffset), () => Assert.AreEqual(address.DstObserved, responsedAddress.DstObserved, true, CultureInfo.CurrentCulture) ); }
public IEnumerator LoadTimeUnaffectedBySaving() { var beforeNewSave = DateTime.Now; yield return(null); var saveData = SaveDataTestImpl.NewSaveFile(nameof(LoadTimeUnaffectedBySaving)); var afterNewSave = DateTime.Now; AssertAll.Of( () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeNewSave, afterNewSave)), () => Assert.That(saveData.LastLoadTime, Is.Null) ); var oldSaveTime = saveData.LastSaveTime; var oldLoadTime = saveData.LastLoadTime; yield return(new WaitForSecondsRealtime(1)); var beforeReSave = DateTime.Now; yield return(null); saveData.Save(false); var afterReSave = DateTime.Now; AssertAll.Of( () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeReSave, afterReSave)), () => Assert.That(saveData.LastSaveTime, Is.Not.EqualTo(oldSaveTime)), () => Assert.That(saveData.LastLoadTime, Is.EqualTo(oldLoadTime)) ); }
public void FailWhenInnerExceptionIsNull() { AssertAll.ThrowsExceptionWithInnerException <ArgumentException>(() => throw new Exception(RandomValue.String())); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
internal static void TestMethod(this AssertAll source, bool passes) { if (passes == false) { AssertAll.Fail(); } }
public void FailWhenThereAreFailures() { AssertAll.IsFalse(false); AssertAll.Inconclusive(); AssertAll.Fail(); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void TruncateLines( [Values(1, 5, 10, 50, 100)] int lineCount, [Values(1, 2, 10, 50, 100)] int truncateTo, [Values(true, false)] bool includeMessage ) { var ln = Enumerable.Repeat("LINE", lineCount); var truncated = ln.TruncateLines(truncateTo, includeMessage); var truncateCount = lineCount - truncateTo; if (lineCount > truncateTo) { AssertAll.Of( () => Assert.That(truncated, Has.Length.EqualTo(truncateTo)), () => { if (includeMessage) { AssertAll.Of( () => Assert.That(truncated.Last(), Is.Not.EqualTo("LINE")), () => Assert.That(truncated.Last(), Contains.Substring(truncateCount + "")) ); } } ); } else if (lineCount <= truncateTo) { Assert.That(truncated, Is.EqualTo(ln)); } }
public void TestSerializeThrowables() { const string nickName = nameof(TestSerializeThrowables); FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nickName); for (int i = 0; i < ValuableDatabase.ValuableTypes.Length; i++) { // copying `i` into `index` inside the loop 'cus otherwise lambdas can get messed up var index = i; var karmaValue = Random.Range(1, 25); var valuableType = ValuableDatabase.ValuableTypes[index]; Log($"Grabbing a {valuableType} with a value of {karmaValue}"); fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(valuableType, karmaValue)); fortuneFountainSaveData.Save(useReSaveDelay: false); Log($"before loading throwables:", fortuneFountainSaveData.Hand.Throwables.JoinLines()); //load the save data we created FortuneFountainSaveData loadedSaveData = FortuneFountainSaveData.Load(nickName); Log($"original SaveData:", fortuneFountainSaveData); Log($"loaded SaveData:", loadedSaveData); AssertAll.Of( () => Assert.That(loadedSaveData.ToJson(), Contains.Substring($"\"{nameof(Hand._throwables)}\":")), () => Assert.That(loadedSaveData.Hand.Throwables.Count, Is.EqualTo(index + 1)), () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable, Has.Property(nameof(ThrowableValuable.ValuableType)).EqualTo(valuableType)), () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable, Has.Property(nameof(ThrowableValuable.PresentValue)).EqualTo(karmaValue)) ); } }
public void FailWhenInnerExceptionIsNotCorrectType() { AssertAll.ThrowsExceptionWithInnerExceptionAsync <ArgumentException>(async() => await ThrowExceptionWithInnerInvalidOperationException(true)); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void FailWhenInnerExceptionIsNull() { AssertAll.ThrowsExceptionWithInnerExceptionAsync <ArgumentException>(async() => await ThrowNewException()); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void JonPath_Simple(string parent, string child, string expected) { AssertAll.Of( () => Assert.That(BPath.JoinPath(parent, child), Is.EqualTo(expected)), () => Assert.That(BPath.JoinPath(new[] { parent, child }), Is.EqualTo(expected)) ); }
public void PassWhenInnerExceptionIsOfCorrectType() { AssertAll.ThrowsExceptionWithInnerExceptionAsync <InvalidOperationException>(async() => await ThrowExceptionWithInnerInvalidOperationException(true)); AssertAll.Execute(); }
public void NotCareIfStructValueChanged() { var testBool = true; AssertAll.IsTrue(testBool); testBool = false; }
public IEnumerator SaveTimeUnaffectedByLoading() { DateTime beforeNewSave = DateTime.Now; yield return(null); var saveData = SaveDataTestImpl.NewSaveFile(nameof(SaveTimeUnaffectedByLoading)); DateTime afterNewSave = DateTime.Now; AssertAll.Of( () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeNewSave, afterNewSave)), () => Assert.That(saveData.LastLoadTime, Is.Null) ); var oldSaveTime = saveData.LastSaveTime; var oldLoadTime = saveData.LastLoadTime; yield return(new WaitForSecondsRealtime(1)); DateTime beforeReload = DateTime.Now; yield return(null); saveData.Reload(); DateTime afterReload = DateTime.Now; AssertAll.Of( () => Assert.That(saveData.LastSaveTime, Is.EqualTo(oldSaveTime), $"The {nameof(SaveDataTestImpl.LastSaveTime)} should not have changed, because we {nameof(SaveDataTestImpl.Reload)}-ed without {nameof(SaveDataTestImpl.Save)}-ing!"), () => Assert.That(saveData.LastLoadTime, Is.Not.EqualTo(oldLoadTime), $"The {nameof(SaveDataTestImpl.LastLoadTime)} should have changed, because we {nameof(SaveDataTestImpl.Reload)}-ed!"), () => Assert.That(saveData.LastLoadTime, Is.InRange(beforeReload, afterReload)) ); }
public void ThrowAssertInconclusiveExceptionWhenInconclusive() { AssertAll.IsFalse(false); AssertAll.AreEqual(1, 1); AssertAll.Inconclusive(); Assert.ThrowsException <AssertAllInconclusiveException>(() => AssertAll.Execute()); }
public void ThrowExceptionIfNotUsingAssertAllAttribute() { var exception = Assert.ThrowsException <InvalidOperationException>(() => AssertAll.IsTrue(true)); Assert.AreEqual("AssertAll statements can only be used in a test with the AssertAllTestMethod attribute", exception.Message); }
public void PassWhenThereAreNoExceptionsOrInconclusives() { AssertAll.IsFalse(false); AssertAll.AreEqual(1, 1); AssertAll.IsInstanceOfType(1, typeof(int)); AssertAll.Execute(); }
public void Substring_Regex(string original, string pattern, string expected_before, string expected_after) { AssertAll.Of( () => Assert.That(original.SubstringBefore(new Regex(pattern)), Is.EqualTo(expected_before)), () => Assert.That(original.SubstringAfter(new Regex(pattern)), Is.EqualTo(expected_after)) ); }
public void PassWhenExceptionOfCorrectTypeIsThrown() { var emptyList = new List <object>(); AssertAll.ThrowsException <InvalidOperationException>(() => emptyList.Single()); AssertAll.Execute(); }
private static void IsBackedBy([CanBeNull] this PropertyInfo propertyInfo, [CanBeNull] FieldInfo expectedBackingField) { AssertAll.Of( $"{propertyInfo.Prettify()} should have the backing field {expectedBackingField.Prettify()}", () => Assert.That(propertyInfo?.BackingField(), Is.Not.Null.And.EqualTo(expectedBackingField)), () => BacksProperty(expectedBackingField, propertyInfo) ); }
public static void IsAutoProperty(this PropertyInfo propertyInfo) { AssertAll.Of( () => Assert.That(propertyInfo.BackingField(), Is.Not.Null), () => Assert.That(propertyInfo.BackingField()?.IsAutoPropertyBackingField(), Is.True), () => BacksProperty(propertyInfo.BackingField(), propertyInfo) ); }
public void FailWhenWrongExceptionIsThrown() { var emptyList = new List <object>(); AssertAll.ThrowsException <NullReferenceException>(() => emptyList.Single()); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void Fill_NegativeLength() { AssertAll.Of( () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".FillRight(-1, "a")), () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".FillLeft(-1, "a")), () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".Fill(-1)) ); }
public void PassWhenSameReferences() { var object1 = new object(); var object2 = object1; AssertAll.AreSame(object1, object2, "these are not the same"); AssertAll.Execute(); }
public void PassWhenDifferentReferences() { var object1 = new object(); var object2 = new object(); AssertAll.AreNotSame(object1, object2, "these are the same"); AssertAll.Execute(); }
public void PassWhenValueEndsWithSubstring() { var start = RandomValue.String(); var end = RandomValue.String(); AssertAll.Strings.EndsWith($"{start}{end}", end); AssertAll.Execute(); }
public void FailWhenValueDoesNotEndsWithSubstring() { var value = RandomValue.String(); var substring = RandomValue.String(); AssertAll.Strings.EndsWith(value, substring); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void FailWhenDifferentReferences() { var object1 = new object(); var object2 = new object(); AssertAll.AreSame(object1, object2, "these are not the same"); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void FailWhenDoesNotStartWith() { var value = RandomValue.String(); var differentValue = RandomValue.String(); AssertAll.Strings.StartsWith(value, differentValue); Assert.ThrowsException <AssertAllFailedException>(() => AssertAll.Execute()); }
public void PassWhenStartsWIth() { var start = RandomValue.String(); var end = RandomValue.String(); AssertAll.Strings.StartsWith($"{start}{end}", start); AssertAll.Execute(); }