StructureMap Issue in Initializing the Dependencies

Posted by azamsharp on Stack Overflow See other posts from Stack Overflow or by azamsharp
Published on 2010-05-27T21:30:18Z Indexed on 2010/05/27 21:31 UTC
Read the original article Hit count: 330

Filed under:
|

I am performing some unit tests and want my MembershipProvider to initialize the dependencies. I run the following code before any test is executed [TestFixtureSetup].

public static void StructureMapConfiguration()
        {
            ObjectFactory.Initialize(InitializeUsingScanning);


        }

        private static void InitializeUsingScanning(IInitializationExpression obj)
        {
            obj.Scan(
                x =>
                    {
                        x.Assembly("EStudyMongoDb.Business");
                        x.WithDefaultConventions();
                    }

                );
        }

Here is my EstablishContext method which is triggered before running any test:

 public override void EstablishContext()
        {
            _provider = ObjectFactory.GetInstance<MongoDbMembershipProvider>(); 

            _config.Add("applicationName", "EStudyApplication");
            _config.Add("name", "EStudyMembershipProvider");
            _config.Add("requiresQuestionAndAnswer", "false");

            _provider.Initialize(_config["name"], _config);
        } 

Here is my test:

 [TestFixture]
    public class when_creating_a_new_user : specification_for_membership_provider 
    {         

        public override void When()
        {
            _user = _provider.CreateUser("johndoe", "password", "[email protected]", String.Empty, String.Empty,
              true, null, out _status);
        }

        [Test]        
        public void should_create_successfully()
        {
            var vUser = Membership.GetUser(_user.UserName);
            Assert.IsNotNull(vUser);             
        }
    }

Now, in the Membership.GetUser method I try to access the _userRepository but I get null.

© Stack Overflow or respective owner

Related posts about c#

Related posts about structuremap