public void CalculateGetHashCode()
        {
            Foo foo = new Foo();

            int expectedHashCode =
                EqualityExtensions.Equality <Foo>(foo).GetHashCode(new object[] { foo.I, foo.S, foo.Bar });

            Assert.Equal(expectedHashCode, foo.GetHashCode());
        }
Пример #2
0
        public void OverridesGetHashCode()
        {
            var foo = new FooComponent {
                I = 1
            };

            int expectedHash = EqualityExtensions.Equality <Component>(foo).GetHashCode(new object[] { foo.I });

            Assert.Equal(expectedHash, foo.GetHashCode());
        }
        public void Constructor5_ValueAsErrorsArgument_ShouldSetErrorsProperty()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", new Exception(), e);

                EqualityExtensions.CheckEquals(e, exception.Errors);
            }
        }
Пример #4
0
        [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetCatalogs();

            foreach (var e in expectations)
            {
                var proxy = new ComposablePartCatalogDebuggerProxy(e);

                EqualityExtensions.CheckEquals(e.Parts, proxy.Parts);
            }
        }
        public void Parts_DelegateToCatalog()
        {
            var         parts   = new TypeCatalog(typeof(FooImpl), typeof(FooImpl2), typeof(FooImpl2)).Parts;
            var         exports = parts.Select(p => Tuple.Create(p, p.ExportDefinitions.First()));
            TestCatalog catalog = new TestCatalog(
                () => parts,
                () => exports);

            CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null);

            EqualityExtensions.CheckEquals(parts, scope.Parts);
        }
Пример #6
0
        [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetAssemblies();

            foreach (var e in expectations)
            {
                var catalog = CreateAssemblyCatalog(e);

                var proxy = new AssemblyCatalogDebuggerProxy(catalog);

                EqualityExtensions.CheckSequenceEquals(catalog.Parts, proxy.Parts);
            }
        }
Пример #7
0
        public void Constructor2_PropertiesShouldBeSetAndMatchArguments()
        {
            ComposablePart[] partsToAdd    = new ComposablePart[] { PartFactory.Create(), PartFactory.Create(), PartFactory.Create() };
            ComposablePart[] partsToRemove = new ComposablePart[] { PartFactory.Create(), PartFactory.Create(), PartFactory.Create() };

            CompositionBatch batch = new CompositionBatch(partsToAdd, partsToRemove);

            Assert.NotNull(batch.PartsToAdd);
            Assert.NotNull(batch.PartsToRemove);

            EqualityExtensions.CheckEquals(batch.PartsToAdd, partsToAdd);
            EqualityExtensions.CheckEquals(batch.PartsToRemove, partsToRemove);
        }
        public void ToResultOfT_ValueAsErrorsArgument_ShouldReturnResultWithErrorsPropertySet()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var result = CreateCompositionResult <string>(e);

                var copy = result.ToResult <string>();

                EqualityExtensions.CheckEquals(result.Errors, copy.Errors);
            }
        }
Пример #9
0
        public void MergeErrors_ValueAsErrorArgumentWhenMergedWithResultWithErrors_ShouldReturnResultWithCombinedErrors()
        {
            var result       = CreateCompositionResult(2);
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var mergedResult = result.MergeErrors(e);
                var mergedErrors = result.Errors.Concat(e);

                EqualityExtensions.CheckEquals(mergedErrors, mergedResult.Errors);
                Assert.False(mergedResult.Succeeded);
            }
        }
Пример #10
0
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetAssemblies();

            foreach (var e in expectations)
            {
                string directoryPath = GetTemporaryDirectory(e.Location);
                var    catalog       = CreateDirectoryCatalog(directoryPath);

                var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                EqualityExtensions.CheckEquals(catalog.Parts, proxy.Parts);
            }
        }
Пример #11
0
        public void MergeError_ValueAsErrorArgumentWhenMergedWithResultWithEmptyErrors_ShouldReturnResultWithCombinedErrors()
        {
            var result       = CreateCompositionResult(Enumerable.Empty <CompositionError>());
            var expectations = Expectations.GetEnumValues <CompositionErrorId>();

            foreach (var e in expectations)
            {
                var error = ErrorFactory.Create(e);

                var mergedResult = result.MergeError(error);
                var mergedErrors = result.Errors.Concat(new CompositionError[] { error });

                EqualityExtensions.CheckEquals(mergedErrors, mergedResult.Errors);
                Assert.False(mergedResult.Succeeded);
            }
        }
Пример #12
0
        public void MergeResult_ResultWithErrorsAsResultArgument_ShouldReturnResultWithCombinedErrors()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var result1 = CreateCompositionResult(e);
                var result2 = CreateCompositionResult(e);

                var mergedResult = result1.MergeResult(result2);
                var mergedErrors = result1.Errors.Concat(result2.Errors);

                EqualityExtensions.CheckEquals(mergedErrors, mergedResult.Errors);
                Assert.Equal(mergedResult.Succeeded, result1.Succeeded | result2.Succeeded);
            }
        }
Пример #13
0
        public void LoadedFiles_ContainsMultipleDllsAndSomeNonDll_ShouldOnlyContainDlls()
        {
            // Add one text file
            using (File.CreateText(Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test.txt"))) { }

            // Add two dll's
            string dll1 = Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test1.dll");
            string dll2 = Path.Combine(TemporaryFileCopier.GetTemporaryDirectory(), "Test2.dll");

            File.Copy(Assembly.GetExecutingAssembly().Location, dll1);
            File.Copy(Assembly.GetExecutingAssembly().Location, dll2);

            var cat = new DirectoryCatalog(TemporaryFileCopier.GetTemporaryDirectory());

            EqualityExtensions.CheckEquals(new string[] { dll1.ToUpperInvariant(), dll2.ToUpperInvariant() },
                                           cat.LoadedFiles);
        }
Пример #14
0
        public void Parts_ShouldNotCacheUnderlyingParts()
        {
            var catalog = CatalogFactory.CreateAggregateCatalog();
            var proxy   = CreateComposablePartCatalogDebuggerProxy(catalog);

            Assert.Empty(proxy.Parts);

            var expectations = Expectations.GetCatalogs();

            foreach (var e in expectations)
            {
                catalog.Catalogs.Add(e);

                EqualityExtensions.CheckEquals(catalog.Parts, proxy.Parts);

                catalog.Catalogs.Remove(e);
            }
        }
            public void VerifyImport(params int[] expectedValues)
            {
                object[] untypedExpectedValues = expectedValues.Cast <object>().ToArray();

                ExportsAssert.AreEqual(CollectionPlain, untypedExpectedValues);
                ExportsAssert.AreEqual(CollectionPlainRawMetadata, untypedExpectedValues);
                EqualityExtensions.IsTrueForAll(CollectionPlainRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                Assert.Empty(CollectionPlainEmpty);
                Assert.Empty(CollectionPlainEmptyRawMetadata);

                // Add a new Export to this collection to ensure that it doesn't
                // modifiy the other collections because they should each have there
                // own collection instance
                CollectionPlain.Add(ExportFactory.Create <object>("Value"));

                ExportsAssert.AreEqual(CollectionTyped, expectedValues);
                ExportsAssert.AreEqual(CollectionTypedRawMetadata, expectedValues);
                EqualityExtensions.IsTrueForAll(CollectionTypedRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                Assert.Empty(CollectionTypedEmpty);

                ExportsAssert.AreEqual(CollectionTypedMetadata, expectedValues);
                EqualityExtensions.IsTrueForAll(CollectionTypedMetadata, i => true == i.Metadata.PropertyName);
                Assert.Empty(CollectionTypedMetadataEmpty);

                EnumerableAssert.AreEqual(ReadWriteEnumerable, expectedValues);
                Assert.Empty(ReadWriteEnumerableEmpty);

                ExportsAssert.AreEqual(MetadataUntypedEnumerable, untypedExpectedValues);
                ExportsAssert.AreEqual(MetadataUntypedEnumerableRawMetadata, untypedExpectedValues);
                EqualityExtensions.IsTrueForAll(MetadataUntypedEnumerableRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                Assert.Empty(MetadataUntypedEnumerableEmpty);
                Assert.Empty(MetadataUntypedEnumerableEmptyRawMetadata);

                ExportsAssert.AreEqual(MetadataTypedEnumerable, expectedValues);
                ExportsAssert.AreEqual(MetadataTypedEnumerableRawMetadata, expectedValues);
                EqualityExtensions.IsTrueForAll(MetadataTypedEnumerableRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                Assert.Empty(MetadataTypedEnumerableEmpty);

                ExportsAssert.AreEqual(MetadataFullyTypedEnumerable, expectedValues);
                EqualityExtensions.IsTrueForAll(MetadataFullyTypedEnumerable, i => true == i.Metadata.PropertyName);
                Assert.Empty(MetadataFullyTypedEnumerableEmpty);
            }
Пример #16
0
        public void TestCollectionEqual()
        {
            Assert.IsTrue(EqualityExtensions.NullableSequenceEqual <object>(null, null));
            Assert.IsTrue(EqualityExtensions.NullableSequenceEqual(null, new object[0]));
            Assert.IsTrue(new object[0].NullableSequenceEqual(null));
            Assert.IsTrue(EqualityExtensions.NullableCollectionEqual <object>(null, null));
            Assert.IsTrue(EqualityExtensions.NullableCollectionEqual(null, new object[0]));
            Assert.IsTrue(new object[0].NullableCollectionEqual(null));

            Assert.IsTrue(new object[0].NullableSequenceEqual(new object[0]));
            Assert.IsTrue(new string[0].NullableSequenceEqual(new object[0]));
            Assert.IsFalse(new object[0].NullableSequenceEqual(new object[1]));
            Assert.IsTrue(new object[0].NullableCollectionEqual(new object[0]));
            Assert.IsTrue(new string[0].NullableCollectionEqual(new object[0]));
            Assert.IsFalse(new object[0].NullableCollectionEqual(new object[1]));

            var one = new[] { "one", "two", "three" };
            var two = new[] { "one", "two", "three" };

            Assert.IsTrue(one.NullableSequenceEqual(one));   // Reference equality shortcut.
            Assert.IsTrue(one.NullableCollectionEqual(one)); // Reference equality shortcut.
            Assert.IsTrue(one.NullableSequenceEqual(two));
            Assert.IsTrue(one.NullableCollectionEqual(two));

            Array.Reverse(two);
            Assert.IsFalse(one.NullableSequenceEqual(two));
            Assert.IsTrue(one.NullableCollectionEqual(two));

            var ione = new[] { 1, 2, 2, 3 };
            var itwo = new[] { 1, 2, 3, 4 };

            Assert.IsFalse(ione.NullableSequenceEqual(itwo));
            Assert.IsFalse(itwo.NullableSequenceEqual(ione));
            Assert.IsFalse(ione.NullableCollectionEqual(itwo));
            Assert.IsFalse(itwo.NullableCollectionEqual(ione));

            itwo = new[] { 6, 7, 8, 9 };
            Assert.IsFalse(ione.NullableSequenceEqual(itwo));
            Assert.IsFalse(ione.NullableCollectionEqual(itwo));
        }
Пример #17
0
        public void FilteredNotifications()
        {
            var catalog1 = CreateSubCatalog1();
            var catalog2 = CreateSubCatalog2();
            var catalog  = new AggregateCatalog();

            var filter1 = catalog.Filter(p => p.Exports <IContract1>());
            var filter2 = catalog.Filter(p => p.Exports <IContract2>());

            bool filter1Ing = false;
            bool filter1Ed  = false;
            bool filter2Ing = false;
            bool filter2Ed  = false;

            ComposablePartCatalogChangeEventArgs edArgs  = null;
            ComposablePartCatalogChangeEventArgs ingArgs = null;

            filter1.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.Same(filter1, s);
                Assert.False(filter1Ing);
                Assert.False(filter1Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter1Ing = true;
                ingArgs    = a;
            };

            filter1.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter1Ing);
                Assert.False(filter1Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter1Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            filter2.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.Same(filter2, s);
                Assert.False(filter2Ing);
                Assert.False(filter2Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter2Ing = true;
                ingArgs    = a;
            };

            filter2.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter2Ing);
                Assert.False(filter2Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter2Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            //at first everything is empty

            // add the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog1);
            Assert.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

            Assert.Equal(2, edArgs.AddedDefinitions.Count());
            Assert.Equal(0, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(edArgs.AddedDefinitions, catalog1.Parts);

            // add the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog2);
            Assert.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

            Assert.Equal(2, edArgs.AddedDefinitions.Count());
            Assert.Equal(0, edArgs.RemovedDefinitions.Count());
            Assert.Equal(2, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(edArgs.AddedDefinitions, catalog2.Parts);

            // remove the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog2);
            Assert.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

            Assert.Equal(0, edArgs.AddedDefinitions.Count());
            Assert.Equal(2, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(edArgs.RemovedDefinitions, catalog2.Parts);

            // remove the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog1);
            Assert.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

            Assert.Equal(0, edArgs.AddedDefinitions.Count());
            Assert.Equal(2, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(0, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(edArgs.RemovedDefinitions, catalog1.Parts);
        }