예제 #1
0
        public void ShouldAllowDynamicAsParameter()
        {
            // Arrange
            var value     = 5;
            var something = new DoSomethingUseful();
            // Act
            var result = something.Execute(value);

            // Assert
            result.Should().Be(value);
        }
예제 #2
0
        public void ShouldAllowReAssignmentOfComplexTypes()
        {
            // Arrange
            dynamic d = new DoSomethingUseful();

            // Pre-Assert
            Assert.AreEqual(typeof(DoSomethingUseful), d.GetType());
            // Act
            d = new TheThing();
            // Assert
            Assert.AreEqual(typeof(TheThing), d.GetType());
        }
예제 #3
0
        public void ShouldThrowRuntimeExceptionWhenCallingMethodThatDoesNotExist()
        {
            // Arrange
            dynamic something = new DoSomethingUseful();

            // Act
            try
            {
                something.SomeMethodThatDoesNotExist();
            }
            catch (Exception e)
            {
                // Assert
                e.Message.Should()
                .Be("'Dynamic.DoSomethingUseful' does not contain a definition for 'SomeMethodThatDoesNotExist'");
            }
        }