Ejemplo n.º 1
0
        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"));
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        // 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);
        }
Ejemplo n.º 30
0
        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);
        }