예제 #1
0
        public void Fetch_ReturnsExtensionFromCollecton_IfCollectionChanged()
        {
            // Arrange
            int    revision   = 1;
            object extension1 = new object();
            object extension2 = new object();

            object entry      = extension1;
            var    collection = CreateCollection <object>(
                onRevision: () => revision,
                onGet: () => entry);
            var reference = new WorkContextExtensionReference <object>();

            reference.Update(collection, extension1);

            // Act
            var result1   = reference.Fetch(collection);
            int revision1 = reference.Revision;

            revision++;
            entry = extension2;

            var result2   = reference.Fetch(collection);
            int revision2 = reference.Revision;

            // Assert
            Assert.NotNull(result1);
            Assert.Same(extension1, result1);
            Assert.Equal(1, revision1);

            Assert.NotNull(result2);
            Assert.Same(extension2, result2);
            Assert.Equal(2, revision2);
        }
예제 #2
0
        public void Update_CapturesExtension_AndRevision()
        {
            // Arrange
            object extension         = new object();
            object capturedExtension = null;
            var    collection        = CreateCollection <object>(
                revision: 1,
                onSet: e => capturedExtension = e);
            var reference = new WorkContextExtensionReference <object>();

            // Act
            var result = reference.Update(collection, extension);

            // Assert
            Assert.Equal(1, reference.Revision);
            Assert.Equal(extension, reference.Extension);
        }
예제 #3
0
        public void Fetch_ReturnsCapturedExtension_IfCollectionNotChanged()
        {
            // Arrange
            object extension  = new object();
            var    collection = CreateCollection <object>(
                revision: 1,
                extension: extension);
            var reference = new WorkContextExtensionReference <object>();

            reference.Update(collection, extension);

            // Act
            var result = reference.Fetch(collection);

            // Assert
            Assert.NotNull(result);
            Assert.Same(extension, result);
            Assert.Same(extension, reference.Extension);
        }
예제 #4
0
        public void Update_SetsExtension_InCollection()
        {
            // Arrange
            object extension         = new object();
            object capturedExtension = null;
            var    collection        = CreateCollection <object>(
                revision: 1,
                onSet: e => capturedExtension = e);
            var reference = new WorkContextExtensionReference <object>();

            // Act
            var result = reference.Update(collection, extension);

            // Assert
            Assert.NotNull(capturedExtension);
            Assert.Same(extension, capturedExtension);
            Assert.NotNull(result);
            Assert.Same(extension, result);
        }