NUnit.Framework.Assert.AreSame(object, object)

Here are the examples of the csharp api NUnit.Framework.Assert.AreSame(object, object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

867 Examples 7

19 View Source File : AddSaveStrategyTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Execute_ShouldAddModel_AndShouldreplacedignNode_WhenModelNodeIsNull()
        {
            ModelBase model = new RendererModel(null);
            XmlElement newElement = new XmlDoreplacedent().CreateElement("element");
            bool addCalled = false;

            ISaveStrategy sut = new AddSaveStrategy<ModelBase>(model, modelParam => { addCalled = true; }, newElement);
            sut.Execute();

            replacedert.IsTrue(addCalled);
            replacedert.AreSame(newElement, model.Node);
        }

19 View Source File : AddSaveStrategyTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Execute_ShouldNotAddModel_AndShouldreplacedignNode_WhenModelNodeIsNotNull()
        {
            ModelBase model = new RendererModel(null);
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlElement newElement = xmlDoc.CreateElement("element");
            model.Node = xmlDoc.CreateElement("oldElement");
            bool addCalled = false;

            ISaveStrategy sut = new AddSaveStrategy<ModelBase>(model, modelParam => { addCalled = true; }, newElement);
            sut.Execute();

            replacedert.IsFalse(addCalled);
            replacedert.AreSame(newElement, model.Node);
        }

19 View Source File : XmlUtilitiesTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void AppendTo_ShouldAppendToParent()
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlNode parent = xmlDoc.CreateElement("parent");
            XmlNode child = xmlDoc.CreateElement("child");

            //Test sanity check
            replacedert.IsNull(parent.FirstChild);

            child.AppendTo(parent);

            replacedert.AreSame(parent.FirstChild, child);
        }

19 View Source File : ConfigurationFactory.CanLoadAndSaveXmlTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Load_ShouldLoadFromFile_WhenExists()
        {
            IXmlDoreplacedent actual = mSut.Load();

            mXmlDoc.Received(1).Load(Filename);

            replacedert.AreSame(mXmlDoc, actual);
        }

19 View Source File : ConfigurationFactory.CanLoadAndSaveXmlTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Load_ShouldNotLoadFromFile_WhenNonexistent()
        {
            mFileExists = false;

            IXmlDoreplacedent actual = mSut.Load();

            mXmlDoc.DidNotReceive().Load(Filename);

            replacedert.AreSame(mXmlDoc, actual);
        }

19 View Source File : ConfigurationFactory.CanLoadAndSaveXmlTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Load_ShouldReturnNewXmlDoc_WithLog4NetElement_WhenFileNonexistent()
        {
            mFileExists = false;

            IXmlDoreplacedent actual = mSut.Load();

            mXmlDoc.Received(1).CreateElement(Log4NetXmlConstants.Log4Net);

            mXmlDoc.Received(1).AppendChild(mXmlDoc.CreateElement(Log4NetXmlConstants.Log4Net));

            replacedert.AreSame(mXmlDoc, actual);
        }

19 View Source File : FileTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Properties_ShouldBeInitializedCorrectly()
        {
            replacedert.AreSame(mHistoricalFiles, mSut.HistoricalFiles);
            replacedert.IsNull(mSut.FilePath);
            replacedert.IsFalse(mSut.PatternString);
            replacedert.IsFalse(mSut.Overwrite);
        }

19 View Source File : MappingModelTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Edit_ShouldShowMappingWindow()
        {
            MappingModel param = null;
            MappingModel sut = new MappingModel(Dummy, model => param = model);

            sut.Edit.Execute(null);

            replacedert.AreSame(sut, param);
        }

19 View Source File : ConfigurationXmlTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void Reload_ShouldChooseFirstLog4NetElement()
        {
            mXmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><log4net></log4net><log4net></log4net></root>");

            mSut.Load();
            mToastService.ClearReceivedCalls();

            mSut.Reload();

            replacedert.AreSame(mXmlDoc.DoreplacedentElement.FirstChild, mSut.Log4NetNode);
        }

19 View Source File : ConfigurationXmlTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void ConfigXml_ShouldReturnUnderlyingConfig()
        {
            mSut.Load();

            replacedert.AreSame(((XmlDoreplacedentWrap)mXmlDoc).XmlDoreplacedentInstance, mSut.ConfigXml);
        }

19 View Source File : SaveIndicationTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void CreateElementConfigurationFor_ShouldCreateElementConfigWithCorrectProperties_WhenModelIsNull()
        {
            mSut.Load();

            IElementConfiguration elementConfiguration = mSut.CreateElementConfigurationFor(null, AppenderDescriptor.Async.ElementName);

            replacedert.IsNull(elementConfiguration.OriginalNode);
            replacedert.AreEqual(AppenderDescriptor.Async.ElementName, elementConfiguration.NewNode.Name);
            replacedert.AreSame(mSut.ConfigXml, elementConfiguration.ConfigXml);
            replacedert.AreSame(mSut.Log4NetNode, elementConfiguration.Log4NetNode);
        }

19 View Source File : SaveIndicationTest.cs
License : MIT License
Project Creator : alexleen

[Test]
        public void CreateElementConfigurationFor_ShouldCreateElementConfigWithCorrectProperties()
        {
            mSut.Load();

            AsyncAppenderModel originalModel = mSut.Children.OfType<AsyncAppenderModel>().First();
            IElementConfiguration elementConfiguration = mSut.CreateElementConfigurationFor(originalModel, AppenderDescriptor.Async.ElementName);

            replacedert.AreSame(originalModel.Node, elementConfiguration.OriginalNode);
            replacedert.AreEqual(AppenderDescriptor.Async.ElementName, elementConfiguration.NewNode.Name);
            replacedert.AreSame(mSut.ConfigXml, elementConfiguration.ConfigXml);
            replacedert.AreSame(mSut.Log4NetNode, elementConfiguration.Log4NetNode);
        }

19 View Source File : StructureClonerTests.cs
License : MIT License
Project Creator : AndresTraks

[Test]
        public void Clone()
        {
            string path = replacedembly.GetExecutingreplacedembly().Location;
            path = Path.GetDirectoryName(path);

            var root = new RootFolderDefinition(Path.Combine(path, "CppTestProject"));
            var header = new HeaderDefinition("header1.h");
            var @namespace = new NamespaceDefinition();
            var @clreplaced = new ClreplacedDefinition("CppClreplaced");
            var @enum = new EnumDefinition("CppEnum");

            root.AddChild(header);

            @namespace.AddChild(@clreplaced);
            header.AddNode(@clreplaced);

            @namespace.AddChild(@enum);
            header.AddNode(@enum);

            var cloner = new StructureCloner();
            cloner.Clone(@namespace);
            var rootClone = cloner.RootFolderClone;
            var rootNamespaceClone = cloner.RootNamespaceClone;


            replacedert.AreNotSame(root, rootClone);
            replacedert.AreEqual(root.FullPath, rootClone.FullPath);
            replacedert.AreEqual(root.Children.Count, rootClone.Children.Count);

            var headerClone = (HeaderDefinition)rootClone.Children.First();
            replacedert.AreNotSame(header, headerClone);
            replacedert.AreSame(rootClone, headerClone.Parent);
            replacedert.AreEqual(2, headerClone.Nodes.Count);

            var clreplacedClone = (ClreplacedDefinition)headerClone.Nodes[0];
            replacedert.AreNotSame(@clreplaced, clreplacedClone);
            replacedert.AreSame(headerClone, clreplacedClone.Header);
            replacedert.AreEqual(@clreplaced.Name, clreplacedClone.Name);
            replacedert.AreEqual(@clreplaced.Children.Count, clreplacedClone.Children.Count);
            replacedert.AreSame(rootNamespaceClone, clreplacedClone.Parent);

            var enumClone = (EnumDefinition)headerClone.Nodes[1];
            replacedert.AreNotSame(@enum, enumClone);
            replacedert.AreSame(headerClone, enumClone.Header);
            replacedert.AreEqual(@enum.Name, enumClone.Name);
            replacedert.AreEqual(@enum.Children.Count, enumClone.Children.Count);
            replacedert.AreSame(rootNamespaceClone, enumClone.Parent);

            replacedert.AreNotSame(@namespace, rootNamespaceClone);
            replacedert.AreEqual(@namespace.Children.Count, rootNamespaceClone.Children.Count);
        }

19 View Source File : DelayedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void ClearThenAdd_Processed_OnlyAddedItemLeft()
        {
            var list = new DelayedList<object>();
            var item = new object();

            Fill(list, 5);
            list.ProcessPending();

            list.Clear();
            list.Add(item);
            list.ProcessPending();

            replacedert.AreEqual(1, list.Count);
            replacedert.AreSame(item, list[0]);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Ascending_LowestPriority_IsAddedFirst()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Ascending);

            Fill(list, -5, 5);
            list.Add(item, -100);

            replacedert.AreSame(item, list[0].Item);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Ascending_HighestPriority_IsAddedLast()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Ascending);

            Fill(list, -5, 5);
            list.Add(item, 100);

            replacedert.AreSame(item, list[list.Count - 1].Item);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Ascending_SamePriority_IsAddedAfterOthers()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Ascending);

            Fill(list, -5, 5);
            list.Add(item, list[3].Priority);

            replacedert.AreSame(item, list[4].Item);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Descending_LowestPriority_IsAddedLast()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, -100);

            replacedert.AreSame(item, list[list.Count - 1].Item);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Descending_HighestPriority_IsAddedFirst()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, 100);

            replacedert.AreSame(item, list[0].Item);
        }

19 View Source File : PrioritizedListTests.cs
License : MIT License
Project Creator : ArchonInteractive

[Test]
        public void Add_Descending_SamePriority_IsAddedAfterOthers()
        {
            var item = new object();
            var list = new PrioritizedList<object>(ListSortDirection.Descending);

            Fill(list, -5, 5);
            list.Add(item, list[3].Priority);

            replacedert.AreSame(item, list[4].Item);
        }

19 View Source File : ElectrodeTest.cs
License : MIT License
Project Creator : Autodesk

[Test]
        public void ParentTest()
        {
            _powerSHAPE.Models.CreateModelFromFile(new File(TestFiles.THREE_ELECTRODES_MODEL));
            var electrode = _powerSHAPE.ActiveModel.Electrodes[1];
            var parent = electrode.Parent;
            replacedert.AreSame(_powerSHAPE.ActiveModel.Electrodes[0], parent);
        }

19 View Source File : ElectrodeTest.cs
License : MIT License
Project Creator : Autodesk

[Test]
        public void CopiesTest()
        {
            _powerSHAPE.Models.CreateModelFromFile(new File(TestFiles.THREE_ELECTRODES_MODEL));
            var electrode = _powerSHAPE.ActiveModel.Electrodes[0];
            var copies = electrode.Copies;
            replacedert.AreSame(_powerSHAPE.ActiveModel.Electrodes[1], copies[0]);
            replacedert.AreSame(_powerSHAPE.ActiveModel.Electrodes[2], copies[1]);
        }

19 View Source File : EntityManagerTests.cs
License : Apache License 2.0
Project Creator : bnoazx005

[Test]
        public void TestGetEnreplacedyById_PreplacedCorrectExistingEnreplacedyId_ReturnsReferenceToIt()
        {
            replacedert.DoesNotThrow(() =>
            {
                IEnreplacedy newEnreplacedy = mEnreplacedyManager.CreateEnreplacedy();

                replacedert.AreSame(newEnreplacedy, mEnreplacedyManager.GetEnreplacedyById(newEnreplacedy.Id));
            });
        }

19 View Source File : WorldContextTests.cs
License : Apache License 2.0
Project Creator : bnoazx005

[Test]
        public void TestGetSingleEnreplacedyWithAll_TryToGetSingleEnreplacedy_ReturnsThatEnreplacedy()
        {
            for (int i = 0; i < 2; ++i)
            {
                mWorldContext.CreateEnreplacedy("JunkEnreplacedy");
            }

            IEnreplacedy expectedEnreplacedy = mWorldContext.GetEnreplacedyById(mWorldContext.CreateEnreplacedy());
            expectedEnreplacedy.AddComponent<TTestComponent>();

            IEnreplacedy actualEnreplacedy = mWorldContext.GetSingleEnreplacedyWithAll(typeof(TTestComponent));
            replacedert.AreSame(expectedEnreplacedy, actualEnreplacedy);
        }

19 View Source File : WorldContextTests.cs
License : Apache License 2.0
Project Creator : bnoazx005

[Test]
        public void TestGetSingleEnreplacedyWithAll_TryToGetAllEnreplacediesWithParticularComponents_ReturnsFirstOne()
        {
            List<IEnreplacedy> enreplacedies = new List<IEnreplacedy>();

            for (int i = 0; i < 3; ++i)
            {
                IEnreplacedy enreplacedy = mWorldContext.GetEnreplacedyById(mWorldContext.CreateEnreplacedy());
                enreplacedies.Add(enreplacedy);

                if (i > 0)
                {
                    enreplacedy.AddComponent<TTestComponent>();
                }
            }

            IEnreplacedy actualEnreplacedy = mWorldContext.GetSingleEnreplacedyWithAll(typeof(TTestComponent));
            replacedert.IsNotNull(actualEnreplacedy);
            replacedert.AreSame(enreplacedies[1], actualEnreplacedy);
        }

19 View Source File : StaticViewsTests.cs
License : Apache License 2.0
Project Creator : bnoazx005

[UnityTest]
    public IEnumerator TestPreInit_CreateNewView_SuccessfullyInvokesPreInitAndCreateRequestEnreplacedy()
    {
        // This execution order imitates scenes loading, for dynamic objects the order doesn't make sense
        var view = TestStaticView.Create();
        var controller = TestController.Create();

        yield return new WaitForEndOfFrame();

        replacedert.IsNotNull(controller);
        replacedert.IsNotNull(view);

        var worldContext = controller.WorldContext;

        replacedert.IsNotNull(worldContext);
        
        var registerRequestsEnreplacedy = worldContext.GetSingleEnreplacedyWithAll(typeof(TOnViewWaitForInitEventComponent));
        replacedert.IsNotNull(registerRequestsEnreplacedy);

        replacedert.DoesNotThrow(() =>
        {
            replacedert.AreSame(view, registerRequestsEnreplacedy.GetComponent<TOnViewWaitForInitEventComponent>().mView);
        });

        yield return new WaitForFixedUpdate();
        yield return new WaitForFixedUpdate();

        replacedert.AreEqual(registerRequestsEnreplacedy.Id, view.LinkedEnreplacedyId);
    }

19 View Source File : ActorTests.cs
License : MIT License
Project Creator : csf-dev

[Test]
    public void GetAbility_returns_instance_when_the_ability_is_possessed()
    {
      // Arrange
      var ability = Mock.Of<SampleAbility>();
      var performer = CreateActor(ability);

      // Act
      var result = performer.GetAbility<SampleAbility>();

      // replacedert
      replacedert.AreSame(ability, result);
    }

19 View Source File : LookupCacheTests.cs
License : MIT License
Project Creator : cyotek

[Test]
    public void Get_returns_existing_item_from_id()
    {
      // arrange
      LookupCache<AccessLevel> target;
      AccessLevel expected;
      AccessLevel actual;
      Dictionary<int, AccessLevel> dict;

      target = new LookupCache<AccessLevel>(null);

      dict = (Dictionary<int, AccessLevel>)target.GetType().GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(target);

      expected = new AccessLevel
                 {
                   Id = 90,
                   Name = "alpha",
                   Label = "beta"
                 };

      dict.Add(expected.Id, expected);

      // act
      actual = target.Get(expected.Id);

      // replacedert
      replacedert.AreSame(expected, actual);
    }

19 View Source File : LookupCacheTests.cs
License : MIT License
Project Creator : cyotek

[Test]
    public void Get_returns_same_object_for_same_id()
    {
      // arrange
      LookupCache<AccessLevel> target;
      Dictionary<string, object> props;
      AccessLevel expected;
      AccessLevel actual;

      target = new LookupCache<AccessLevel>(null);

      props = new Dictionary<string, object>
              {
                {
                  "id", 90
                },
                {
                  "name", "alpha"
                },
                {
                  "label", "beta"
                }
              };

      expected = target.Get(props);

      // act
      actual = target.Get(expected.Id);

      // replacedert
      replacedert.AreSame(expected, actual);
    }

19 View Source File : Decorators.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<S>();

        // singleton decorator effectively makes the decorated service a singleton too.
        container.Register<S, D1>(Reuse.Singleton, setup: Setup.Decorator);

        var s1 = container.Resolve<S>();
        var s2 = container.Resolve<S>();
        replacedert.AreSame(s1, s2);
    }

19 View Source File : Decorators.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<S>(Reuse.Singleton);
        container.Register<S, D1>(setup: Setup.DecoratorWith(useDecorateeReuse: true));

        var s1 = container.Resolve<S>();
        var s2 = container.Resolve<S>();
        replacedert.AreSame(s1, s2); // because of decoratee service reuse.
    }

19 View Source File : Decorators.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var c = new Container();

        // Generic wrapper to extract the FactoryID, we need it to lookup the scope for the created service
        c.Register(typeof(FactoryInfo<>),
           new ExpressionFactory(
               req =>
               {
                   var wrapperType = req.ServiceType;
                   var serviceType = wrapperType.GetGenericParamsAndArgs()[0];
                   var factory = req.Container.ResolveFactory(req.Push(serviceType));
                   return Expression.New(wrapperType.SingleConstructor(), Expression.Constant(factory.FactoryID));
               },
               setup: Setup.Wrapper));

        // Generic decorator applied to all Scoped services (see condition)
        c.Register<object>(
            made: Made.Of(req => GetType().SingleMethod(nameof(GetFromParentOrCurrent)).MakeGenericMethod(req.ServiceType)),
            setup: Setup.DecoratorWith(condition: req => req.Reuse == Reuse.Scoped));

        // Application code
        c.Register<A>(Reuse.Scoped);

        var s = c.OpenScope();
        var a = s.Resolve<A>();

        var ss = s.OpenScope();
        var aa = ss.Resolve<A>();
        replacedert.AreSame(aa, a);

        // health check that the other services are not affected
        c.Register<B>(Reuse.Singleton);
        replacedert.IsNotNull(c.Resolve<B>());
    }

19 View Source File : ExamplesContextBasedResolution.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        // default logger
        container.Register(Made.Of(() => Serilog.Log.Logger),
            setup: Setup.With(condition: r => r.Parent.ImplementationType == null));

        // type dependent logger
        container.Register(
            Made.Of(() => Serilog.Log.ForContext(Arg.Index<Type>(0)), r => r.Parent.ImplementationType),
            setup: Setup.With(condition: r => r.Parent.ImplementationType != null));

        var defaultLogger = container.Resolve<Serilog.ILogger>();
        replacedert.AreSame(Serilog.Log.Logger, defaultLogger);

        container.Register<LogSubject>();
        var s = container.Resolve<LogSubject>();

        replacedert.AreSame(Serilog.Log.ForContext<LogSubject>(), s.Logger);
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<IClient, SomeClient>();

        // making Service dependency a singleton
        container.Register<IService, SomeService>(Reuse.Singleton);

        // consuming part is still the same, win!
        var one = container.Resolve<IClient>();
        var two = container.Resolve<IClient>();

        replacedert.AreSame(two.Service, one.Service);
    }

19 View Source File : ErrorDetectionAndResolution.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<Child>();

        // note the singleton reuse, so that container resolves and injects the same instance of Parent 
        container.Register<Parent>(Reuse.Singleton);

        var parent = container.Resolve<Parent>(); // works just fine
        replacedert.AreSame(parent, parent.Child.Parent);
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container(rules => rules.WithDefaultReuse(Reuse.Scoped));

        container.Register<Abc>();

        using (var scope = container.OpenScope())
        {
            var abc = scope.Resolve<Abc>();
            replacedert.AreSame(abc, scope.Resolve<Abc>());
        }
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<A>(Reuse.Scoped);

        // Three nested scopes
        var s1 = container.OpenScope();
        var s2 = s1.OpenScope();
        var s3 = s2.OpenScope();

        replacedert.AreSame(s1.Resolve<A>(), s1.Resolve<A>());
        replacedert.AreNotSame(s1.Resolve<A>(), s2.Resolve<A>());
        replacedert.AreNotSame(s2.Resolve<A>(), s3.Resolve<A>());
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container(scopeContext: new AsyncExecutionFlowScopeContext());

        container.Register<A>(Reuse.Scoped);

        // Three nested scopes
        var s1 = container.OpenScope();
        var s2 = s1.OpenScope();
        var s3 = s2.OpenScope();

        replacedert.AreSame(s1.Resolve<A>(), s1.Resolve<A>());

        // Here is the difference - all the instances of are the same and stored in the deepest scope `s3`
        replacedert.AreSame(s1.Resolve<A>(), s2.Resolve<A>());
        replacedert.AreSame(s2.Resolve<A>(), s3.Resolve<A>());

        // An `a` will be actually resolved from the `s3` despite that we resolving from the `parent`
        var a = s1.Resolve<A>();

        // We disposed of the `s3` scope, making its parent `s2` a new current scope.
        s3.Dispose();
        replacedert.IsTrue(a.IsDisposed);

        // Now a new instances started to be resolved from `s2`
        replacedert.AreNotSame(a, s2.Resolve<A>());
        replacedert.AreSame(s2.Resolve<A>(), s1.Resolve<A>());
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<Car>(Reuse.ScopedTo("top"));

        using (var s1 = container.OpenScope("top"))
        {
            var car1 = s1.Resolve<Car>();

            using (var s2 = s1.OpenScope())
            {
                var car2 = s2.Resolve<Car>();

                // Cars are the same despite that `car2` is resolved from the nested `s2`,
                // because it was specifically resolved from the matching name scope `s1`
                replacedert.AreSame(car2, car1);
            }
        }
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test] public void Example()
    {
        var container = new Container();

        // `openResolutionScope` option is required to open the scope for the `Foo`
        container.Register<Foo>(setup: Setup.With(openResolutionScope: true));

        container.Register<Dependency>();
        container.Register<SubDependency>(Reuse.ScopedTo<Foo>());

        var foo = container.Resolve<Foo>();
        replacedert.AreSame(foo.Sub, foo.Dep.Sub);
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        container.Register<Mercedes>(Reuse.Singleton);
        container.Register<Dodge>();

        container.Register<Wheels>(setup: Setup.With(useParentReuse: true));

        // same Mercedes with the same Wheels
        var m1 = container.Resolve<Mercedes>();
        var m2 = container.Resolve<Mercedes>();
        replacedert.AreSame(m1.Wheels, m2.Wheels);

        // different Dodges with the different Wheels
        var d1 = container.Resolve<Dodge>();
        var d2 = container.Resolve<Dodge>();
        replacedert.AreNotSame(d1.Wheels, d2.Wheels);
    }

19 View Source File : MefAttributedModel.cs
License : MIT License
Project Creator : dadhi

[Test] public void Example()
    {
        // Using `WithMefAttributedModel` applies the MEF rules where the default reuse is singleton
        var container = new Container().WithMefAttributedModel();
        // alternatively you may apply just the rules
        container = new Container(rules => rules.WithMefAttributedModel());

        container.RegisterExports(
            typeof(A),
            typeof(B),
            typeof(C)
        );

        replacedert.AreSame(container.Resolve<I>(), container.Resolve<J>()); 
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        // Allows registration of B which implements IDisposable as Transient, which is default `RegisterMany` reuse.
        var container = new Container(rules => rules
            .WithTrackingDisposableTransients()); 

        // Registers X, Y and A itself with A implementation 
        container.RegisterMany<A>();

        // Registers only X and Y, but not A itself
        container.RegisterMany<A>(serviceTypeCondition: type => type.IsInterface);

        // X, Y, A are sharing the same singleton
        container.RegisterMany<A>(Reuse.Singleton);
        replacedert.AreSame(container.Resolve<X>(), container.Resolve<Y>());

        // Registers X, Y with A and X with B
        // IDisposable is too general to be considered as a service type, 
        // see the full list of excluded types after example below.
        container.RegisterMany(
            new[] { typeof(A), typeof(B) },
            serviceTypeCondition: type => type.IsInterface);

        // Registers only X with A and X with B
        container.RegisterMany(
            new[] { typeof(A), typeof(B) },
            serviceTypeCondition: type => type == typeof(X));

        // The same as above if A and B in the same replacedembly.
        // Plus registers the rest of the types from replacedembly of A.
        container.RegisterMany(new[] { typeof(A).replacedembly }, type => type == typeof(X));

        // Made.Of expression is supported too
        container.RegisterMany(Made.Of(() => CreateA()));

        // Explicit about what services to register
        container.RegisterMany(new[] { typeof(X), typeof(Y) }, typeof(A));

        // Provides full control to you
        container.RegisterMany(new[] { typeof(A).replacedembly },
            getServiceTypes: implType => implType.GetImplementedServiceTypes(),
            getImplFactory: implType => new ReflectionFactory(implType,
                reuse: implType.IsreplacedignableTo<IDisposable>() ? Reuse.Scoped : Reuse.Transient,
                made: FactoryMethod.ConstructorWithResolvableArguments));
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        // Register I as a singleton S
        container.Register<I, S>(Reuse.Singleton);

        // Map J to I, and therefore map J to the same singleton S
        container.RegisterMapping<J, I>();

        replacedert.AreSame(container.Resolve<I>(), container.Resolve<J>());
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        // Multiple interfaces refer to a single implementation
        container.RegisterMany(new[] { typeof(I), typeof(J) }, typeof(S), Reuse.Singleton);
        replacedert.AreSame(container.Resolve<I>(), container.Resolve<J>());

        replacedert.AreSame(container.Resolve<I>(), container.Resolve<J>());
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();

        var a = new A();
        container.RegisterInstance(a);
        container.Register<B>();

        var b = container.Resolve<B>();
        replacedert.AreSame(a, b.A);
    }

19 View Source File : ReuseAndScopes.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();
        container.Register<A>(Reuse.Singleton);

        var a = container.Resolve<A>();
        replacedert.AreSame(a, container.Resolve<A>());
    }

19 View Source File : Wrappers.cs
License : MIT License
Project Creator : dadhi

[Test] public void Example()
    {
        var container = new Container(rules => rules.ForExpressionGeneration());

        container.Register<A>(Reuse.Singleton);
        container.Register<B>(Reuse.Scoped);

        var expr = container.Resolve<LambdaExpression>(typeof(A));
        var factory = (FactoryDelegate)expr.Compile();

        using (var scope = container.OpenScope())
        {
            var a1 = (A)factory(scope);
            replacedert.AreSame(a1.GetB(), a1.GetB());
        }
    }

19 View Source File : RegisterResolve.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();
        container.Register<B>();

        using (var scope = container.OpenScope())
        {
            var a = new A();
            scope.Use(a); // injected into current open scope

            var b = scope.Resolve<B>(); // will inject `a`
            replacedert.AreSame(a, b.A);
        }

        var anotherA = new A();
        container.Use(anotherA); // injected into singleton scope

        var anotherB = container.Resolve<B>(); // will inject `anotherA`
        replacedert.AreSame(anotherA, anotherB.A);
    }

19 View Source File : RulesAndDefaultConventions.cs
License : MIT License
Project Creator : dadhi

[Test]
    public void Example()
    {
        var container = new Container();
        container.Register<X>(Reuse.Scoped);

        using (var scope = container.OpenScope())
        {
            var x = scope.Resolve<X>();

            // the expected behavior is that `x.Resolver` will be the one from scope, not from container
            replacedert.AreSame(scope, x.Resolver);
        }
    }

See More Examples