public void test_getRequiredTags() { ContainerInstance containerInstance = Model.AddContainerInstance(_database); Assert.Equal(1, containerInstance.getRequiredTags().Count); Assert.True(containerInstance.Tags.Contains(Tags.ContainerInstance)); }
public void Test_AddElementInstance_AddsElementInstancesAndReplicatesRelationshipsWithinTheDeploymentEnvironmentAndDefaultGroup() { SoftwareSystem softwareSystem1 = Model.AddSoftwareSystem("Software System"); Container api = softwareSystem1.AddContainer("API"); Container database = softwareSystem1.AddContainer("Database"); api.Uses(database, "Uses"); DeploymentNode liveDeploymentNode = Model.AddDeploymentNode("Live", "Deployment Node", "Description", "Technology"); ContainerInstance apiInstance1 = liveDeploymentNode.Add(api); ContainerInstance databaseInstance1 = liveDeploymentNode.Add(database); ContainerInstance apiInstance2 = liveDeploymentNode.Add(api); ContainerInstance databaseInstance2 = liveDeploymentNode.Add(database); Assert.Equal(2, apiInstance1.Relationships.Count); Assert.Equal(2, apiInstance2.Relationships.Count); // apiInstance1 -> databaseInstance1 Relationship relationship = apiInstance1.GetEfferentRelationshipWith(databaseInstance1); Assert.Equal("Uses", relationship.Description); // apiInstance1 -> databaseInstance2 relationship = apiInstance1.GetEfferentRelationshipWith(databaseInstance2); Assert.Equal("Uses", relationship.Description); // apiInstance2 -> databaseInstance1 relationship = apiInstance2.GetEfferentRelationshipWith(databaseInstance1); Assert.Equal("Uses", relationship.Description); // apiInstance2 -> databaseInstance2 relationship = apiInstance2.GetEfferentRelationshipWith(databaseInstance2); Assert.Equal("Uses", relationship.Description); }
public void Test_AddElementInstance_AddsElementInstancesAndReplicatesRelationshipsWithinTheDeploymentEnvironmentAndSpecifiedGroup() { // in this test, container instances are added to two deployment groups: "Service 1" and "Service 2" // relationships are not replicated between element instances in other groups SoftwareSystem softwareSystem1 = Model.AddSoftwareSystem("Software System"); Container api = softwareSystem1.AddContainer("API"); Container database = softwareSystem1.AddContainer("Database"); api.Uses(database, "Uses"); DeploymentNode liveDeploymentNode = Model.AddDeploymentNode("Live", "Deployment Node", "Description", "Technology"); ContainerInstance apiInstance1 = liveDeploymentNode.Add(api, "Service 1"); ContainerInstance databaseInstance1 = liveDeploymentNode.Add(database, "Service 1"); ContainerInstance apiInstance2 = liveDeploymentNode.Add(api, "Service 2"); ContainerInstance databaseInstance2 = liveDeploymentNode.Add(database, "Service 2"); Assert.Equal(1, apiInstance1.Relationships.Count); Assert.Equal(1, apiInstance2.Relationships.Count); // apiInstance1 -> databaseInstance1 Relationship relationship = apiInstance1.GetEfferentRelationshipWith(databaseInstance1); Assert.Equal("Uses", relationship.Description); // apiInstance2 -> databaseInstance2 relationship = apiInstance2.GetEfferentRelationshipWith(databaseInstance2); Assert.Equal("Uses", relationship.Description); }
public void Test_AddAnimationStep_ThrowsAnException_WhenContainerInstancesAreSpecifiedButNoneOfThemExistInTheView() { try { SoftwareSystem softwareSystem = Model.AddSoftwareSystem("Software System", ""); Container webApplication = softwareSystem.AddContainer("Web Application", "Description", "Technology"); Container database = softwareSystem.AddContainer("Database", "Description", "Technology"); webApplication.Uses(database, "Reads from and writes to", "JDBC/HTTPS"); DeploymentNode developerLaptop = Model.AddDeploymentNode("Developer Laptop", "Description", "Technology"); DeploymentNode apacheTomcat = developerLaptop.AddDeploymentNode("Apache Tomcat", "Description", "Technology"); DeploymentNode oracle = developerLaptop.AddDeploymentNode("Oracle", "Description", "Technology"); ContainerInstance webApplicationInstance = apacheTomcat.Add(webApplication); ContainerInstance databaseInstance = oracle.Add(database); deploymentView = Views.CreateDeploymentView(softwareSystem, "deployment", "Description"); deploymentView.AddAnimation(webApplicationInstance, databaseInstance); throw new TestFailedException(); } catch (ArgumentException ae) { Assert.Equal("None of the specified container instances exist in this view.", ae.Message); } }
public void Test_AddAnimationStep_IgnoresContainerInstancesThatDoNotExistInTheView() { SoftwareSystem softwareSystem = Model.AddSoftwareSystem("Software System", ""); Container webApplication = softwareSystem.AddContainer("Web Application", "Description", "Technology"); Container database = softwareSystem.AddContainer("Database", "Description", "Technology"); webApplication.Uses(database, "Reads from and writes to", "JDBC/HTTPS"); DeploymentNode developerLaptop = Model.AddDeploymentNode("Developer Laptop", "Description", "Technology"); DeploymentNode apacheTomcat = developerLaptop.AddDeploymentNode("Apache Tomcat", "Description", "Technology"); DeploymentNode oracle = developerLaptop.AddDeploymentNode("Oracle", "Description", "Technology"); ContainerInstance webApplicationInstance = apacheTomcat.Add(webApplication); ContainerInstance databaseInstance = oracle.Add(database); deploymentView = Views.CreateDeploymentView(softwareSystem, "deployment", "Description"); deploymentView.Add(apacheTomcat); deploymentView.AddAnimation(webApplicationInstance, databaseInstance); Animation step1 = deploymentView.Animations.First(step => step.Order == 1); Assert.Equal(3, step1.Elements.Count); Assert.True(step1.Elements.Contains(developerLaptop.Id)); Assert.True(step1.Elements.Contains(apacheTomcat.Id)); Assert.True(step1.Elements.Contains(webApplicationInstance.Id)); Assert.Equal(0, step1.Relationships.Count); }
internal void SetupBindable(TInstance instance) { ContainerInstance = instance; if (ContainerInstance != null) { PropertyInfo = ContainerInstance.GetPropertyInfo(PropertyExpression); } }
private static string BuildConnectionString(string endpoint, ContainerInstance instance) { return ($"DefaultEndpointsProtocol=http;AccountName={DevStorageAccountName};" + $"AccountKey={DevKey};" + $"{endpoint}=http://127.0.0.1:{instance.HostPort}/" + $"{DevStorageAccountName};"); }
public void Test_construction() { ContainerInstance containerInstance = Model.AddContainerInstance(_deploymentNode, _database, "Default"); Assert.Same(_database, containerInstance.Container); Assert.Equal(_database.Id, containerInstance.ContainerId); Assert.Equal(1, containerInstance.InstanceId); }
public void test_construction() { ContainerInstance containerInstance = Model.AddContainerInstance(_database); Assert.Same(_database, containerInstance.Container); Assert.Equal(_database.Id, containerInstance.ContainerId); Assert.Equal(1, containerInstance.InstanceId); }
public void Ctor_ShouldRegisterBaseTypeWithContainer() { // Arrange + Act var objectInfo = new ContainerInstance(this.registeredType, this.container); // Assert Assert.IsTrue(this.container.IsRegistered(this.registeredType)); }
public void test_getName() { ContainerInstance containerInstance = Model.AddContainerInstance(_database); Assert.Null(containerInstance.Name); containerInstance.Name = "foo"; Assert.Null(containerInstance.Name); }
public void test_getTags() { _database.AddTags("Database"); ContainerInstance containerInstance = Model.AddContainerInstance(_deploymentNode, _database, "Default"); containerInstance.AddTags("Primary Instance"); Assert.Equal("Container Instance,Primary Instance", containerInstance.Tags); }
public void Test_Name() { ContainerInstance containerInstance = Model.AddContainerInstance(_deploymentNode, _database, "Default"); Assert.Equal(_database.Name, containerInstance.Name); containerInstance.Name = "foo"; Assert.Equal(_database.Name, containerInstance.Name); }
public void Test_ContainerId() { ContainerInstance containerInstance = Model.AddContainerInstance(_deploymentNode, _database, "Default"); Assert.Equal(_database.Id, containerInstance.ContainerId); containerInstance.Container = null; containerInstance.ContainerId = "1234"; Assert.Equal("1234", containerInstance.ContainerId); }
public void test_getContainerId() { ContainerInstance containerInstance = Model.AddContainerInstance(_database); Assert.Equal(_database.Id, containerInstance.ContainerId); containerInstance.Container = null; containerInstance.ContainerId = "1234"; Assert.Equal("1234", containerInstance.ContainerId); }
public void test_getTags() { _database.AddTags("Database"); ContainerInstance containerInstance = Model.AddContainerInstance(_database); containerInstance.AddTags("Primary Instance"); Assert.Equal("Element,Container,Database,Container Instance,Primary Instance", containerInstance.Tags); }
public void test_uses_ThrowsAnException_WhenADestinationIsNotSpecified() { ContainerInstance containerInstance = Model.AddContainerInstance(_database); try { containerInstance.Uses(null, "", ""); } catch (ArgumentException ae) { Assert.Equal("The destination of a relationship must be specified.", ae.Message); } }
public void test_removeTags_DoesNotRemoveRequiredTags() { ContainerInstance containerInstance = Model.AddContainerInstance(_deploymentNode, _database); Assert.True(containerInstance.Tags.Contains(Tags.ContainerInstance)); containerInstance.RemoveTag(Tags.ContainerInstance); Assert.True(containerInstance.Tags.Contains(Tags.ContainerInstance)); }
public void Resolve_TypeDoesntHaveSpecifiedConstructor_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(typeof(ServiceWithoutInjectAttributeStub), this.container); // Act TestDelegate action = () => objectInfo.Resolve(); // Assert Assert.Throws <NotSupportedException>(action, string.Format(CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_CannotFindConstructorForType, typeof(ServiceWithoutInjectAttributeStub))); }
public void test_add_AddsAContainerInstance_WhenAContainerIsSpecified() { SoftwareSystem softwareSystem = Model.AddSoftwareSystem("Software System", ""); Container container = softwareSystem.AddContainer("Container", "", ""); DeploymentNode deploymentNode = Model.AddDeploymentNode("Deployment Node", "", ""); ContainerInstance containerInstance = deploymentNode.Add(container); Assert.NotNull(containerInstance); Assert.Same(container, containerInstance.Container); Assert.True(deploymentNode.ContainerInstances.Contains(containerInstance)); }
public void And_PassNullInstance_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); // Act TestDelegate act = () => objectInfo.And(null); // Assert Assert.Throws <ArgumentNullException>(act); }
public void GenericAnd_PassNewType_ShouldRegisterTypeWithContainer() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); // Act objectInfo.And <IServiceStub2>(); // Assert Assert.IsTrue(this.container.IsRegistered <IServiceStub2>()); }
public void And_PassNullInstance_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); // Act TestDelegate act = () => objectInfo.And(null); // Assert Assert.Throws<ArgumentNullException>(act); }
public void And_PassNewType_ShouldRegisterTypeWithContainer() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); var type = typeof(IServiceStub2); // Act objectInfo.And(type); // Assert Assert.IsTrue(this.container.IsRegistered<IServiceStub2>()); }
public void Test_AddAllDeploymentNodes_DoesNothing_WhenThereNoDeploymentNodesForTheDeploymentEnvironment() { SoftwareSystem softwareSystem = Model.AddSoftwareSystem("Software System", ""); Container container = softwareSystem.AddContainer("Container", "Description", "Technology"); DeploymentNode deploymentNode = Model.AddDeploymentNode("Deployment Node", "Description", "Technology"); ContainerInstance containerInstance = deploymentNode.Add(container); deploymentView = Views.CreateDeploymentView(softwareSystem, "deployment", "Description"); deploymentView.Environment = "Live"; deploymentView.AddAllDeploymentNodes(); Assert.Equal(0, deploymentView.Elements.Count); }
public void Test_AddContainerInstance_AddsAContainerInstance_WhenAContainerIsSpecified() { DeploymentNode developmentDeploymentNode = Model.AddDeploymentNode("Development", "Deployment Node", "Description", "Technology"); SoftwareSystem softwareSystem1 = Model.AddSoftwareSystem("Software System 1", "Description"); Container container1 = softwareSystem1.AddContainer("Container 1", "Description", "Technology"); SoftwareSystem softwareSystem2 = Model.AddSoftwareSystem("Software System 2", "Description"); Container container2 = softwareSystem2.AddContainer("Container 2", "Description", "Technology"); SoftwareSystem softwareSystem3 = Model.AddSoftwareSystem("Software System 3", "Description"); Container container3 = softwareSystem3.AddContainer("Container 3", "Description", "Technology"); container1.Uses(container2, "Uses 1", "Technology 1", InteractionStyle.Synchronous); container2.Uses(container3, "Uses 2", "Technology 2", InteractionStyle.Asynchronous); ContainerInstance containerInstance1 = Model.AddContainerInstance(developmentDeploymentNode, container1); ContainerInstance containerInstance2 = Model.AddContainerInstance(developmentDeploymentNode, container2); ContainerInstance containerInstance3 = Model.AddContainerInstance(developmentDeploymentNode, container3); // the following live container instances should not affect the relationships of the development container instances DeploymentNode liveDeploymentNode = Model.AddDeploymentNode("Live", "Deployment Node", "Description", "Technology"); liveDeploymentNode.Add(container1); liveDeploymentNode.Add(container2); liveDeploymentNode.Add(container3); Assert.Same(container2, containerInstance2.Container); Assert.Equal(container2.Id, containerInstance2.ContainerId); Assert.Same(softwareSystem2, containerInstance2.Parent); Assert.Equal("/Software System 2/Container 2[1]", containerInstance2.CanonicalName); Assert.Equal("Container Instance", containerInstance2.Tags); Assert.Equal("Development", containerInstance2.Environment); Assert.Equal(1, containerInstance1.Relationships.Count); Relationship relationship = containerInstance1.Relationships.First(); Assert.Same(containerInstance1, relationship.Source); Assert.Same(containerInstance2, relationship.Destination); Assert.Equal("Uses 1", relationship.Description); Assert.Equal("Technology 1", relationship.Technology); Assert.Equal(InteractionStyle.Synchronous, relationship.InteractionStyle); Assert.Equal("", relationship.Tags); Assert.Equal(1, containerInstance2.Relationships.Count); relationship = containerInstance2.Relationships.First(); Assert.Same(containerInstance2, relationship.Source); Assert.Same(containerInstance3, relationship.Destination); Assert.Equal("Uses 2", relationship.Description); Assert.Equal("Technology 2", relationship.Technology); Assert.Equal(InteractionStyle.Asynchronous, relationship.InteractionStyle); Assert.Equal("", relationship.Tags); }
private void Write(ContainerInstance containerInstance, TextWriter writer, int indent) { writer.Write( String.Format("{0}artifact \"{1}\" <<{2}>> as {3}", CalculateIndent(indent), containerInstance.Container.Name, TypeOf(containerInstance), containerInstance.Id ) ); writer.Write(Environment.NewLine); }
public void Resolve_AsSingletonWithoutImplementationForMoreThanOneType_ThrowException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.And(typeof(ServiceStub)); // Act TestDelegate act = objectInfo.AsSingleton; // Assert Assert.Throws <NotSupportedException>(act, InversionOfControlResources.ErrMsg_CannotRegisterTypeAsSingleton); }
public override void Init() { base.Init(); if (null != ContainerInstance) { IEnumerable <IObjectToucher <HttpApplication> > touchers = ContainerInstance.ResolveAll <IObjectToucher <HttpApplication> >(); foreach (IObjectToucher <HttpApplication> toucher in touchers) { toucher.Touch(this); } } }
public void Resolve_SetTypeImplementationAsSingletonWithGenericMethod_ShouldCreateNewInstance() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.AsSingleton <ServiceStub>(); // Act var serviceStub = objectInfo.Resolve(); // Assert Assert.IsInstanceOf(typeof(ServiceStub), serviceStub); }
public void test_uses_AddsARelationship_WhenADestinationIsSpecified() { Container database = _softwareSystem.AddContainer("Database", "", ""); ContainerInstance primaryDatabase = Model.AddContainerInstance(database); ContainerInstance secondaryDatabase = Model.AddContainerInstance(database); Relationship relationship = primaryDatabase.Uses(secondaryDatabase, "Replicates data to", "Some technology"); Assert.Same(primaryDatabase, relationship.Source); Assert.Same(secondaryDatabase, relationship.Destination); Assert.Equal("Replicates data to", relationship.Description); Assert.Equal("Some technology", relationship.Technology); }
public void Test_AddAllDeploymentNodes_AddsDeploymentNodesAndContainerInstances_WhenThereAreTopLevelDeploymentNodesWithContainerInstances() { SoftwareSystem softwareSystem = Model.AddSoftwareSystem("Software System", ""); Container container = softwareSystem.AddContainer("Container", "Description", "Technology"); DeploymentNode deploymentNode = Model.AddDeploymentNode("Deployment Node", "Description", "Technology"); ContainerInstance containerInstance = deploymentNode.Add(container); deploymentView = Views.CreateDeploymentView(softwareSystem, "deployment", "Description"); deploymentView.AddAllDeploymentNodes(); Assert.Equal(2, deploymentView.Elements.Count); Assert.True(deploymentView.Elements.Contains(new ElementView(deploymentNode))); Assert.True(deploymentView.Elements.Contains(new ElementView(containerInstance))); }
public void As_SetInterfaceAsTypeImplementation_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); // Act TestDelegate testDelegate = () => objectInfo.As(typeof(IServiceStubParent1)); // Assert Assert.Throws<ArgumentException>( testDelegate, string.Format( CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_CannotSetInterfaceAsImplementation, typeof(IServiceStubParent1))); }
public void As_SetTypeImplementationWithWrongTypeForOneOfTwoServices_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.And<IServiceProvider>(); // Act TestDelegate testDelegate = () => objectInfo.As(typeof(ServiceStub)); // Assert Assert.Throws<ArgumentException>( testDelegate, string.Format( CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_CannotSetTypeAsImplementation, typeof(ServiceStub), typeof(IServiceProvider))); }
public IResult Render(ContainerInstance component) { return component.RenderingInstructions.AnnotateComponentPaths ? new AnnotatedResult(this.inner.Render(component), component.Path) : this.inner.Render(component); }
public void InjectionRule_TwoTypesRegistered_ResolvedWithTypeFromRule() { // Arrange var serviceStub1 = new ServiceStub(); var serviceStub2 = new ServiceStub(); this.registrationContext.Register<IServiceStub1>().AsSingleton(serviceStub1); this.registrationContext.Register<IServiceStub2>().AsSingleton(serviceStub2); var objectInfo = new ContainerInstance(typeof(ServiceWithStubBaseInjection), this.container); objectInfo.As(typeof(ServiceWithStubBaseInjection)); // Act objectInfo.InjectionRule(typeof(IServiceStubBase), typeof(IServiceStub2)); var stub = (ServiceWithStubBaseInjection)objectInfo.Resolve(); // Assert Assert.AreEqual(serviceStub2, stub.Child); }
public void Resolve_AsSingletonWithoutImplementationForMoreThanOneType_ThrowException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.And(typeof(ServiceStub)); // Act TestDelegate act = objectInfo.AsSingleton; // Assert Assert.Throws<NotSupportedException>(act, InversionOfControlResources.ErrMsg_CannotRegisterTypeAsSingleton); }
public void Resolve_AsSingletonWithoutImplementation_ShouldReturnTheSameInstance() { // Arrange var objectInfo = new ContainerInstance(typeof(ServiceStub), this.container); objectInfo.AsSingleton(); // Act var serviceStub1 = objectInfo.Resolve(); var serviceStub2 = objectInfo.Resolve(); // Assert Assert.AreSame(serviceStub1, serviceStub2); }
public void Resolve_ResolveTypeWithDependency_ShouldAskContainerToResolveArgumentsForCtor() { // Arrange var serviceStub = new ServiceStub(); this.registrationContext.Register<IServiceStub1>().AsSingleton(serviceStub); var objectInfo = new ContainerInstance(typeof(ServiceWithDependencyStub), this.container); objectInfo.As(typeof(ServiceWithDependencyStub)); // Act var result = (ServiceWithDependencyStub)objectInfo.Resolve(); // Assert Assert.AreEqual(serviceStub, result.Child); }
public void Resolve_SetFactory_ShouldCreateNewInstanceEachTime() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.As(() => new ServiceStub()); // Act var serviceStub1 = objectInfo.Resolve(); var serviceStub2 = objectInfo.Resolve(); // Assert Assert.AreNotSame(serviceStub1, serviceStub2); }
public void Resolve_SetTypeImplementation_ShouldCreateNewInstance() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.As(typeof(ServiceStub)); // Act var serviceStub = objectInfo.Resolve(); // Assert Assert.IsInstanceOf(typeof(ServiceStub), serviceStub); }
public IResult Render(ContainerInstance container) { throw new NotImplementedException(); }
public void As_SetTypeImplementationWithWrongType_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); // Act TestDelegate testDelegate = () => objectInfo.As(typeof(UTF8Encoding)); // Assert Assert.Throws<ArgumentException>( testDelegate, string.Format( CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_CannotSetTypeAsImplementation, typeof(UTF8Encoding), this.registeredType)); }
public void Resolve_WithArguments_ShouldUseArguments() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); const string A = "Test"; const int B = 10; objectInfo.As(typeof(ServiceWithConstructorStub)); // Act var result = (ServiceWithConstructorStub)objectInfo.Resolve(new object[] { A, B }); // Assert Assert.AreEqual(A, result.A); Assert.AreEqual(B, result.B); }
public void Resolve_TypeWithPrivateMethodInjection_ShouldInjectMethod() { // Arrange var serviceStub1 = new ServiceStub(); this.registrationContext.Register<IServiceStub1>().AsSingleton(serviceStub1); var objectInfo = new ContainerInstance(typeof(ServiceWithPrivateMethodInjection), this.container); objectInfo.As(typeof(ServiceWithPrivateMethodInjection)); // Act var result = (ServiceWithPrivateMethodInjection)objectInfo.Resolve(); // Assert Assert.AreEqual(serviceStub1, result.Child); }
public void Resolve_TypeDoesntHaveSpecifiedConstructor_ThrowsException() { // Arrange var objectInfo = new ContainerInstance(typeof(ServiceWithoutInjectAttributeStub), this.container); // Act TestDelegate action = () => objectInfo.Resolve(); // Assert Assert.Throws<NotSupportedException>(action, string.Format(CultureInfo.CurrentCulture, InversionOfControlResources.ErrMsg_CannotFindConstructorForType, typeof(ServiceWithoutInjectAttributeStub))); }
public void Resolve_SetTypeImplementation_ShouldCreateNewInstanceEachTime() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.As(typeof(ServiceStub)); // Act var serviceStub1 = objectInfo.Resolve(); var serviceStub2 = objectInfo.Resolve(); // Assert Assert.AreNotSame(serviceStub1, serviceStub2); }
public IResult Render(ContainerInstance container) { var result = this.rendererFactory.GetContainerRenderer(container.Name).Render(container); return this.Annotate(container, result); }
public void Resolve_SetInstanceAsSingleton_ShouldReturnTheSameInstance() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); var instance = new ServiceStub(); objectInfo.AsSingleton(instance); // Act var serviceStub1 = objectInfo.Resolve(); // Assert Assert.AreSame(instance, serviceStub1); }
public void Resolve_SetFactory_ShouldCreateNewInstance() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); var serviceStub = new ServiceStub(); objectInfo.As(() => serviceStub); // Act var result = objectInfo.Resolve(); // Assert Assert.AreEqual(serviceStub, result); }
public void Resolve_SetTypeImplementationAsSingletonWithGenericMethod_ShouldCreateTheSameInstance() { // Arrange var objectInfo = new ContainerInstance(this.registeredType, this.container); objectInfo.AsSingleton<ServiceStub>(); // Act var serviceStub1 = objectInfo.Resolve(); var serviceStub2 = objectInfo.Resolve(); // Assert Assert.AreSame(serviceStub1, serviceStub2); }