public void Enumerator_ReturnsElementsInDefault_ExceptThoseInDirectCollection()
        {
            // Arrange
            var extension1          = new ExtensionOne();
            var extension2          = new ExtensionTwo();
            var extension2InDefault = new ExtensionTwo();
            var extension3InDefault = new ExtensionThree();
            var defaults            = new WorkContextExtensionCollection();

            defaults[typeof(ExtensionTwo)]   = extension2InDefault;
            defaults[typeof(ExtensionThree)] = extension3InDefault;
            var collection = new WorkContextExtensionCollection(defaults);

            collection[typeof(ExtensionOne)] = extension1;
            collection[typeof(ExtensionTwo)] = extension2;

            // Act
            var extensions = collection.ToList();

            // Assert
            Assert.Equal(3, extensions.Count);
            Assert.Contains(extensions, p => p.Key == typeof(ExtensionOne) && p.Value == extension1);
            Assert.Contains(extensions, p => p.Key == typeof(ExtensionTwo) && p.Value == extension2);
            Assert.Contains(extensions, p => p.Key == typeof(ExtensionThree) && p.Value == extension3InDefault);
            Assert.DoesNotContain(extensions, p => p.Key == typeof(ExtensionTwo) && p.Value == extension2InDefault);
        }
        public void Revision_InitiallyZero()
        {
            // Arrange

            // Act
            var collection = new WorkContextExtensionCollection();

            // Assert
            Assert.Equal(0, collection.Revision);
        }
        public void Indexer_ValidatesArguments()
        {
            // Arrange
            var    collection = new WorkContextExtensionCollection();
            object extension  = null;

            // Act

            // Assert
            Assert.Throws <ArgumentNullException>(() => extension = collection[null /* key */]);
            Assert.Throws <ArgumentNullException>(() => collection[null /* key */] = extension);
        }
Пример #4
0
        public void Constructor_FlowsCollection_ToProperties()
        {
            // Arrange
            var collection = new WorkContextExtensionCollection();

            // Act
            var context = new WorkContext(collection);

            // Assert
            Assert.NotNull(context.Extensions);
            Assert.Same(collection, context.Extensions);
        }
        public void Indexer_DoesntStepRevision_IfSettingNullValue_WhenSettingDidntExist()
        {
            // Arrange
            var extension  = new object();
            var collection = new WorkContextExtensionCollection();

            // Act
            collection[typeof(object)] = null;
            var result = collection[typeof(object)];

            // Assert
            Assert.Null(result);
            Assert.Equal(0, collection.Revision);
        }
        public void Indexer_SetsExtension_InCollection()
        {
            // Arrange
            var extension  = new object();
            var collection = new WorkContextExtensionCollection();

            // Act
            collection[typeof(object)] = extension;
            var result = collection[typeof(object)];

            // Assert
            Assert.NotNull(result);
            Assert.Equal(1, collection.Revision);
        }
        public void Revision_IncludesDefaultCollectionRevision()
        {
            // Arrange
            var extension = new object();
            var defaults  = new WorkContextExtensionCollection();

            defaults[typeof(object)] = extension;

            // Act
            var collection = new WorkContextExtensionCollection(defaults);

            // Assert
            Assert.Equal(1, collection.Revision);
        }
Пример #8
0
        public void TenantId_ProvidesTenantId_FromExtension()
        {
            // Arrange
            var tenantId   = new TenantId("custom");
            var extension  = CreateTenantWorkContextExtension(tenantId);
            var collection = new WorkContextExtensionCollection();

            collection.SetExtension(extension);

            // Act
            var context = new WorkContext(collection);

            // Assert
            Assert.Equal(tenantId, context.TenantId);
        }
        public void Indexer_RemovesExtension_InCollection_WhenSettingNullValue()
        {
            // Arrange
            var extension  = new object();
            var collection = new WorkContextExtensionCollection();

            collection[typeof(object)] = extension;

            // Act
            collection[typeof(object)] = null;
            var result = collection[typeof(object)];

            // Assert
            Assert.Null(result);
            Assert.Equal(2, collection.Revision);
        }
        public void Indexer_GetsExtension_FromDefaults_WhenNotInDirectCollection()
        {
            // Arrange
            var extension = new object();
            var defaults  = new WorkContextExtensionCollection();

            defaults[typeof(object)] = extension;

            var collection = new WorkContextExtensionCollection(defaults);

            // Act
            var result = collection[typeof(object)];

            // Assert
            Assert.NotNull(result);
            Assert.Same(extension, result);
        }
        public void Enumerator_ReturnsElementsInCollection()
        {
            // Arrange
            var extension1 = new ExtensionOne();
            var extension2 = new ExtensionTwo();
            var collection = new WorkContextExtensionCollection();

            collection[typeof(ExtensionOne)] = extension1;
            collection[typeof(ExtensionTwo)] = extension2;

            // Act
            var extensions = collection.ToList();

            // Assert
            Assert.Equal(2, extensions.Count);
            Assert.Contains(extensions, p => p.Key == typeof(ExtensionOne) && p.Value == extension1);
            Assert.Contains(extensions, p => p.Key == typeof(ExtensionTwo) && p.Value == extension2);
        }
Пример #12
0
        public void Cultures_ProvidedByExtension()
        {
            // Arrange
            var formatting = CultureInfo.GetCultureInfo("en-US");
            var resource   = CultureInfo.GetCultureInfo("es-ES");
            var extension  = CreateCultureWorkContextExtension(formatting, resource);
            var collection = new WorkContextExtensionCollection();

            collection.SetExtension(extension);

            // Act
            var context = new WorkContext(collection);

            // Assert
            Assert.NotNull(context.FormattingCulture);
            Assert.Same(formatting, context.FormattingCulture);

            Assert.NotNull(context.ResourceCulture);
            Assert.Same(resource, context.ResourceCulture);
        }
Пример #13
0
        public void FormattingCulture_CanBeChanged_WhenSettingExtension()
        {
            // Arrange
            var culture1 = new CultureInfo("en-GB");
            var culture2 = new CultureInfo("en-US");

            var extension1 = CreateCultureWorkContextExtension(culture1, culture1);
            var extension2 = CreateCultureWorkContextExtension(culture2, culture2);

            var collection = new WorkContextExtensionCollection();

            collection.SetExtension(extension1);

            var context = new WorkContext(collection);

            // Act
            context.Extensions.SetExtension(extension2);

            // Assert
            Assert.Equal(culture2, context.FormattingCulture);
        }
Пример #14
0
        public void Tenant_CanBeChanged_WhenSettingExtension()
        {
            // Arrange
            var tenant1 = new TenantId("one");
            var tenant2 = new TenantId("two");

            var extension1 = CreateTenantWorkContextExtension(tenant1);
            var extension2 = CreateTenantWorkContextExtension(tenant2);

            var collection = new WorkContextExtensionCollection();

            collection.SetExtension(extension1);

            var context = new WorkContext(collection);

            // Act
            context.Extensions.SetExtension(extension2);

            // Assert
            Assert.Equal(tenant2, context.TenantId);
        }