public void Context_OK() { var mc = new MyClass(300); RunTest(AnyValue.IsValid, ctx => mc.Method(ctx.SetHandle), SmartAssert.Within(100), SmartAssert.WaitContextHandle(1000)); Assert.IsTrue(mc.Done); Assert.IsNull(mc.Exception); }
public void EmptyName() { // Act part: implement another case. // This case is an error, should be treated specifically (one error at a time) RunTest(Case("name", ValidString.IsEmpty) & Case("address", ValidString.HasContent), () => new Customer("", "Montreal"), // Assert Part // Ensure the ArgumentOutOfRangeException is thrown when the Customer is created // Better than Assert.Catch, as you can still have Smart Assertions after catching the failure SmartAssert.Throw <ArgumentOutOfRangeException>("name")); }
public void IndirectError() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(false, false, true, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.ChangedTo(() => mc.Items.Count, 3)); }); Assert.AreEqual("Change is wrong. Expected 3, but was 2", exception.Message); }
public void IndirectBad() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(false, false, true, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.ChangedTo(() => mc.Items.Count, 1)); }); Assert.AreEqual("BAD TEST: unexpected value 1", exception.Message); }
public void Property2Changed() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(false, true, false, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChanged(mc, NotChangedKind.AllProperties)); }); Assert.AreEqual("Property 'NotChangedTestsAll+MyClass.MyProperty2' has changed", exception.Message); }
public void Fail() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(100); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.Within(90)); }); StringAssert.IsMatch(@"Should be less than 90ms, but was \d+ms", exception.Message); }
public void AllPropertiesChanged_ImplicitPublicImplicitInstance() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(true, true, true, true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChangedExcept("MyProperty1")); }); Assert.AreEqual("Property 'NotChangedTestsExcept+MyClass.MyProperty2' has changed", exception.Message); }
public void AllPropertiesChanged_Except123() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(true, true, true, true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChangedExcept(mc, NotChangedKind.AllProperties, "MyProperty1", "MyProperty2", "MyProperty3")); }); StringAssert.Contains("Property 'NotChangedTestsExcept+MyClass.MyProperty4' has changed", exception.Message); }
public void Property1ChangedPublic() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(true, false, false, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChanged()); }); Assert.AreEqual("Property 'NotChangedTestsImplicit+MyClass.MyProperty1' has changed", exception.Message); }
public void PropertyChangeError() { var exception = Assert.Catch <SmartTestException>(() => { _Mc.ChangeProperty = true; RunTest(AnyValue.IsValid, () => _Mc.Method(), SmartAssert.Change(() => _Mc.MyProperty + 2)); }); Assert.AreEqual("Change is wrong. Expected 2, but was 1", exception.Message); }
public void IndexerChangeError() { var exception = Assert.Catch <SmartTestException>(() => { _Mc.ChangeIndexer = true; RunTest(AnyValue.IsValid, () => _Mc.Method(), SmartAssert.Change(() => _Mc[0] + 3)); }); Assert.AreEqual("Change is wrong. Expected 3, but was 2", exception.Message); }
public void Field1ChangedPublic() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(true, false, false, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChanged(NotChangedKind.PublicFields)); }); Assert.AreEqual("Field 'NotChangedTestsFieldsImplicit+MyClass.MyField1' has changed", exception.Message); }
public void UnexpectedNotEvent() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotRaised(mc, "NotEvent")); }); Assert.AreEqual("BAD TEST: 'NotEvent' is not an event of type 'EventHandlerTests+MyClass'", exception.Message); }
public void HappyPath_Message() { var run = false; RunTest(AnyValue.IsValid, () => MyClass.Method("throw"), SmartAssert.Throw <ArithmeticException>(e => { run = true; Assert.AreEqual("Wrong Computation", e.Message); })); Assert.IsTrue(run); }
public void FieldBad() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, Assign(() => mc.MyField, 0), SmartAssert.ChangedTo()); }); Assert.AreEqual("BAD TEST: unexpected value 0", exception.Message); }
public void PropertyBad() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(true, false, false, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.ChangedTo(() => mc.MyProperty, 0)); }); Assert.AreEqual("BAD TEST: unexpected value 0", exception.Message); }
public void PropertyNotAssignment() { var exception = Assert.Catch <BadTestException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, () => mc.MyProperty, SmartAssert.ChangedTo()); }); Assert.AreEqual("BAD TEST: Act is not an assignment", exception.Message); }
public void NotRaised() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.Raised(mc, "MyEvent")); }); Assert.AreEqual("Event 'EventHandlerTests+MyClass.MyEvent' was expected", exception.Message); }
public void PropertyBad() { var exception = Assert.Catch <BadTestException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, Assign(() => mc.MyProperty, 0), SmartAssert.ChangedTo()); }); Assert.AreEqual("BAD TEST: unexpected value 0", exception.Message); }
public void AllPropertiesChanged_ImplicitPublicWithNonPublic() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(true, true, true, true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChangedExcept(mc, "MyProperty1", "MyProperty3")); }); Assert.AreEqual("BAD TEST: 'MyProperty3' is not a property nor a field of type 'NotChangedTestsExcept+MyClass'", exception.Message); }
public void PropertyError() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, Assign(() => mc.MyPropertyError, 1), SmartAssert.ChangedTo()); }); Assert.AreEqual("Change is wrong. Expected 1, but was 0", exception.Message); }
public void BadProperty() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(false, false, false, false); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotChangedExcept(mc, NotChangedKind.AllProperties, "BadProperty")); }); Assert.AreEqual("BAD TEST: 'BadProperty' is not a property nor a field of type 'NotChangedTestsExcept+MyClass'", exception.Message); }
public void FieldBad() { var exception = Assert.Catch <BadTestException>(() => { var mc = new MyClass(false, false, false, true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.ChangedTo(() => mc.MyField, 0)); }); Assert.AreEqual("BAD TEST: unexpected value 0", exception.Message); }
public void NegativeTimeout() { var exception = Assert.Catch <BadTestException>(() => { var mc = new MyClass(100); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.Within(-90)); }); Assert.AreEqual(@"BAD TEST: Time should be strictly positive, but was -90ms", exception.Message); }
public void FieldError() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(false, false, false, true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.ChangedTo(() => mc.MyField, 2)); }); Assert.AreEqual("Change is wrong. Expected 2, but was 4", exception.Message); }
// ReSharper disable once InconsistentNaming public void OK() { var handle = new AutoResetEvent(false); var mc = new MyClass(300); RunTest(AnyValue.IsValid, () => mc.Method(() => handle.Set()), SmartAssert.Within(100), SmartAssert.Wait(handle, 1000)); Assert.IsTrue(mc.Done); Assert.IsNull(mc.Exception); }
public void FieldNotAssignment() { var exception = Assert.Catch <InconclusiveException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, () => mc.MyField, SmartAssert.ChangedTo()); }); Assert.AreEqual("BAD TEST: Act is not an assignment", exception.Message); }
public void NotEvent() { var exception = Assert.Catch <BadTestException>(() => { var mc = new MyClass(true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.Raised("NotEvent")); }); Assert.AreEqual("BAD TEST: 'NotEvent' is not an event of type 'EventHandlerTestsImplicit+MyClass'", exception.Message); }
public void UnexpectedRaised() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(true); RunTest(AnyValue.IsValid, () => mc.Method(), SmartAssert.NotRaised("MyEvent")); }); Assert.AreEqual("Event 'EventHandlerTestsImplicit+MyClass.MyEvent' was unexpected", exception.Message); }
public void NotChangedExcept_BadExcept() { var exception = Assert.Catch <SmartTestException>(() => { var mc = new MyClass(); RunTest(AnyValue.IsValid, Assign(() => mc.MyProperty2, 1), SmartAssert.NotChangedExceptAct(), SmartAssert.ChangedTo()); }); StringAssert.Contains("Property 'NotChangedTestsExceptImplicit+MyClass.MyProperty3' has changed", exception.Message); }