コード例 #1
0
        public void Constructor4_ValuesAsErrorsArgument_ShouldSetErrorsProperty()
        {
            var errors = Expectations.GetCompositionErrors();

            foreach (var e in errors)
            {
                var result = new CompositionResult <string>(e);

                EnumerableAssert.AreEqual(e, result.Errors);
            }
        }
コード例 #2
0
ファイル: ReadOnlyDictionaryTests.cs プロジェクト: zqb971/mef
        public void GetEnumerator()
        {
            var dictionary         = GetWritableDictionaryWithData();
            var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
            IEnumerable <KeyValuePair <string, object> > genericEnumerable = readOnlyDictionary;

            EnumerableAssert.AreEqual(genericEnumerable, dictionary);
            IEnumerable weakEnumerable = (IEnumerable)readOnlyDictionary;

            EnumerableAssert.AreEqual(weakEnumerable, dictionary);
        }
コード例 #3
0
        public void Constructor_ValueAsDictionaryArgument_ShouldSetItemsProperty()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var proxy = new ReadOnlyDictionaryDebuggerProxy <string, object>(CreateReadOnlyDictionary(e));

                EnumerableAssert.AreEqual(e, proxy.Items);
            }
        }
コード例 #4
0
        public void Constructor2_DictionaryAsMetadataArgument_ShouldSetMetadataProperty()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var definition = new ExportDefinition("Contract", e);

                EnumerableAssert.AreEqual(e, definition.Metadata);
            }
        }
コード例 #5
0
        public void Constructor2_ValueAsMetadataArgument_ShouldSetMetadataProperty()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var definition = new ContractBasedImportDefinition("ContractName", (string)null, null, ImportCardinality.ExactlyOne, false, false, CreationPolicy.Any, e);

                EnumerableAssert.AreEqual(e, definition.Metadata);
            }
        }
コード例 #6
0
ファイル: ExportTests.cs プロジェクト: rsumner31/corefx2
        public void Constructor4_DictionaryAsMetadataArgument_ShouldSetDefinitionMetadataProperty()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var export = new Export("ContractName", e, () => null);

                EnumerableAssert.AreEqual(e, export.Definition.Metadata);
            }
        }
コード例 #7
0
        public void Constructor5_ArrayAsAsErrorsArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var error  = CreateCompositionError();
            var errors = new CompositionError[] { error };

            var exception = new CompositionException("Message", new Exception(), errors);

            errors[0] = null;

            EnumerableAssert.AreEqual(exception.Errors, error);
        }
コード例 #8
0
        public void RequiredNonSharedImporter_ShouldFilterShared()
        {
            var container = CreateDefaultContainer();

            var importer = container.GetExportedValue <RequiredNonSharedImporter>();

            EnumerableAssert.AreEqual(
                importer.Exports.Select(obj => obj.GetType()),
                typeof(CreationPolicyAnyExportImplicit),
                typeof(CreationPolicyAnyExportExplicit),
                typeof(CreationPolicyNonSharedExport));
        }
コード例 #9
0
        public void Constructor_ValueAsCatalogArgument_ShouldSetAssemblyProperty()
        {
            var expectations = Expectations.GetAssemblies();

            using (TemporaryFileCopier copier = new TemporaryFileCopier(expectations.Select(assembly => assembly.Location).ToArray()))
            {
                var catalog = CreateDirectoryCatalog(copier.DirectoryPath);
                var proxy   = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                EnumerableAssert.AreEqual(expectations, proxy.Assemblies);
            }
        }
コード例 #10
0
        private static void AssertCanParse(Expression <Func <ExportDefinition, bool> > constraint, string contractName, IEnumerable <KeyValuePair <string, Type> > requiredMetadata)
        {
            Assert.IsNotNull(constraint);

            string contractNameResult = null;
            IEnumerable <KeyValuePair <string, Type> > requiredMetadataResult = null;
            bool success = ContraintParser.TryParseConstraint(constraint, out contractNameResult, out requiredMetadataResult);

            Assert.IsTrue(success);
            Assert.AreEqual(contractName, contractNameResult);
            EnumerableAssert.AreEqual(requiredMetadata, requiredMetadataResult);
        }
コード例 #11
0
        public void TestFlatten()
        {
            IEnumerable <IEnumerable <int> > source = new[]
            {
                new[] { 1, 3, 7 },
                new[] { 2, 4 }
            };

            IEnumerable <int> flattened = source.Flatten();

            EnumerableAssert.AreEqual(new[] { 1, 3, 7, 2, 4 }, flattened);
        }
コード例 #12
0
ファイル: ExportTests.cs プロジェクト: zhy29563/MyMEF
        public void Metadata_DerivedExportDefinition_ShouldReturnDefinitionMetadata()
        {
            var expectations = Expectations.GetMetadata();

            foreach (var e in expectations)
            {
                var definition = ExportDefinitionFactory.Create("ContractName", e);

                var export = new DerivedExport(definition);

                EnumerableAssert.AreEqual(e, export.Metadata);
            }
        }
コード例 #13
0
            public void then_session_is_updated_with_new_eventSources()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     = new EventSourceSettings(currentEventSource.Name, level: currentEventSource.Level, matchAnyKeyword: EventKeywords.AuditSuccess);

                this.Sut.UpdateSession(new List <EventSourceSettings> {
                    newEventSource
                });

                Assert.AreEqual(newEventSource.Level, currentEventSource.Level);
                Assert.AreEqual(newEventSource.MatchAnyKeyword, currentEventSource.MatchAnyKeyword);
                EnumerableAssert.AreEqual(newEventSource.Arguments, currentEventSource.Arguments);
                EnumerableAssert.AreEqual(newEventSource.ProcessNamesToFilter, currentEventSource.ProcessNamesToFilter);
            }
コード例 #14
0
        public void ImportSingleIntoCollection()
        {
            var container = ContainerFactory.Create();
            var importer  = new Int32CollectionImporter();
            var exporter  = new Int32Exporter(42);

            CompositionBatch batch = new CompositionBatch();

            batch.AddPart(importer);
            batch.AddPart(exporter);
            container.Compose(batch);

            EnumerableAssert.AreEqual(importer.Values, 42);
        }
コード例 #15
0
            public void VerifyImports(params T[] expectedValues)
            {
                // Fields
                EnumerableAssert.AreEqual(IEnumerableOfTField, expectedValues);
                EnumerableAssert.AreEqual(IEnumerableOfObjectField, expectedValues.Cast <object>());
                EnumerableAssert.AreEqual(ArrayOfTField, expectedValues);
                EnumerableAssert.AreEqual(ArrayOfObjectField, expectedValues.Cast <object>());

                // Properties
                EnumerableAssert.AreEqual(IEnumerableOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(IEnumerableOfObjectProperty, expectedValues.Cast <object>());
                EnumerableAssert.AreEqual(ArrayOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ArrayOfObjectProperty, expectedValues.Cast <object>());
            }
コード例 #16
0
        public void ImportCollectionsNameless()
        {
            // Verifing that the contract name gets the correct value
            var container               = ContainerFactory.Create();
            NamelessImporter importer   = new NamelessImporter();
            NamelessExporter exporter42 = new NamelessExporter(42);
            NamelessExporter exporter0  = new NamelessExporter(0);

            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(importer, exporter42, exporter0);
            container.Compose(batch);

            EnumerableAssert.AreEqual(importer.ReadWriteIList, 42, 0);
        }
コード例 #17
0
        public void TestCircuitEvaluation()
        {
            BitArray[] inputs =
            {
                BitArray.FromBinaryString("0111010011"),
                BitArray.FromBinaryString("1101100010"),
                BitArray.FromBinaryString("0111110011")
            };

            Bit[] sequentialInput = inputs.SelectMany(bits => bits).ToArray();

            CircuitBuilder builder = new CircuitBuilder();
            SetIntersectionCircuitRecorder setIntersectionCircuitRecorder =
                new SetIntersectionCircuitRecorder(inputs.Length, inputs[0].Length);

            setIntersectionCircuitRecorder.Record(builder);

            Circuit        circuit        = builder.CreateCircuit();
            ForwardCircuit forwardCircuit = new ForwardCircuit(circuit);

            ICircuitEvaluator <Bit> evaluator = new LocalCircuitEvaluator();
            ReportingBatchCircuitEvaluator <Bit> batchCircuitEvaluator =
                new ReportingBatchCircuitEvaluator <Bit>(new BatchCircuitEvaluator <Bit>(evaluator));

            BitArray lazyEvaluationOutput     = new BitArray(circuit.Evaluate(evaluator, sequentialInput));
            BitArray forwardEvaluationOutput  = new BitArray(forwardCircuit.Evaluate(batchCircuitEvaluator, sequentialInput));
            BitArray expectedEvaluationOutput = BitArray.FromBinaryString("01010000101100");

            EnumerableAssert.AreEqual(
                expectedEvaluationOutput,
                lazyEvaluationOutput
                );

            EnumerableAssert.AreEqual(
                expectedEvaluationOutput,
                forwardEvaluationOutput
                );

            int[] actualBatchSizes   = batchCircuitEvaluator.BatchSizes;
            int[] expectedBatchSizes = { 10, 10, 9, 9, 8 };

            EnumerableAssert.AreEqual(
                expectedBatchSizes,
                actualBatchSizes
                );
        }
コード例 #18
0
        public void ReadToEnd_Entire()
        {
            var bytes = new byte[] { 243, 75, 31, 139, 26 };

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

            bytes = CachedRandom.Current.NextBytes(4 * 1024 * 1024);
            using (var stream = new MemoryStream(bytes))
            {
                EnumerableAssert.AreEqual(bytes, stream.ReadToEnd());
                Assert.AreEqual(bytes.Length, stream.Position);
            }
        }
コード例 #19
0
            public void VerifyImport(params int[] expectedValues)
            {
                object[] untypedExpectedValues = expectedValues.Cast <object>().ToArray();

                ExportsAssert.AreEqual(CollectionPlain, untypedExpectedValues);
                ExportsAssert.AreEqual(CollectionPlainRawMetadata, untypedExpectedValues);
                EnumerableAssert.IsTrueForAll(CollectionPlainRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(CollectionPlainEmpty);
                EnumerableAssert.IsEmpty(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);
                EnumerableAssert.IsTrueForAll(CollectionTypedRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(CollectionTypedEmpty);

                ExportsAssert.AreEqual(CollectionTypedMetadata, expectedValues);
#if !SILVERLIGHT // Silverlight doesn't support strongly typed metadata
                EnumerableAssert.IsTrueForAll(CollectionTypedMetadata, i => true == i.Metadata.PropertyName);
#endif //!SILVERLIGHT
                EnumerableAssert.IsEmpty(CollectionTypedMetadataEmpty);

                EnumerableAssert.AreEqual(ReadWriteEnumerable, expectedValues);
                EnumerableAssert.IsEmpty(ReadWriteEnumerableEmpty);

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

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

                ExportsAssert.AreEqual(MetadataFullyTypedEnumerable, expectedValues);
#if !SILVERLIGHT // Silverlight doesn't support strongly typed metadata
                EnumerableAssert.IsTrueForAll(MetadataFullyTypedEnumerable, i => true == i.Metadata.PropertyName);
#endif //!SILVERLIGHT
                EnumerableAssert.IsEmpty(MetadataFullyTypedEnumerableEmpty);
            }
コード例 #20
0
        public void Items_ShouldNotCacheUnderlyingItems()
        {
            var dictionary = new Dictionary <string, object>();

            dictionary.Add("Name", "Value");

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

            EnumerableAssert.AreEqual(dictionary, proxy.Items);

            dictionary.Add("AnotherName", "Value");

            EnumerableAssert.AreEqual(dictionary, proxy.Items);

            dictionary.Add("AndAnotherName", "Value");

            EnumerableAssert.AreEqual(dictionary, proxy.Items);
        }
コード例 #21
0
        public void Sorting()
        {
            using (new CultureSwapper(PredefinedCulture.EnglishUnitedStates))
            {
                var cities = new[] { paris, newYork, athens, madrid, añasco };

                var sortedSet = new SortedSet <City>(cities, KeyComparer.Create((City city) => city.Name));
                EnumerableAssert.AreEqual(new[] { añasco, athens, madrid, newYork, paris }, sortedSet);

                sortedSet = new SortedSet <City>(cities, KeyComparer.Create((City city) => city.Name, StringComparer.Ordinal));
                EnumerableAssert.AreEqual(new[] { athens, añasco, madrid, newYork, paris }, sortedSet);
            }

            int[] nums  = new[] { 47, -32, -54, 18, 62, -71, 58 };
            var   byAbs = new SortedSet <int>(nums, KeyComparer.Create((int n) => Math.Abs(n)));

            EnumerableAssert.AreEqual(new [] { 18, -32, 47, -54, 58, 62, -71 }, byAbs);
        }
コード例 #22
0
        public void AddExport_ReturnedComposablePart_ContainsExportDefinitionRepresentingExport()
        {
            var metadata = new Dictionary <string, object>();

            metadata["Name"] = "Value";

            CompositionBatch batch = new CompositionBatch();
            var export             = ExportFactory.Create("Contract", "Value", metadata);

            var part = batch.AddExport(export);

            Assert.Equal(1, batch.PartsToAdd.Count);

            var definition = part.ExportDefinitions.Single();

            Assert.Equal("Contract", definition.ContractName);
            Assert.Equal("Value", part.GetExportedValue(definition));
            EnumerableAssert.AreEqual(metadata, definition.Metadata);
        }
            public void VerifyImports(params T[] expectedValues)
            {
                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyField, expectedValues);

                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyProperty, expectedValues);

                EnumerableAssert.AreEqual(ObservableCollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyProperty, expectedValues);
            }
コード例 #24
0
        public void ImportCollections_WriteOnlyArray()
        {
            var container = ContainerFactory.Create();
            var batch     = new CompositionBatch();

            var importer = new ImporterWriteOnlyArray();

            List <int> values = new List <int>()
            {
                21, 32, 43
            };

            batch.AddPart(importer);
            values.ForEach(v => batch.AddExportedValue("Value", v));

            container.Compose(batch);

            EnumerableAssert.AreEqual(values, importer.PublicArray);
        }
コード例 #25
0
        public void RebindingShouldNotHappenForConstructorArguments()
        {
            var container          = GetContainerWithCatalog();
            CompositionBatch batch = new CompositionBatch();

            var p1 = batch.AddExportedValue("MyConstructorCollectionItem", 1);

            batch.AddExportedValue("MyConstructorCollectionItem", 2);
            batch.AddExportedValue("MyConstructorCollectionItem", 3);
            container.Compose(batch);

            var a = container.GetExportedValue <AWithCollectionArgument>();

            EnumerableAssert.AreEqual(a.Values, 1, 2, 3);

            batch = new CompositionBatch();
            batch.AddExportedValue("MyConstructorCollectionItem", 4);
            batch.AddExportedValue("MyConstructorCollectionItem", 5);
            batch.AddExportedValue("MyConstructorCollectionItem", 6);
            // After rejection changes that are incompatible with existing assumptions are no
            // longer silently ignored.  The batch attempting to make this change is rejected
            // with a ChangeRejectedException
            CompositionAssert.ThrowsChangeRejectedError(ErrorId.ImportEngine_PreventedByExistingImport, () =>
            {
                container.Compose(batch);
            });

            // The collection which is a constructor import should not be rebound
            EnumerableAssert.AreEqual(a.Values, 1, 2, 3);

            batch.RemovePart(p1);
            // After rejection changes that are incompatible with existing assumptions are no
            // longer silently ignored.  The batch attempting to make this change is rejected
            // with a ChangeRejectedException
            CompositionAssert.ThrowsChangeRejectedError(ErrorId.ImportEngine_PreventedByExistingImport, () =>
            {
                container.Compose(batch);
            });

            // The collection which is a constructor import should not be rebound
            EnumerableAssert.AreEqual(a.Values, 1, 2, 3);
        }
コード例 #26
0
            public void then_session_is_updated_with_new_eventSources_with_filters_and_arguments()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     =
                    new EventSourceSettings(
                        currentEventSource.Name,
                        level: currentEventSource.Level,
                        matchAnyKeyword: currentEventSource.MatchAnyKeyword,
                        arguments: new[] { new KeyValuePair <string, string>("key", "value") },
                        processNameFilters: new[] { "process" });

                this.Sut.UpdateSession(new List <EventSourceSettings> {
                    newEventSource
                });

                Assert.AreEqual(newEventSource.Level, currentEventSource.Level);
                Assert.AreEqual(newEventSource.MatchAnyKeyword, currentEventSource.MatchAnyKeyword);
                EnumerableAssert.AreEqual(newEventSource.Arguments, currentEventSource.Arguments);
                EnumerableAssert.AreEqual(newEventSource.ProcessNamesToFilter, currentEventSource.ProcessNamesToFilter);
            }
コード例 #27
0
        public void Person_SortedSet()
        {
            var persons = new[]
            {
                new Person {
                    Ssn = "324-00-3015", DateOfBirth = new DateTime(1970, 12, 17), FirstName = "Tod", LastName = "Temme"
                },
                new Person {
                    Ssn = "548-00-1592", DateOfBirth = new DateTime(1968, 03, 13), FirstName = "Lucia", LastName = "Armstrong"
                },
                new Person {
                    Ssn = "129-00-7416", DateOfBirth = new DateTime(1982, 09, 02), FirstName = "Spencer", LastName = "Weaver"
                },
                new Person {
                    Ssn = "831-00-6391", DateOfBirth = new DateTime(1974, 04, 30), FirstName = "Celia", LastName = "Potter"
                },
                new Person {
                    Ssn = "714-00-6502", DateOfBirth = new DateTime(1966, 11, 19), FirstName = "Powell", LastName = "Beck"
                },
            };

            var bySsn = new SortedSet <Person>(persons, KeyComparer.Create(
                                                   (Person p) => p.Ssn));

            // Not suitable for real-world scenarios, since SortedSet<T> does not allow duplicates.
            var byDateOfBirth = new SortedSet <Person>(persons, KeyComparer.Create(
                                                           (Person p) => p.DateOfBirth));
            var byFullName = new SortedSet <Person>(persons, KeyComparer.Create(
                                                        (Person p) => $"{p.FirstName} {p.LastName}", StringComparer.Ordinal));

            EnumerableAssert.AreEqual(new[] { "Spencer", "Tod", "Lucia", "Powell", "Celia" }, bySsn.Select(p => p.FirstName));
            EnumerableAssert.AreEqual(new[] { "Powell", "Lucia", "Tod", "Celia", "Spencer" }, byDateOfBirth.Select(p => p.FirstName));
            EnumerableAssert.AreEqual(new[] { "Celia", "Lucia", "Powell", "Spencer", "Tod" }, byFullName.Select(p => p.FirstName));

            var person = new Person {
                Ssn = "301-00-1582", DateOfBirth = new DateTime(1984, 11, 01), FirstName = "Teddy", LastName = "Wake"
            };

            bySsn.Add(person);
            EnumerableAssert.AreEqual(new[] { "Spencer", "Teddy", "Tod", "Lucia", "Powell", "Celia" }, bySsn.Select(p => p.FirstName));
        }
コード例 #28
0
        private static void PerformSecureComputation(IMultiPartyNetworkSession session, BitArray expectedOutput)
        {
            BitArray localInput = Inputs[session.LocalParty.Id];

            using CryptoContext cryptoContext = CryptoContext.CreateDefault();

            IObliviousTransfer obliviousTransfer = new NaorPinkasObliviousTransfer(
                new SecurityParameters(47, 23, 4, 1, 1),
                cryptoContext
                );

            IMultiplicativeSharing multiplicativeSharing = new ObliviousTransferMultiplicativeSharing(
                obliviousTransfer,
                cryptoContext
                );

            SecretSharingSecureComputation computation = new SecretSharingSecureComputation(
                session,
                multiplicativeSharing,
                cryptoContext
                );

            SetIntersectionCircuitRecorder circuitRecorder = new SetIntersectionCircuitRecorder(
                session.NumberOfParties,
                localInput.Length
                );

            CircuitBuilder circuitBuilder = new CircuitBuilder();

            circuitRecorder.Record(circuitBuilder);

            ForwardCircuit circuit      = new ForwardCircuit(circuitBuilder.CreateCircuit());
            BitArray       actualOutput = computation
                                          .EvaluateAsync(circuit, circuitRecorder.InputMapping, circuitRecorder.OutputMapping, localInput)
                                          .Result;

            EnumerableAssert.AreEqual(
                expectedOutput,
                actualOutput
                );
        }
コード例 #29
0
            public void VerifyImports(params T[] expectedValues)
            {
                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyField, expectedValues);

                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyProperty, expectedValues);

#if FEATURE_OBSERVABLECOLLECTIONS
                EnumerableAssert.AreEqual(ObservableCollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyProperty, expectedValues);
#endif // FEATURE_OBSERVABLECOLLECTIONS
            }
コード例 #30
0
        public void ReadToEnd_FileStream()
        {
            using (var tempFile = new TempFile(create: false))
            {
                var filePath = tempFile.FilePath;
                var bytes    = CachedRandom.Current.NextBytes(16 * 1024);
                File.WriteAllBytes(filePath, bytes);

                using (var fileStream = File.OpenRead(filePath))
                {
                    EnumerableAssert.AreEqual(bytes, fileStream.ReadToEnd());
                }

                using (var fileStream = File.OpenRead(filePath))
                {
                    byte[] discard   = new byte[4 * 1024];
                    int    discarded = fileStream.Read(discard, 0, discard.Length);

                    EnumerableAssert.AreEqual(bytes.Skip(discarded), fileStream.ReadToEnd());
                }
            }
        }