public void AlwaysSerialize_WithUnchangedProperty_SerializesPropertyAnyway()
        {
            // Arrange
            var secondary = new Config
                {
                    Age = 12,
                    Name = "Timothy"
                };

            var primary = new Config();

            var expected = new Config
                {
                    Name = "Timothy"
                };

            var configManager = new ConfigurationManager<Config>(
                new DummyConfigurationSource<Config>(secondary),
                new DummyConfigurationSource<Config>(primary));

            configManager.AlwaysSerialize(t => t.Name);

            var actualManager = new DummyConfigurationSource<Config>(new Config());
            configManager.SaveChanges(actualManager);

            Assert.IsTrue(new ConfigComparer().Equals(
                expected, actualManager.SavedObject));
        }
Beispiel #2
0
        public void AlwaysSerialize_WithUnchangedProperty_SerializesPropertyAnyway()
        {
            // Arrange
            var secondary = new Config
            {
                Age  = 12,
                Name = "Timothy"
            };

            var primary = new Config();

            var expected = new Config
            {
                Name = "Timothy"
            };

            var configManager = new ConfigurationManager <Config>(
                new DummyConfigurationSource <Config>(secondary),
                new DummyConfigurationSource <Config>(primary));

            configManager.AlwaysSerialize(t => t.Name);

            var actualManager = new DummyConfigurationSource <Config>(new Config());

            configManager.SaveChanges(actualManager);

            Assert.IsTrue(new ConfigComparer().Equals(
                              expected, actualManager.SavedObject));
        }
Beispiel #3
0
        public void Validation_WhereValidationIsFailingThrowsException()
        {
            // Arrange
            var primary = new Config
            {
                Age  = 12,
                Name = "Timothy"
            };

            var primarySource = new DummyConfigurationSource <Config>(primary);

            // Act
            // ReSharper disable ObjectCreationAsStatement
            new ConfigurationManager <Config>(
                new ConfigValidator(), primarySource);
            // ReSharper restore ObjectCreationAsStatement
        }
Beispiel #4
0
        public void NeverSerialize_WithChangedProperty_DoesNotSerializeProperty()
        {
            var config = new Config
            {
                Name = "Timothy"
            };

            var manager = new ConfigurationManager <Config>(
                new DummyConfigurationSource <Config>(config));

            manager.NeverSerialize(p => p.Occupation);

            manager.Out.Occupation = "Top Secret";

            var actualManager = new DummyConfigurationSource <Config>(new Config());

            manager.SaveChanges(actualManager);

            Assert.IsTrue(new ConfigComparer().Equals(
                              config, actualManager.SavedObject));
        }
Beispiel #5
0
        public void Validation_WithMultipleSourcesWhereValidationIsFailingInFirstButOverriden_DoesNotThrowException()
        {
            // Arrange
            var primary = new Config
            {
                Age  = 12,
                Name = "Timothy"
            };

            var secondary = new Config
            {
                Age = 20,
            };

            var primarySource   = new DummyConfigurationSource <Config>(primary);
            var secondarySource = new DummyConfigurationSource <Config>(secondary);

            // Act
            // ReSharper disable ObjectCreationAsStatement
            new ConfigurationManager <Config>(
                new ConfigValidator(), primarySource, secondarySource);
            // ReSharper restore ObjectCreationAsStatement
        }
Beispiel #6
0
        public void SaveChanges_WherePrimarySourceIsNotLast_MergesPrimarySourceIntoOutput()
        {
            // Arrange
            var primary = new Config
            {
                Age  = 20,
                Name = "Timothy"
            };
            var secondary = new Config
            {
                Name = "Fred"
            };
            var expected = new Config
            {
                Age  = 88,
                Name = "Timothy"
            };

            var primarySource = new DummyConfigurationSource <Config>(primary)
            {
                PrimarySource = true
            };

            // Act
            var newConf = new ConfigurationManager <Config>(
                primarySource,
                new DummyConfigurationSource <Config>(secondary))
            {
                Out = { Age = 88 }
            };

            newConf.SaveChanges();

            // Assert
            Assert.IsTrue(new ConfigComparer().Equals(expected, primarySource.SavedObject));
        }
        public void Validation_WithMultipleSourcesWhereValidationIsFailingInFirstButOverriden_DoesNotThrowException()
        {
            // Arrange
            var primary = new Config
            {
                Age = 12,
                Name = "Timothy"
            };

            var secondary = new Config
            {
                Age = 20,
            };

            var primarySource = new DummyConfigurationSource<Config>(primary);
            var secondarySource = new DummyConfigurationSource<Config>(secondary);

            // Act
            // ReSharper disable ObjectCreationAsStatement
            new ConfigurationManager<Config>(
                new ConfigValidator(), primarySource, secondarySource);
            // ReSharper restore ObjectCreationAsStatement
        }
        public void Validation_WhereValidationIsPassing_DoesNotThrowException()
        {
            // Arrange
            var primary = new Config
            {
                Age = 20,
                Name = "Timothy"
            };

            var primarySource = new DummyConfigurationSource<Config>(primary);

            // Act
            // ReSharper disable ObjectCreationAsStatement
            new ConfigurationManager<Config>(
                new ConfigValidator(), primarySource);
            // ReSharper restore ObjectCreationAsStatement
        }
        public void SaveChanges_WherePrimarySourceIsNotLast_MergesPrimarySourceIntoOutput()
        {
            // Arrange
            var primary = new Config
                {
                    Age = 20,
                    Name = "Timothy"
                };
            var secondary = new Config
                {
                    Name = "Fred"
                };
            var expected = new Config
                {
                    Age = 88,
                    Name = "Timothy"
                };

            var primarySource = new DummyConfigurationSource<Config>(primary)
                {
                    PrimarySource = true
                };

            // Act
            var newConf = new ConfigurationManager<Config>(
                primarySource,
                new DummyConfigurationSource<Config>(secondary))
                {
                    Out = {Age = 88}
                };
            newConf.SaveChanges();

            // Assert
            Assert.IsTrue(new ConfigComparer().Equals(expected, primarySource.SavedObject));
        }
        public void NeverSerialize_WithChangedProperty_DoesNotSerializeProperty()
        {
            var config = new Config
                {
                    Name = "Timothy"
                };

            var manager = new ConfigurationManager<Config>(
                new DummyConfigurationSource<Config>(config));

            manager.NeverSerialize(p => p.Occupation);

            manager.Out.Occupation = "Top Secret";

            var actualManager = new DummyConfigurationSource<Config>(new Config());
            manager.SaveChanges(actualManager);

            Assert.IsTrue(new ConfigComparer().Equals(
                config, actualManager.SavedObject));
        }