Here are the examples of the csharp api Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(int, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
583 Examples
19
View Source File : FilteredCatalogTransitiveClosureTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void IncludeDependenciesChainWithCyclesOptionalOnly()
{
var catalog = CreateCatalog(
typeof(Exporter3OptionalImport2),
typeof(Exporter2OptionalImport3),
typeof(Exporter1),
typeof(Exporter2),
typeof(Exporter3),
typeof(Exporter1Import2),
typeof(IOther));
var filteredCatalog = catalog.Filter(p => p.Exports<IContract2>());
replacedert.AreEqual(2, filteredCatalog.Parts.Count());
var dependentsCatalog = filteredCatalog.IncludeDependencies(i => i.Cardinality == ImportCardinality.ZeroOrOne);
replacedert.AreEqual(4, dependentsCatalog.Parts.Count());
}
19
View Source File : FilteredCatalogTransitiveClosureTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void IncludeDependciesOpenGenericToOpenGeneric()
{
var catalog = CreateCatalog(
typeof(OpenGenericExporter<,>),
typeof(OpenGenericImporter<,>),
typeof(Other));
var filteredCatalog = catalog.Filter(p => p.Exports<IContract3>());
replacedert.AreEqual(1, filteredCatalog.Parts.Count());
var dependentsCatalog = filteredCatalog.IncludeDependencies();
replacedert.AreEqual(2, dependentsCatalog.Parts.Count());
}
19
View Source File : FilteredCatalogTransitiveClosureTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void IncludeDependenciesOpenGenericToOpenGenericReverse()
{
var catalog = CreateCatalog(
typeof(OpenGenericExporter<,>),
typeof(OpenGenericImporterReverseOrder<,>),
typeof(Other));
var filteredCatalog = catalog.Filter(p => p.Exports<IContract3>());
replacedert.AreEqual(1, filteredCatalog.Parts.Count());
var dependentsCatalog = filteredCatalog.IncludeDependencies();
replacedert.AreEqual(2, dependentsCatalog.Parts.Count());
}
19
View Source File : FilteredCatalogTransitiveClosureTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void IncludeDependenciesOpenGenericToClosedGeneric()
{
var catalog = CreateCatalog(
typeof(OpenGenericExporter<,>),
typeof(ClosedGenericImporter),
typeof(Other));
var filteredCatalog = catalog.Filter(p => p.Exports<IContract1>());
replacedert.AreEqual(1, filteredCatalog.Parts.Count());
var dependentsCatalog = filteredCatalog.IncludeDependencies();
replacedert.AreEqual(2, dependentsCatalog.Parts.Count());
}
19
View Source File : FilteredCatalogTransitiveClosureTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void IncludeDependenciesClosedToClosed()
{
var catalog = CreateCatalog(
typeof(SpecificGenericExporter),
typeof(ClosedGenericImporter),
typeof(Other));
var filteredCatalog = catalog.Filter(p => p.Exports<IContract1>());
replacedert.AreEqual(1, filteredCatalog.Parts.Count());
var dependentsCatalog = filteredCatalog.IncludeDependencies();
replacedert.AreEqual(2, dependentsCatalog.Parts.Count());
}
19
View Source File : ComposablePartCatalogTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Dispose_CallsDisposeBoolOnce()
{
int disposeCount = 0;
var catalog = CatalogFactory.CreateDisposable(disposing =>
{
disposeCount++;
});
catalog.Dispose();
replacedert.AreEqual(1, disposeCount);
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void SingletonBehavior()
{
TypeCatalog catalog = new TypeCatalog(typeof(SingletonExport<,>));
CompositionContainer container = new CompositionContainer(catalog);
SingletonExportExportCount.Count = 0;
var exports = container.GetExportedValues<IExport<IFoo, IBar>>();
replacedert.AreEqual(1, exports.Count());
// only one instance of the SingletonExport<,> is created
replacedert.AreEqual(1, SingletonExportExportCount.Count);
exports = container.GetExportedValues<IExport<IFoo, IBar>>();
replacedert.AreEqual(1, exports.Count());
// still only one instance of the SingletonExport<,> is created
replacedert.AreEqual(1, SingletonExportExportCount.Count);
var import = new SingletonImport<IFoo, IBar>();
container.SatisfyImportsOnce(import);
// still only one instance of the SingletonExport<,> is created
replacedert.AreEqual(1, SingletonExportExportCount.Count);
import = new SingletonImport<IFoo, IBar>();
container.SatisfyImportsOnce(import);
// still only one instance of the SingletonExport<,> is created
replacedert.AreEqual(1, SingletonExportExportCount.Count);
var import2 = new SingletonImport<IBar, IFoo>();
container.SatisfyImportsOnce(import2);
// two instances of the SingletonExport<,> is created
replacedert.AreEqual(2, SingletonExportExportCount.Count);
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithTypeConstraintTest()
{
TypeCatalog catalog = new TypeCatalog(typeof(PartWithTypeConstraint<>));
CompositionContainer container = new CompositionContainer(catalog);
// IFoo should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<IFoo>>().Count());
// IFoo2 should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<IFoo2>>().Count());
// IBar shouldn't
replacedert.AreEqual(0, container.GetExportedValues<IExport<IBar>>().Count());
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithRefTypeConstraintTest()
{
TypeCatalog catalog = new TypeCatalog(typeof(PartWithRefTypeConstraint<>));
CompositionContainer container = new CompositionContainer(catalog);
// IFoo should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<IFoo>>().Count());
// Bar should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<Bar>>().Count());
// int shouldn't
replacedert.AreEqual(0, container.GetExportedValues<IExport<int>>().Count());
// FooStruct shouldn't
replacedert.AreEqual(0, container.GetExportedValues<IExport<FooStruct>>().Count());
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithGenericConstraintTest()
{
TypeCatalog catalog = new TypeCatalog(typeof(PartWithGenericConstraint<,>));
CompositionContainer container = new CompositionContainer(catalog);
// int, Dictionary<string, int> should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<int, Dictionary<string, int>>>().Count());
// int, Dictionary<string, string> should not work
replacedert.AreEqual(0, container.GetExportedValues<IExport<int, Dictionary<string, string>>>().Count());
// FooStruct, FooStruct[] should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<FooStruct, Dictionary<string, FooStruct>>>().Count());
// FooStruct, IFoo should not
replacedert.AreEqual(0, container.GetExportedValues<IExport<FooStruct, IFoo>>().Count());
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithNakedConstraintTest()
{
TypeCatalog catalog = new TypeCatalog(typeof(PartWithNakedConstraint<,>));
CompositionContainer container = new CompositionContainer(catalog);
// Bar, Bar2 should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<Bar, Bar2>>().Count());
// Bar2, Bar should not work
replacedert.AreEqual(0, container.GetExportedValues<IExport<Bar2, Bar>>().Count());
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithExportParametersInReverseOrder()
{
TypeCatalog catalog = new TypeCatalog(typeof(PropertyExportWithChangedParameterOrder<,>));
CompositionContainer container = new CompositionContainer(catalog);
replacedert.AreEqual(1, container.GetExportedValues<IExport<string, int>>().Count());
}
19
View Source File : MetadataViewProviderTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void GetMetadataView_IMetadataViewWithDefaultedIntInTranparentType()
{
var view = MetadataViewProvider.GetMetadataView<ITrans_MetadataViewWithDefaultedInt>(new Dictionary<string, object>());
int result = TransparentTestCase.GetMetadataView_IMetadataViewWithDefaultedIntInTranparentType(view);
replacedert.AreEqual(120, result);
}
19
View Source File : SampleComponents.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[Export("ActionWith3Args")]
public void MyAction3(int i1, int i2, int i3)
{
replacedert.AreEqual(i1, 1);
replacedert.AreEqual(i2, 2);
replacedert.AreEqual(i3, 3);
}
19
View Source File : SampleComponents.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[Export("ActionWith4Args")]
public void MyAction4(int i1, int i2, int i3, int i4)
{
replacedert.AreEqual(i1, 1);
replacedert.AreEqual(i2, 2);
replacedert.AreEqual(i3, 3);
replacedert.AreEqual(i4, 4);
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void FilteredScopeFactoryOfT_ShouldSucceed()
{
var c1 = new TypeCatalog( typeof(ClreplacedRoot), typeof(ClreplacedA) );
var c2 = new TypeCatalog( typeof(ClreplacedA), typeof(ClreplacedB), typeof(ClreplacedC), typeof(ClreplacedD) );
var sd = c1.replacedcope( c2.replacedcope() );
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
fromRoot.clreplacedA.ValueToFilter ="IncludeInFirstInstance";
var a1 = fromRoot.clreplacedA.CreateExport().Value;
fromRoot.clreplacedA.ValueToFilter ="IncludeInSubsequentInstances";
var a2 = fromRoot.clreplacedA.CreateExport().Value;
replacedert.AreEqual(fromRoot.localClreplacedA.filteredTypes.Count(), 0);
replacedert.AreEqual(a1.filteredTypes.Count(), 2);
replacedert.AreEqual(a2.filteredTypes.Count(), 1);
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void FilteredScopeFactoryOfTM_ShouldSucceed()
{
var c1 = new TypeCatalog( typeof(ClreplacedRoot), typeof(ClreplacedA) );
var c2 = new TypeCatalog( typeof(ClreplacedA), typeof(ClreplacedB), typeof(ClreplacedC), typeof(ClreplacedD) );
var sd = c1.replacedcope( c2.replacedcope() );
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
fromRoot.clreplacedA.ValueToFilter ="IncludeInFirstInstance";
var a1 = fromRoot.clreplacedA.CreateExport().Value;
var md = fromRoot.clreplacedA.Metadata;
fromRoot.clreplacedA.ValueToFilter ="IncludeInSubsequentInstances";
var a2 = fromRoot.clreplacedA.CreateExport().Value;
replacedert.AreEqual(fromRoot.localClreplacedA.filteredTypes.Count(), 0);
replacedert.AreEqual(a1.filteredTypes.Count(), 2);
replacedert.AreEqual(a2.filteredTypes.Count(), 1);
}
19
View Source File : CompositionScopeDefinitionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor()
{
TypeCatalog catalog = new TypeCatalog(typeof(FooImpl));
TypeCatalog catalog1 = new TypeCatalog(typeof(FooImpl2));
TypeCatalog catalog2 = new TypeCatalog(typeof(FooImpl3));
CompositionScopeDefinition scope1 = new CompositionScopeDefinition(catalog1, Enumerable.Empty<CompositionScopeDefinition>());
CompositionScopeDefinition scope2 = new CompositionScopeDefinition(catalog1, Enumerable.Empty<CompositionScopeDefinition>());
CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, new CompositionScopeDefinition[] { scope1, scope2 });
replacedert.IsNotNull(scope);
replacedert.IsNotNull(scope.Parts);
replacedert.AreEqual(1, scope.Parts.Count());
replacedert.AreEqual(2, scope.Children.Count());
replacedert.AreSame(scope1, scope.Children.ToArray()[0]);
replacedert.AreSame(scope2, scope.Children.ToArray()[1]);
}
19
View Source File : CompositionScopeDefinitionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_NullChildren()
{
TypeCatalog catalog = new TypeCatalog(typeof(FooImpl));
CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null);
replacedert.IsNotNull(scope.Children);
replacedert.AreEqual(0, scope.Children.Count());
}
19
View Source File : CompositionScopeDefinitionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_PublicSurface()
{
var catalog = new TypeCatalog(typeof(FooImpl), typeof(FooImpl2), typeof(FooImpl2));
var exports = catalog.Parts.Select(p => p.ExportDefinitions.First());
CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null, exports);
replacedert.AreEqual(catalog.Parts.Count(), scope.Parts.Count());
replacedert.AreEqual(exports.Count(), scope.PublicSurface.Count());
}
19
View Source File : CompositionScopeDefinitionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_PublicSurface_MultipleExportsPerPart()
{
var catalog = new TypeCatalog(typeof(FooImpl4));
var exports = catalog.Parts.SelectMany(p => p.ExportDefinitions);
CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null, exports);
replacedert.AreEqual(3, scope.PublicSurface.Count());
}
19
View Source File : CompositionScopeDefinitionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void SimpleComposition()
{
var catalog = new TypeCatalog(typeof(FooImpl), typeof(FooImpl2), typeof(FooImpl2));
var scope = new CompositionScopeDefinition(catalog, null);
var container = new CompositionContainer(scope);
var foos = container.GetExportedValues<IFooContract>();
replacedert.AreEqual(3, foos.Count());
}
19
View Source File : LazyMemberInfoTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_PreplacedMember()
{
foreach (var memberAndAccessorsInfo in GetMembersAndAccessors(typeof(LazyMemberTestClreplaced)))
{
MemberInfo member = memberAndAccessorsInfo.Item1;
MemberTypes memberType = memberAndAccessorsInfo.Item2.Item1;
MemberInfo[] accessors = memberAndAccessorsInfo.Item2.Item2;
LazyMemberInfo lazy = new LazyMemberInfo(member);
replacedert.AreEqual(memberType, lazy.MemberType);
replacedert.AreEqual(accessors.Length, lazy.GetAccessors().Length);
replacedert.IsTrue(accessors.SequenceEqual(lazy.GetAccessors()));
}
}
19
View Source File : LazyMemberInfoTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_PreplacedAccessors()
{
foreach (var memberAndAccessorsInfo in GetMembersAndAccessors(typeof(LazyMemberTestClreplaced)))
{
MemberInfo member = memberAndAccessorsInfo.Item1;
MemberTypes memberType = memberAndAccessorsInfo.Item2.Item1;
MemberInfo[] accessors = memberAndAccessorsInfo.Item2.Item2;
LazyMemberInfo lazy = new LazyMemberInfo(memberType, accessors);
replacedert.AreEqual(memberType, lazy.MemberType);
replacedert.AreEqual(accessors.Length, lazy.GetAccessors().Length);
replacedert.IsTrue(accessors.SequenceEqual(lazy.GetAccessors()));
}
}
19
View Source File : LazyMemberInfoTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Constructor_PreplacedAccessorCreators()
{
foreach (var memberAndAccessorsInfo in GetMembersAndAccessors(typeof(LazyMemberTestClreplaced)))
{
MemberInfo member = memberAndAccessorsInfo.Item1;
MemberTypes memberType = memberAndAccessorsInfo.Item2.Item1;
MemberInfo[] accessors = memberAndAccessorsInfo.Item2.Item2;
LazyMemberInfo lazy = new LazyMemberInfo(memberType, () => accessors);
replacedert.AreEqual(memberType, lazy.MemberType);
replacedert.AreEqual(accessors.Length, lazy.GetAccessors().Length);
replacedert.IsTrue(accessors.SequenceEqual(lazy.GetAccessors()));
}
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void LocalSharedNonLocalInSameContainer_ShouldSucceed()
{
var cat1 = new TypeCatalog( typeof(ClreplacedRoot), typeof(ClreplacedXXXX) );
var cat2 = new TypeCatalog( typeof(ClreplacedA) );
var cat3 = new TypeCatalog( typeof(ClreplacedB) );
var cat4 = new TypeCatalog( typeof(ClreplacedC), typeof(ClreplacedD), typeof(ClreplacedXXXX) );
var sd = cat1.replacedcope( cat2.replacedcope( cat3.replacedcope( cat4.replacedcope( ) )) );
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
var a1 = fromRoot.clreplacedA.CreateExport().Value;
fromRoot.xxxx.InstanceValue = 16;
var b1 = a1.clreplacedB.CreateExport().Value;
var c1 = b1.clreplacedC.CreateExport().Value;
replacedert.AreEqual(16, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(16, a1.xxxx.InstanceValue);
replacedert.AreEqual(16, b1.xxxx.InstanceValue);
replacedert.AreEqual(16, c1.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.clreplacedD.xxxx.InstanceValue);
c1.xxxx.InstanceValue = 8;
replacedert.AreEqual(8, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(8, a1.xxxx.InstanceValue);
replacedert.AreEqual(8, b1.xxxx.InstanceValue);
replacedert.AreEqual(8, c1.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.clreplacedD.xxxx.InstanceValue);
c1.clreplacedD.xxxx.InstanceValue = 2;
replacedert.AreEqual(8, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(8, a1.xxxx.InstanceValue);
replacedert.AreEqual(8, b1.xxxx.InstanceValue);
replacedert.AreEqual(8, c1.xxxx.InstanceValue);
replacedert.AreEqual(2, c1.clreplacedD.xxxx.InstanceValue);
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void ScopeBridgingAdapters_ShouldSucceed()
{
var cat1 = new TypeCatalog( typeof(ClreplacedRoot), typeof(ClreplacedXXXX) );
var cat2 = new TypeCatalog( typeof(ClreplacedC), typeof(ClreplacedD) );
var sd = cat1.replacedcope(cat2.replacedcope());
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
var c1 = fromRoot.clreplacedC.CreateExport().Value;
var c2 = fromRoot.clreplacedC.CreateExport().Value;
var c3 = fromRoot.clreplacedC.CreateExport().Value;
var c4 = fromRoot.clreplacedC.CreateExport().Value;
var c5 = fromRoot.clreplacedC.CreateExport().Value;
replacedert.AreEqual(0, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c2.xxxx.InstanceValue);
replacedert.AreEqual(0, c2.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c3.xxxx.InstanceValue);
replacedert.AreEqual(0, c3.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c4.xxxx.InstanceValue);
replacedert.AreEqual(0, c4.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c5.xxxx.InstanceValue);
replacedert.AreEqual(0, c5.clreplacedD.xxxx.InstanceValue);
c1.xxxx.InstanceValue = 1;
c2.xxxx.InstanceValue = 2;
c3.xxxx.InstanceValue = 3;
c4.xxxx.InstanceValue = 4;
c5.xxxx.InstanceValue = 5;
replacedert.AreEqual(0, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(1, c1.xxxx.InstanceValue);
replacedert.AreEqual(1, c1.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(2, c2.xxxx.InstanceValue);
replacedert.AreEqual(2, c2.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(3, c3.xxxx.InstanceValue);
replacedert.AreEqual(3, c3.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(4, c4.xxxx.InstanceValue);
replacedert.AreEqual(4, c4.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(5, c5.xxxx.InstanceValue);
replacedert.AreEqual(5, c5.clreplacedD.xxxx.InstanceValue);
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void ScopeBridgingAdaptersImportExportProperty_ShouldSucceed()
{
var cat1 = new TypeCatalog( typeof(ClreplacedRoot), typeof(ClreplacedXXXX) );
var cat2 = new TypeCatalog( typeof(ClreplacedC), typeof(ClreplacedD) );
var sd = cat1.replacedcope(cat2.replacedcope());
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
var c1 = fromRoot.clreplacedC.CreateExport().Value;
var c2 = fromRoot.clreplacedC.CreateExport().Value;
var c3 = fromRoot.clreplacedC.CreateExport().Value;
var c4 = fromRoot.clreplacedC.CreateExport().Value;
var c5 = fromRoot.clreplacedC.CreateExport().Value;
replacedert.AreEqual(0, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.xxxx.InstanceValue);
replacedert.AreEqual(0, c1.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c2.xxxx.InstanceValue);
replacedert.AreEqual(0, c2.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c3.xxxx.InstanceValue);
replacedert.AreEqual(0, c3.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c4.xxxx.InstanceValue);
replacedert.AreEqual(0, c4.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(0, c5.xxxx.InstanceValue);
replacedert.AreEqual(0, c5.clreplacedD.xxxx.InstanceValue);
c1.xxxx.InstanceValue = 1;
c2.xxxx.InstanceValue = 2;
c3.xxxx.InstanceValue = 3;
c4.xxxx.InstanceValue = 4;
c5.xxxx.InstanceValue = 5;
replacedert.AreEqual(0, fromRoot.xxxx.InstanceValue);
replacedert.AreEqual(1, c1.xxxx.InstanceValue);
replacedert.AreEqual(1, c1.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(2, c2.xxxx.InstanceValue);
replacedert.AreEqual(2, c2.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(3, c3.xxxx.InstanceValue);
replacedert.AreEqual(3, c3.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(4, c4.xxxx.InstanceValue);
replacedert.AreEqual(4, c4.clreplacedD.xxxx.InstanceValue);
replacedert.AreEqual(5, c5.xxxx.InstanceValue);
replacedert.AreEqual(5, c5.clreplacedD.xxxx.InstanceValue);
}
19
View Source File : AdaptingCollectionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void TestFilteringImports()
{
var container = ContainerFactory.CreateWithAttributedCatalog(typeof(NetworkExport), typeof(NonNetworkExport));
var filterExports = new FilterExports();
container.ComposeParts(filterExports);
replacedert.AreEqual(1, filterExports.OnlineOnly.Count);
replacedert.AreEqual(1, filterExports.OnlineOnly2.Count);
}
19
View Source File : AdaptingCollectionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void TestDyamicallyFilteringImports()
{
var container = ContainerFactory.CreateWithAttributedCatalog(typeof(Dynamic1), typeof(Dynamic2), typeof(NonDynamic1));
var dynamicExports = new DynamicExports();
container.ComposeParts(dynamicExports);
replacedert.AreEqual(1, dynamicExports.DynamicCollection.Count);
dynamicExports.DynamicCollection.IncludeDynamic = true;
replacedert.AreEqual(3, dynamicExports.DynamicCollection.Count);
}
19
View Source File : AdaptingCollectionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void TestDyamicallyFilteringNoSubTypeImports()
{
var container = ContainerFactory.CreateWithAttributedCatalog(typeof(Dynamic1), typeof(Dynamic2), typeof(NonDynamic1));
var dynamicExports = new DynamicExportsNoSubType();
container.ComposeParts(dynamicExports);
replacedert.AreEqual(1, dynamicExports.DynamicCollection.Count);
dynamicExports.IncludeDynamic = true;
replacedert.AreEqual(3, dynamicExports.DynamicCollection.Count);
}
19
View Source File : DelayLoadingTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartTypeLoadedLazilyEagerDependeciesLoadEagerly()
{
var catalog = new TypeLoadNotifyingCatalog(typeof(ExportingPart), typeof(PartImportingEagerly));
var container = new CompositionContainer(catalog);
catalog.replacedertNotLoaded(typeof(ExportingPart));
catalog.replacedertNotLoaded(typeof(PartImportingEagerly));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
Lazy<IImporter> lazyContract = container.GetExport<IImporter>();
replacedert.IsNotNull(lazyContract);
catalog.replacedertNotLoaded(typeof(PartImportingEagerly));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
IImporter value = lazyContract.Value;
catalog.replacedertLoaded(typeof(PartImportingEagerly));
catalog.replacedertLoaded(typeof(ExportingPart));
replacedert.AreEqual(2, catalog.LoadedTypes.Count());
}
19
View Source File : DelayLoadingTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartTypeLoadedLazilyLazyDependeciesLoadLazily()
{
var catalog = new TypeLoadNotifyingCatalog(typeof(ExportingPart), typeof(PartImportingLazily));
var container = new CompositionContainer(catalog);
catalog.replacedertNotLoaded(typeof(ExportingPart));
catalog.replacedertNotLoaded(typeof(PartImportingLazily));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
Lazy<IImporter> lazyContract = container.GetExport<IImporter>();
replacedert.IsNotNull(lazyContract);
catalog.replacedertNotLoaded(typeof(PartImportingLazily));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
IImporter value = lazyContract.Value;
catalog.replacedertLoaded(typeof(PartImportingLazily));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(1, catalog.LoadedTypes.Count());
}
19
View Source File : DelayLoadingTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartTypeLoadedLazilyEagerCollectionDependeciesLoadEagerly()
{
var catalog = new TypeLoadNotifyingCatalog(typeof(ExportingPart), typeof(PartImportingCollectionEagerly));
var container = new CompositionContainer(catalog);
catalog.replacedertNotLoaded(typeof(ExportingPart));
catalog.replacedertNotLoaded(typeof(PartImportingCollectionEagerly));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
Lazy<IImporter> lazyContract = container.GetExport<IImporter>();
replacedert.IsNotNull(lazyContract);
catalog.replacedertNotLoaded(typeof(PartImportingCollectionEagerly));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
IImporter value = lazyContract.Value;
catalog.replacedertLoaded(typeof(PartImportingCollectionEagerly));
catalog.replacedertLoaded(typeof(ExportingPart));
replacedert.AreEqual(2, catalog.LoadedTypes.Count());
}
19
View Source File : DelayLoadingTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartTypeLoadedLazilyLazyCollectionDependeciesLoadLazily()
{
var catalog = new TypeLoadNotifyingCatalog(typeof(ExportingPart), typeof(PartImportingCollectionLazily));
var container = new CompositionContainer(catalog);
catalog.replacedertNotLoaded(typeof(ExportingPart));
catalog.replacedertNotLoaded(typeof(PartImportingCollectionLazily));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
Lazy<IImporter> lazyContract = container.GetExport<IImporter>();
replacedert.IsNotNull(lazyContract);
catalog.replacedertNotLoaded(typeof(PartImportingCollectionLazily));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(0, catalog.LoadedTypes.Count());
IImporter value = lazyContract.Value;
catalog.replacedertLoaded(typeof(PartImportingCollectionLazily));
catalog.replacedertNotLoaded(typeof(ExportingPart));
replacedert.AreEqual(1, catalog.LoadedTypes.Count());
}
19
View Source File : DelegateCompositionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Export_SimpleCustomDelegate_ShouldWork()
{
var container = ContainerFactory.CreateWithAttributedCatalog(
typeof(MethodExporter));
var contractName = AttributedModelServices.GetContractName(typeof(SimpleDelegate));
var export1 = container.GetExportedValue<SimpleDelegate>();
replacedert.AreEqual(1, export1());
var export2 = container.GetExportedValue<Func<int>>();
replacedert.AreEqual(1, export1());
var export3 = (ExportedDelegate)container.GetExportedValue<object>(contractName);
var export4 = (SimpleDelegate)export3.CreateDelegate(typeof(SimpleDelegate));
replacedert.AreEqual(1, export4());
}
19
View Source File : DelegateCompositionTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void MethodWithOutParam_ShouldWorkWithRefParam()
{
var container = ContainerFactory.CreateWithAttributedCatalog(
typeof(RefOutMethodExporter));
int i = 0;
var export1 = container.GetExportedValue<GetRef>();
export1(ref i);
replacedert.AreEqual(29, i);
i = 0;
var export2 = container.GetExportedValue<GetOut>();
export2(out i);
replacedert.AreEqual(29, i);
}
19
View Source File : DiscoveryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void TestInterfaces()
{
var container = ContainerFactory.CreateWithAttributedCatalog(
typeof(MyToolbarPlugin));
var app = new object();
container.AddAndComposeExportedValue<object>("Application", app);
var toolbar = new object();
container.AddAndComposeExportedValue<object>("ToolBar", toolbar);
var export = container.GetExportedValue<IToolbarPlugin>();
replacedert.AreEqual(app, export.Application);
replacedert.AreEqual(toolbar, export.ToolBar);
replacedert.AreEqual("MyToolbarPlugin", export.Name);
var pluginNames = container.GetExportedValues<string>("ApplicationPluginNames");
replacedert.AreEqual(1, pluginNames.Count());
}
19
View Source File : DiscoveryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Import_VirtualPropertyOverrideWithSameContract_ShouldSucceed()
{
var container = ContainerFactory.Create();
container.AddAndComposeExportedValue<int>("VirtualImport", 21);
var import = new ImportOnOverridenPropertyWithSameContract();
container.SatisfyImportsOnce(import);
// Import will get set twice because there are 2 imports on the same property.
// We would really like to either elminate it getting set twice or error in this case
// but we figure it is a rare enough corner case that it doesn't warrented the run time cost
// and can be covered by an FxCop rule.
replacedert.AreEqual(2, import.ImportSetCount);
replacedert.AreEqual(21, import.VirtualImport);
}
19
View Source File : DiscoveryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Import_VirtualPropertyOverrideWithDifferentContract_ShouldSucceed()
{
var container = ContainerFactory.Create();
container.AddAndComposeExportedValue<int>("VirtualImport", 21);
container.AddAndComposeExportedValue<int>("OverriddenImport", 42);
var import = new ImportOnOverridenPropertyWithSameContract();
container.SatisfyImportsOnce(import);
// Import will get set twice because there are 2 imports on the same property.
// We would really like to either elminate it getting set twice or error in this case
// but we figure it is a rare enough corner case that it doesn't warrented the run time cost
// and can be covered by an FxCop rule.
replacedert.AreEqual(2, import.ImportSetCount);
// The derived most import should be discovered first and so it will get set first
// and thus the value should be the base import which is 21.
replacedert.AreEqual(21, import.VirtualImport);
}
19
View Source File : DiscoveryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void Export_ExportOnlyOnBaseInterfacewithInheritedMarked_ShouldFindAllImplementers()
{
var container = ContainerFactory.CreateWithAttributedCatalog(
typeof(NorthwindOrderScreen),
typeof(SouthsandOrderScreen));
var exports = container.GetExportedValues<IOrderScreen>();
replacedert.AreEqual(2, exports.Count());
replacedert.IsInstanceOfType(exports.ElementAt(0), typeof(NorthwindOrderScreen));
replacedert.IsInstanceOfType(exports.ElementAt(1), typeof(SouthsandOrderScreen));
}
19
View Source File : LifetimeTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartAddedTwice_AppearsTwice()
{
// You probably shouldn't be adding a part to the container twice, but it's not something we're going to check for and throw an exception on
var container = new CompositionContainer();
var disposable = new AnyPartDisposable();
var part = AttributedModelServices.CreatePart(disposable);
var batch = new CompositionBatch();
batch.AddPart(part);
container.Compose(batch);
batch = new CompositionBatch();
batch.AddPart(part);
container.Compose(batch);
var exports = container.GetExports<AnyPartDisposable>();
replacedert.AreEqual(2, exports.Count());
container.Dispose();
}
19
View Source File : CompositionServiceExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
[Description("Verifies CompositionServices.SatisfyImportsOne with Scoped ExportFactories")]
public void ComposeAppInNewScopeChildrenInBoth_ShouldSucceed()
{
var childCatalog = new CompositionScopeDefinition(new TypeCatalog(typeof(Foo1), typeof(Child)), new CompositionScopeDefinition[] { });
var rootCatalog = new CompositionScopeDefinition(new TypeCatalog(typeof(Child)), new CompositionScopeDefinition[] { childCatalog });
var cs = rootCatalog.CreateCompositionService();
var app = new App();
cs.SatisfyImportsOnce(app);
var e1 = app.FooFactory.CreateExport();
var e2 = app.FooFactory.CreateExport();
var e3 = app.FooFactory.CreateExport();
e1.Value.FooChild.FooValue = 10;
e2.Value.FooChild.FooValue = 20;
e3.Value.FooChild.FooValue = 30;
replacedert.AreEqual<int>(e1.Value.FooChild.FooValue, 10);
replacedert.AreEqual<int>(e2.Value.FooChild.FooValue, 20);
replacedert.AreEqual<int>(e3.Value.FooChild.FooValue, 30);
}
19
View Source File : CompositionServiceExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
[Description("Verifies CompositionServices.SatisfyImportsOne with NonScoped ExportFactories")]
public void ComposeAppInRootScope_ShouldSucceed()
{
var catalog = new TypeCatalog(typeof(Foo1), typeof(Child));
var cs = catalog.CreateCompositionService();
var app = new App();
cs.SatisfyImportsOnce(app);
var e1 = app.FooFactory.CreateExport();
var e2 = app.FooFactory.CreateExport();
var e3 = app.FooFactory.CreateExport();
e1.Value.FooChild.FooValue = 10;
e2.Value.FooChild.FooValue = 20;
e3.Value.FooChild.FooValue = 30;
replacedert.AreEqual<int>(e1.Value.FooChild.FooValue, 30);
replacedert.AreEqual<int>(e2.Value.FooChild.FooValue, 30);
replacedert.AreEqual<int>(e3.Value.FooChild.FooValue, 30);
}
19
View Source File : GenericsTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void PartWithNewableTypeConstraintTest()
{
TypeCatalog catalog = new TypeCatalog(typeof(PartWithNewableTypeConstraint<>));
CompositionContainer container = new CompositionContainer(catalog);
// int should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<int>>().Count());
// FooStruct should work
replacedert.AreEqual(1, container.GetExportedValues<IExport<FooStruct>>().Count());
// IFoo shouldn't
replacedert.AreEqual(0, container.GetExportedValues<IExport<IFoo>>().Count());
// Bar should
replacedert.AreEqual(1, container.GetExportedValues<IExport<Bar>>().Count());
}
19
View Source File : SampleComponents.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[Export("ActionWith1Arg")]
public void MyAction1(int i1)
{
replacedert.AreEqual(i1, 1);
}
19
View Source File : SampleComponents.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[Export("ActionWith2Args")]
public void MyAction2(int i1, int i2)
{
replacedert.AreEqual(i1, 1);
replacedert.AreEqual(i2, 2);
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void SimpleChainWithTwoChildren()
{
var parentCatalog = new TypeCatalog(typeof(BarWithMany));
var childCatalog1 = new TypeCatalog(typeof(FooImpl));
var childCatalog2 = new TypeCatalog(typeof(Foo2Impl));
var scope = parentCatalog.replacedcope(childCatalog1.replacedcope(), childCatalog2.replacedcope());
var container = new CompositionContainer(scope);
var bar = container.GetExportedValue<IBarContract>() as BarWithMany;
replacedert.IsNotNull(bar);
replacedert.AreEqual(2, bar.FooFactories.Length);
IFooContract foo1 = null;
using (var efFoo1 = bar.FooFactories[0].CreateExport())
{
foo1 = efFoo1.Value;
}
IFooContract foo2 = null;
using (var efFoo2 = bar.FooFactories[1].CreateExport())
{
foo2 = efFoo2.Value;
}
replacedert.IsTrue(((foo1 is FooImpl) && (foo2 is Foo2Impl)) || ((foo2 is FooImpl) && (foo1 is Foo2Impl)));
}
19
View Source File : ScopeExportFactoryTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void SelfExportFromExportFactory_ShouldSucceed()
{
var cat1 = new TypeCatalog( typeof(ClreplacedRoot) );
var cat2 = new TypeCatalog( typeof(ClreplacedA), typeof(ClreplacedB), typeof(ClreplacedC), typeof(ClreplacedD) );
var sd = cat1.replacedcope( cat2.replacedcope() );
var container = new CompositionContainer(sd);
var fromRoot = container.GetExportedValue<ClreplacedRoot>();
var a1 = fromRoot.clreplacedA.CreateExport().Value;
a1.InstanceValue = 8;
replacedert.AreEqual(8, a1.clreplacedB.clreplacedA.InstanceValue);
replacedert.AreEqual(8, a1.clreplacedC.clreplacedA.InstanceValue);
replacedert.AreEqual(8, a1.clreplacedD.clreplacedA.InstanceValue);
}
19
View Source File : LifetimeTests.cs
License : MIT License
Project Creator : microsoftarchive
License : MIT License
Project Creator : microsoftarchive
[TestMethod]
public void AnyPart_RecomposabeImport_ShouldNotBeCollected()
{
var catalog = new TypeCatalog(typeof(AnyPartRecomposable));
var container = new CompositionContainer(catalog);
// Setup dependency
CompositionBatch batch = new CompositionBatch();
var valueKey = batch.AddExportedValue("Value", 21);
container.Compose(batch);
batch = null;
var refTracker = new ReferenceTracker();
refTracker.AddReferencesNotExpectedToBeCollected(
container.GetExportedValue<AnyPartRecomposable>());
refTracker.CollectAndreplacedert();
// Lets make sure recomposition doesn't blow anything up here.
batch = new CompositionBatch();
batch.RemovePart(valueKey);
batch.AddExportedValue("Value", 42);
container.Compose(batch);
batch = null;
var exportedValue = (AnyPartRecomposable)refTracker.ReferencesNotExpectedToBeCollected[0].Target;
replacedert.AreEqual(42, exportedValue.Value);
GC.KeepAlive(container);
}
See More Examples