コード例 #1
0
        public void GetExports_WhenDefinitionsAreResurrected_ShouldTraceInformation()
        {
            using (TraceContext context = new TraceContext(SourceLevels.Information))
            {
                var part1 = PartFactory.CreateImporterExporter("Export", "Import");
                var part2 = PartFactory.CreateImporterExporter("Export", "Import");

                var sourceProvider = ExportProviderFactory.CreateRecomposable();
                var provider       = CreateCatalogExportProvider(part1, part2);
                provider.SourceProvider = sourceProvider;

                EnumerableAssert.IsEmpty(provider.GetExports <object>("Export"));

                // Add the required export to the source provider 'resurrect' the part
                sourceProvider.AddExport("Import", "Value");

                provider.GetExports <object>("Export");

                Assert.AreEqual(4, context.TraceEvents.Count);  // 2 for rejection, 2 for resurrection
                Assert.AreEqual(context.TraceEvents[2].EventType, TraceEventType.Information);
                Assert.AreEqual(context.TraceEvents[3].EventType, TraceEventType.Information);
                Assert.AreEqual(context.TraceEvents[2].Id, TraceId.Rejection_DefinitionResurrected);
                Assert.AreEqual(context.TraceEvents[3].Id, TraceId.Rejection_DefinitionResurrected);
            }
        }
コード例 #2
0
            public void OnExportsChanged(object sender, ExportsChangeEventArgs args)
            {
                Assert.IsTrue(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    EnumerableAssert.IsEmpty(args.AddedExports);
                }
                else
                {
                    foreach (var add in this._expectedAdds)
                    {
                        Assert.IsTrue(this._container.IsPresent(add), "Added exports should be added during changed");
                    }
                }

                if (this._expectedRemoves == null)
                {
                    EnumerableAssert.IsEmpty(args.RemovedExports);
                }
                else
                {
                    foreach (var remove in this._expectedRemoves)
                    {
                        Assert.IsFalse(this._container.IsPresent(remove), "Removed exports should be removed during changed");
                    }
                }

                Assert.IsNull(args.AtomicComposition);

                this._changedEventCount++;
            }
コード例 #3
0
        public void EmailValidationTest()
        {
            Contact contact1 = new Contact()
            {
                Name = nameof(Contact.Name), Email = "*****@*****.**"
            };
            ValidationContext       validationContext1 = new ValidationContext(contact1);
            List <ValidationResult> results1           = new List <ValidationResult>();

#if !WINDOWS_UWP && !ANDROID
            Assert.IsTrue(Validator.TryValidateObject(contact1, validationContext1, results1, true));
            EnumerableAssert.IsEmpty(results1);
#endif

            Contact contact2 = new Contact()
            {
                Name = nameof(Contact.Name), Email = "user"
            };
            ValidationContext       validationContext2 = new ValidationContext(contact2);
            List <ValidationResult> results2           = new List <ValidationResult>();
#if !WINDOWS_UWP && !ANDROID
            Assert.IsFalse(Validator.TryValidateObject(contact2, validationContext2, results2, true));
            Assert.AreEqual(nameof(Contact.Email), results2.Single().MemberNames.Single());
            Assert.AreEqual(Resources.EmailInvalid, results2.Single().ErrorMessage);
#endif
        }
コード例 #4
0
        public void GetExports_AfterResurrectedDefinitionHasBeenRemovedAndReaddedToCatalog_ShouldNotBeTreatedAsRejected()
        {
            var definition1 = PartDefinitionFactory.Create(PartFactory.CreateImporterExporter("Export", "Import"));
            var definition2 = PartDefinitionFactory.Create(PartFactory.CreateImporterExporter("Export", "Import"));
            var catalog     = CatalogFactory.CreateMutable(definition1, definition2);

            var provider       = CreateCatalogExportProvider(catalog);
            var sourceProvider = ExportProviderFactory.CreateRecomposable();

            provider.SourceProvider = sourceProvider;

            var exports = provider.GetExports <object>("Export");

            EnumerableAssert.IsEmpty(exports, "definition1 and definition2 should have been rejected.");

            // Resurrect both definitions
            sourceProvider.AddExport("Import", new object());

            exports = provider.GetExports <object>("Export");

            Assert.AreEqual(2, exports.Count(), "definition1 and definition2 should have been resurrected.");

            catalog.RemoveDefinition(definition1);

            exports = provider.GetExports <object>("Export");
            Assert.AreEqual(1, exports.Count(), "definition1 should have been removed.");

            catalog.AddDefinition(definition1);

            exports = provider.GetExports <object>("Export");

            Assert.AreEqual(2, exports.Count(), "definition1 and definition2 should be both present.");
        }
コード例 #5
0
            public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.IsTrue(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    EnumerableAssert.IsEmpty(args.AddedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    EnumerableAssert.IsEmpty(args.RemovedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.IsNull(args.AtomicComposition);
                Assert.IsTrue(ContainsChanges(), "The catalog should contain the changes");

                this._changedEventCount++;
            }
コード例 #6
0
        public void Constructor2_NullAsMetadataArgument_ShouldSetRequiredMetadataToEmptyEnumerable()
        {
            var requiredMetadata = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("key", null) };
            var definition       = new ContractBasedImportDefinition("metadata", (string)null, requiredMetadata, ImportCardinality.ExactlyOne, false, false, CreationPolicy.Any, null);

            EnumerableAssert.IsEmpty(definition.Metadata);
        }
コード例 #7
0
        public void ReadToEnd_Empty()
        {
            using (var stream = new MemoryStream())
            {
                EnumerableAssert.IsEmpty(stream.ReadToEnd());
                Assert.AreEqual(0, stream.Position);
            }

            var bytes = new byte[] { 243, 75, 31, 139, 26 };

            using (var stream = new MemoryStream(bytes))
            {
                stream.Seek(0, SeekOrigin.End);
                EnumerableAssert.IsEmpty(stream.ReadToEnd());
                Assert.AreEqual(bytes.Length, stream.Position);
            }

            bytes = CachedRandom.Current.NextBytes(4 * 1024 * 1024);
            using (var stream = new MemoryStream(bytes))
            {
                stream.Seek(0, SeekOrigin.End);
                EnumerableAssert.IsEmpty(stream.ReadToEnd());
                Assert.AreEqual(bytes.Length, stream.Position);
            }
        }
コード例 #8
0
        public void Test_DrawablePath()
        {
            DrawablePath path = new DrawablePath();

            EnumerableAssert.IsEmpty(path.Paths);

            ((IDrawingWand)path).Draw(null);
        }
コード例 #9
0
        public void ToResult_NullAsErrorsArgument_ShouldReturnResultWithEmptyErrorsProperty()
        {
            var result = CreateCompositionResult <string>((IEnumerable <CompositionError>)null);

            var copy = result.ToResult();

            EnumerableAssert.IsEmpty(copy.Errors);
        }
コード例 #10
0
        public void ToResultOfT_EmptyEnumerableAsErrorsArgument_ShouldReturnResultWithEmptyErrorsProperty()
        {
            var result = CreateCompositionResult <string>(Enumerable.Empty <CompositionError>());

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

            EnumerableAssert.IsEmpty(copy.Errors);
        }
コード例 #11
0
        public void Constructor_EmptyDictionaryAsDictionaryArgument_ShouldSetItemsPropertyToEmptyEnumerable()
        {
            var dictionary = CreateReadOnlyDictionary <string, object>();

            var proxy = new ReadOnlyDictionaryDebuggerProxy <string, object>(dictionary);

            EnumerableAssert.IsEmpty(proxy.Items);
        }
コード例 #12
0
        public void FindFactories_NoFactories_IsEmpty()
        {
            IAssembly assembly = MockAssemblyFactory.CreateMockAssembly();

            _mocks.ReplayAll();
            FactoryMap map = _target.FindFactories(assembly);

            EnumerableAssert.IsEmpty(map.Factories);
        }
コード例 #13
0
            public void ShouldReturnEmptyCollectionWhenDataHasNoValues()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0 };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
            }
コード例 #14
0
            public void ShouldReturnEmptyCollectionWhenDataIsEmpty()
            {
                var reader = new ExifReader();
                var data   = new byte[] { };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
            }
コード例 #15
0
            public void ShouldNotThrowExceptionWhenEnumerableImagesIsEmpty()
            {
                using (var images = new MagickImageCollection())
                {
                    images.AddRange(new IMagickImage <QuantumType> [0]);

                    EnumerableAssert.IsEmpty(images);
                }
            }
コード例 #16
0
            public void ShouldReadProfileValues()
            {
                var bytes = ToBytes('8', 'B', 'I', 'M', (short)2000, (short)0, 1, (byte)0);

                var profile = new EightBimProfile(bytes);

                EnumerableAssert.IsSingle(profile.Values);
                EnumerableAssert.IsEmpty(profile.ClipPaths);
            }
コード例 #17
0
        public void IsEmpty()
        {
            var bytes = new byte[] { 243, 75, 31, 139, 26 };

            EnumerableAssert.IsEmpty(new byte[0]);
            EnumerableAssert.IsEmpty(bytes.Where(b => b == 0));
            ExceptionAssert.ThrowsAssertFailed(() => EnumerableAssert.IsEmpty(bytes));
            ExceptionAssert.ThrowsAssertFailed(() => EnumerableAssert.IsEmpty(bytes.Where(b => b == 31)));
        }
コード例 #18
0
            public void ShouldCheckTypeOfJPEGInterchangeFormatLength()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0 };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
                Assert.AreEqual(2, reader.InvalidTags.Count);
            }
コード例 #19
0
            public void ShouldCheckArraySize()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 148, 1, 1, 0, 255, 255, 255, 255, 26, 0, 0, 0, 31, 0, 0, 0, 42 };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
                EnumerableAssert.IsSingle(reader.InvalidTags);
            }
コード例 #20
0
        public void Constructor1_PropertiesShouldBeSetAndEmpty()
        {
            CompositionBatch batch = new CompositionBatch();

            Assert.IsNotNull(batch.PartsToAdd);
            EnumerableAssert.IsEmpty(batch.PartsToAdd);

            Assert.IsNotNull(batch.PartsToRemove);
            EnumerableAssert.IsEmpty(batch.PartsToRemove);
        }
コード例 #21
0
 public void ShouldReturnEmptyCollectionWhenCollectionIsEmpty()
 {
     using (var images = new MagickImageCollection())
     {
         using (var clones = images.Clone())
         {
             EnumerableAssert.IsEmpty(clones);
         }
     }
 }
コード例 #22
0
        public void CreatePartDefinition_NoConstructorBecauseStatic_ShouldHaveNullConstructor()
        {
            var definition = CreateDefinition(typeof(StaticExportClass));

            ConstructorInfo constructor = definition.GetConstructor();

            Assert.IsNull(constructor);

            EnumerableAssert.IsEmpty(definition.ImportDefinitions.OfType <ReflectionParameterImportDefinition>());
        }
コード例 #23
0
            public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DeskewSettings();

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsEmpty(image.ArtifactNames);
                }
            }
コード例 #24
0
        public void CreatePartDefinition_TwoZeroParameterConstructors_ShouldPickNonStaticOne()
        {
            var definition = CreateDefinition(typeof(ClassWithTwoZeroParameterConstructors));

            ConstructorInfo constructor = definition.GetConstructor();

            Assert.IsNotNull(constructor);
            Assert.IsFalse(constructor.IsStatic);

            EnumerableAssert.IsEmpty(definition.ImportDefinitions.OfType <ReflectionParameterImportDefinition>());
        }
コード例 #25
0
        public void CreatePartDefinition_OneDefaultConstructorAsPartTypeArgument_ShouldSetConstructorToDefault()
        {
            var definition = CreateDefinition(typeof(PublicComponentWithPublicExports));

            ConstructorInfo constructor = definition.GetConstructor();

            Assert.IsNotNull(constructor);

            EnumerableAssert.IsEmpty(constructor.GetParameters());
            EnumerableAssert.IsEmpty(definition.ImportDefinitions.OfType <ReflectionParameterImportDefinition>());
        }
コード例 #26
0
        public void AddPart_PartIsInPartsToAdd()
        {
            CompositionBatch batch = new CompositionBatch();
            ComposablePart   part  = PartFactory.Create();

            batch.AddPart(part);

            Assert.AreEqual(1, batch.PartsToAdd.Count);
            Assert.AreSame(part, batch.PartsToAdd[0]);

            EnumerableAssert.IsEmpty(batch.PartsToRemove);
        }
コード例 #27
0
            public void ShouldRemoveAllValues()
            {
                var profile = new IptcProfile();

                profile.SetValue(IptcTag.Byline, "test");
                profile.SetValue(IptcTag.Byline, "test2");

                var result = profile.RemoveValue(IptcTag.Byline);

                Assert.IsTrue(result);
                EnumerableAssert.IsEmpty(profile.Values);
            }
コード例 #28
0
        public void CreateEmpty()
        {
            string path = Path.GetTempFileName();

            File.WriteAllText(path, "Hello world!");
            FileOperation.CreateEmpty(path);
            EnumerableAssert.IsEmpty(File.ReadAllBytes(path), "File was not overwritten as empty.");

            File.Delete(path);
            FileOperation.CreateEmpty(path);
            Assert.IsTrue(File.Exists(path), "File was not created as empty.");
            EnumerableAssert.IsEmpty(File.ReadAllBytes(path), "File was not created as empty.");
        }
コード例 #29
0
            public void ShouldAllowInvalidValues()
            {
                var bytes = ToBytes('8', 'B', 'I', 'M', (short)42, (byte)0, 1);

                var profile = new EightBimProfile(bytes);

                EnumerableAssert.IsEmpty(profile.Values);

                bytes = ToBytes('8', 'B', 'I', 'M', (short)42, (short)0, -1);

                profile = new EightBimProfile(bytes);
                EnumerableAssert.IsEmpty(profile.Values);
            }
コード例 #30
0
            public void ShouldRemoveAndDisposeTheImages()
            {
                var image = new MagickImage(MagickColors.Red, 10, 10);

                var collection = new MagickImageCollection
                {
                    image,
                };

                collection.Dispose();

                EnumerableAssert.IsEmpty(collection);
                Assert.IsTrue(image.IsDisposed);
            }