public void IfEqualWith3Arguments() { // ACT var exception = Assert.Throws <DesignByContractViolationException>( () => Fail.IfEqual(1, 1, "{0} is equal to {1} and shouldn't {2}", 1, 1, "be") ); // ASSERT Assert.That(exception.Message, Is.EqualTo("1 is equal to 1 and shouldn't be")); }
public void IfEqualWith0Arguments() { // ACT var exception = Assert.Throws <DesignByContractViolationException>( () => Fail.IfEqual("s1", "s1", "values are equal and shouldn't be") ); // ASSERT Assert.That(exception.Message, Is.EqualTo("values are equal and shouldn't be")); }
public void IfEqualWithMessage(Pair obj) { // ACT var exception = Assert.Throws <DesignByContractViolationException>( () => Fail.IfEqual(obj.Value1, obj.Value2, Violation.Of("{0} is equal to {1} and shouldn't {2}. {3}", "first", "second", "be", "Seriously?")) ); // ASSERT Assert.That(exception.Message, Is.EqualTo("first is equal to second and shouldn't be. Seriously?")); }
public void IfEqualWithNArguments() { // ACT var exception = Assert.Throws <DesignByContractViolationException>( // ReSharper disable HeapView.BoxingAllocation () => Fail.IfEqual(1, 1, "{0} is equal to {1} and shouldn't {2}. {3}", 1, 1, "be", "Seriously?") // ReSharper restore HeapView.BoxingAllocation ); // ASSERT Assert.That(exception.Message, Is.EqualTo("1 is equal to 1 and shouldn't be. Seriously?")); }
public void InvokeAnotherSession() { Fail.IfFalse(this.sampleDatabase.CurrentSession.Transaction.IsActive, "Transaction not started"); var task = new Task(session => { var currentSession = this.sampleDatabase.CurrentSession; Fail.IfEqual(session, currentSession, "session should differ"); }, this.sampleDatabase.CurrentSession); task.Start(); task.Wait(); }
/// <inheritdoc /> public void Apply([NotNull] IPropertyInstance instance) { Fail.IfArgumentNull(instance, nameof(instance)); if (instance.Type.GetUnderlyingSystemType() != typeof(string)) { return; } int length = ((IPropertyInspector)instance).Length; Fail.IfEqual(0, length, "{0}.{1} length is 0", instance.EntityType.Name, instance.Name); }
public void IfEqualNulls() { // ARRANGE object o1 = null; object o2 = null; // ACT var exception = Assert.Throws <DesignByContractViolationException>( // ReSharper disable ExpressionIsAlwaysNull () => Fail.IfEqual(o1, o2, "values are equal and shouldn't be") // ReSharper restore ExpressionIsAlwaysNull ); // ASSERT Assert.That(exception.Message, Is.EqualTo("values are equal and shouldn't be")); }
public void InvokeAnotherSession() { Fail.IfFalse(this.myDatabase.CurrentSession.Transaction.IsActive, "Transaction not started"); var task = new Task(session => { using (new SessionThreadStaticScope()) { using (this.myDatabase.OpenSession()) { var currentSession = this.myDatabase.CurrentSession; Fail.IfEqual(session, currentSession, "session should differ"); } } }, this.myDatabase.CurrentSession); task.Start(); task.Wait(); }
public void IfEqualSuccess() { // ACT Fail.IfEqual("s1", "s2", "values are equal and shouldn't be"); }
public void IfEqualSuccess(Pair obj) { // ACT Fail.IfEqual(obj.Value1, obj.Value2, "values are equal and shouldn't be"); }