예제 #1
0
        public void TestReportTitleConflictWhenBothHaveTitle()
        {
            var schema1 = new JSchema
            {
                Title = "s1"
            };
            var schema2 = new JSchema
            {
                Title = "s2"
            };

            var underTest = new SchemaCombiner();
            var report    = new SchemaComparisionReport();
            var result    = underTest.Apply(schema1, schema2, report);

            var failures = report.GetFailures().ToList();

            Assert.AreEqual(1, failures.Count, "One failure expected");
            Assert.IsInstanceOfType(failures[0], typeof(ValueConflict));

            var valueConflict = (ValueConflict)failures[0];

            Assert.AreEqual("title", valueConflict.PropertyName);
            Assert.AreEqual(schema1, valueConflict.SchemaPart);
            Assert.AreEqual(schema2, valueConflict.SchemaBasePart);
            Assert.AreEqual("s1", valueConflict.Value1);
            Assert.AreEqual("s2", valueConflict.Value2);
        }
예제 #2
0
        public void TestCombineSubSchemaProperties()
        {
            var schema1     = new JSchema();
            var propSchema1 = new JSchema();

            propSchema1.Properties.Add("sub_prop1", new JSchema());
            schema1.Properties.Add("prop1", propSchema1);

            var schema2     = new JSchema();
            var propSchema2 = new JSchema();

            propSchema2.Properties.Add("sub_prop2", new JSchema());
            schema2.Properties.Add("prop1", propSchema2);

            var underTest = new SchemaCombiner();
            var result    = underTest.Apply(schema1, schema2, null);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Properties);
            Assert.AreEqual(1, result.Properties.Count);
            Assert.IsTrue(result.Properties.ContainsKey("prop1"), "Expect the property from both schema.");

            var innerProperties = result.Properties["prop1"].Properties;

            Assert.AreEqual(2, innerProperties.Count);
            Assert.IsTrue(innerProperties.ContainsKey("sub_prop1"), "Expect the property from the first schema.");
            Assert.IsTrue(innerProperties.ContainsKey("sub_prop2"), "Expect the property from the second schema.");
        }
예제 #3
0
		public void TestReportTitleConflictWhenBothHaveTitle()
		{
			var schema1 = new JSchema
			{
				Title = "s1"
			};
			var schema2 = new JSchema
			{
				Title = "s2"
			};

			var underTest = new SchemaCombiner();
			var report = new SchemaComparisionReport();
			var result = underTest.Apply(schema1, schema2, report);

			var failures = report.GetFailures().ToList();

			Assert.AreEqual(1, failures.Count, "One failure expected");
			Assert.IsInstanceOfType(failures[0], typeof(ValueConflict));

			var valueConflict = (ValueConflict)failures[0];
			Assert.AreEqual("title", valueConflict.PropertyName);
			Assert.AreEqual(schema1, valueConflict.SchemaPart);
			Assert.AreEqual(schema2, valueConflict.SchemaBasePart);
			Assert.AreEqual("s1", valueConflict.Value1);
			Assert.AreEqual("s2", valueConflict.Value2);
		}
예제 #4
0
        public void TestTitleUsedFromAvailableSchema()
        {
            const string expectedResult = "title";

            var schema1 = new JSchema();
            var schema2 = new JSchema
            {
                Title = expectedResult
            };

            var underTest = new SchemaCombiner();
            var result    = underTest.Apply(schema1, schema2, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result.Title);
        }
예제 #5
0
		public void TestTitleUsedFromAvailableSchema()
		{
			const string expectedResult = "title";

			var schema1 = new JSchema();
			var schema2 = new JSchema
			{
				Title = expectedResult
			};

			var underTest = new SchemaCombiner();
			var result = underTest.Apply(schema1, schema2, null);

			Assert.IsNotNull(result);
			Assert.AreEqual(expectedResult, result.Title);
		}
예제 #6
0
		public void TestCombineSchemaProperties()
		{
			var schema1 = new JSchema();
			schema1.Properties.Add("prop1", new JSchema());

			var schema2 = new JSchema();
			schema2.Properties.Add("prop2", new JSchema());

			var underTest = new SchemaCombiner();
			var result = underTest.Apply(schema1, schema2, null);

			Assert.IsNotNull(result);
			Assert.IsNotNull(result.Properties);
			Assert.AreEqual(2, result.Properties.Count);
			Assert.IsTrue(result.Properties.ContainsKey("prop1"), "Expect the property from the first schema.");
			Assert.IsTrue(result.Properties.ContainsKey("prop2"), "Expect the property from the second schema.");
		}
        public async Task <JSchema> GetSchemaFromModuleAsync(ModuleDefinition module)
        {
            IEnumerable <TemplateInfo> templates;

            if (module.Skins != null)
            {
                templates = module.Skins.Values;
            }
            else
            {
                templates = Enumerable.Empty <TemplateInfo>();
            }

            if (module.DefaultTemplate != null)
            {
                templates = templates.Union(new[] { module.DefaultTemplate });
            }

            var enumerator = templates.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(null);
            }

            var result = await _schemaProvider.GetSchemaFromTemplateAsync(enumerator.Current).ConfigureAwait(false);

            var report = new SchemaComparisionReport();

            while (enumerator.MoveNext())
            {
                var schema = await _schemaProvider.GetSchemaFromTemplateAsync(enumerator.Current).ConfigureAwait(false);

                result = _schemaCombiner.Apply(result, schema, report);
            }

            return(result);
        }
예제 #8
0
		public void TestCombineSubSchemaProperties()
        {
            var schema1 = new JSchema();
            var propSchema1 = new JSchema();
            propSchema1.Properties.Add("sub_prop1", new JSchema());
            schema1.Properties.Add("prop1", propSchema1);

            var schema2 = new JSchema();
            var propSchema2 = new JSchema();
            propSchema2.Properties.Add("sub_prop2", new JSchema());
            schema2.Properties.Add("prop1", propSchema2);

            var underTest = new SchemaCombiner();
            var result = underTest.Apply(schema1, schema2, null);

            Assert.NotNull(result);
            Assert.NotNull(result.Properties);
            Assert.Equal(1, result.Properties.Count);
            Assert.True(result.Properties.ContainsKey("prop1"), "Expect the property from both schema.");

            var innerProperties = result.Properties["prop1"].Properties;
            Assert.Equal(2, innerProperties.Count);
            Assert.True(innerProperties.ContainsKey("sub_prop1"), "Expect the property from the first schema.");
            Assert.True(innerProperties.ContainsKey("sub_prop2"), "Expect the property from the second schema.");
        }