예제 #1
0
        public void Attribute_string_does_not_contain_unset_properties()
        {
            // Arrange
            var nativeTag = new Mock <INativeTag>();
            var tag       = new NativeTagWrapper(nativeTag.Object);

            // Act
            tag.Initialize();


            // Assert
            nativeTag.Verify(m => m.plc_tag_create("", It.IsAny <int>()), Times.Once);
        }
예제 #2
0
        public void Destroy_is_called_if_initialized_and_disposed()
        {
            // Arrange
            var nativeTag = new Mock <INativeTag>();
            var tag       = new NativeTagWrapper(nativeTag.Object);

            // Act
            tag.Initialize();
            tag.Dispose();

            // Assert
            nativeTag.Verify(m => m.plc_tag_destroy(It.IsAny <int>()), Times.Once);
        }
예제 #3
0
        public void Attribute_string_formatted_correctly()
        {
            // Arrange
            var nativeTag = new Mock <INativeTag>();
            var tag       = new NativeTagWrapper(nativeTag.Object)
            {
                ElementSize  = 4,
                ElementCount = 10,
                PlcType      = PlcType.Slc500,
                Name         = "TagName",
            };


            // Act
            tag.Initialize();


            // Assert
            nativeTag.Verify(m => m.plc_tag_create("plc=slc500&elem_size=4&elem_count=10&name=TagName", It.IsAny <int>()), Times.Once);
        }
예제 #4
0
        public void Finalizer_calls_destroy()
        {
            // See https://www.inversionofcontrol.co.uk/unit-testing-finalizers-in-csharp/


            // Arrange
            var    nativeTag = new Mock <INativeTag>();
            Action dispose   = () =>
            {
                // This will go out of scope after dispose() is executed, so the garbage collector will be able to call the finalizer
                var tag = new NativeTagWrapper(nativeTag.Object);
                tag.Initialize();
            };

            // Act
            dispose();
            GC.Collect(0, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            // Assert
            nativeTag.Verify(m => m.plc_tag_destroy(It.IsAny <int>()), Times.Once);
        }