コード例 #1
0
 private AccountUser CreateBasicUser()
 {
     return(ObjectActivator.CreateInstance <AccountUser>()
            .Set(x => x.AccountId, AccountId)
            .Set(x => x.Created, Removed.AddDays(-10))
            .Set(x => x.UserRef, UserRef));
 }
コード例 #2
0
        public void FinalizeInstanceWithDependencyDefined()
        {
            ObjectActivatorTests.TestActivator <IActivatorTest, ActivatorTest>(container =>
            {
                // Arrange...
                // ... register more items into the container...
                var newBuilder = new ContainerBuilder();
                newBuilder
                .RegisterType <ActivatorWithDependencyTest>()
                .As <IDependentActivatorTest>();
                newBuilder
                .RegisterType <ObjectPortal <IDependentActivatorTest> >()
                .As <IObjectPortal <IDependentActivatorTest> >();
                // ... append new registrations to the container given by the TestActivator Action...
                newBuilder.Update(container);
                // ... still arranging...
                var activator = new ObjectActivator(container);
                var obj       = activator.CreateInstance(typeof(IDependentActivatorTest));
                activator.InitializeInstance(obj);

                // Act...
                activator.FinalizeInstance(obj);

                // Assert...
                ActivatorWithDependencyTest target = (ActivatorWithDependencyTest)obj;
                var aDependency = target.GetType().GetProperty("ADependency", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(target, null);
                Assert.IsNull(aDependency);
            });
        }
        public SeedAccountUsersJobTestsFixture AddUserOwnerRoleToReadStore()
        {
            ReadStoreUsers.Add(ObjectActivator.CreateInstance <AccountUser>()
                               .Set(x => x.UserRef, UserOwnerRole.User.Ref)
                               .Set(x => x.AccountId, UserOwnerRole.AccountId));

            return(this);
        }
コード例 #4
0
 public void CreateInstanceWithConcreteType()
 {
     ObjectActivatorTests.TestActivator(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(ActivatorTest));
         Assert.IsInstanceOfType(result, typeof(IActivatorTest));
     });
 }
コード例 #5
0
 public void CreateInstanceOfInterfaceImplementedByAChildType()
 {
     ObjectActivatorTests.TestActivator <IChildType, ChildType>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(IObjectPortal <IChildType>));
         Assert.IsInstanceOfType(obj, typeof(IObjectPortal <IChildType>));
     });
 }
コード例 #6
0
 public void CreateInstanceWithInterfaceType()
 {
     ObjectActivatorTests.TestActivator <IDependentActivatorTest, ActivatorWithDependencyTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(IDependentActivatorTest));
         Assert.IsInstanceOfType(result, typeof(IDependentActivatorTest));
     });
 }
コード例 #7
0
 public void CreateInstanceWithInterfaceTypeForAReadOnlyItem()
 {
     ObjectActivatorTests.TestActivator <IActivatorROTest, ActivatorROTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var result    = activator.CreateInstance(typeof(IActivatorROTest));
         Assert.IsInstanceOfType(result, typeof(IActivatorROTest));
     });
 }
コード例 #8
0
        public UpdateAccountLegalEntityNameCommandHandlerTestsFixture()
        {
            OriginalAccountLegalEntityName = "Foo";
            Now = DateTime.UtcNow;
            AccountLegalEntity = ObjectActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 1).Set(ale => ale.Name, OriginalAccountLegalEntityName);
            Command            = new UpdateAccountLegalEntityNameCommand(AccountLegalEntity.Id, "Bar", Now.AddHours(-1));
            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Db.AccountLegalEntities.Add(AccountLegalEntity);
            Db.SaveChanges();

            Handler = new UpdateAccountLegalEntityNameCommandHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db));
        }
        public HealthCheckEventHandlerTestsFixture()
        {
            Db = new Mock <EmployerAccountsDbContext>();

            HealthChecks = new List <HealthCheck>
            {
                ObjectActivator.CreateInstance <HealthCheck>().Set(x => x.Id, 1),
                ObjectActivator.CreateInstance <HealthCheck>().Set(x => x.Id, 2)
            };

            Db.Setup(d => d.HealthChecks).Returns(new DbSetStub <HealthCheck>(HealthChecks));

            Handler = new HealthCheckEventHandler(new Lazy <EmployerAccountsDbContext>(() => Db.Object));
        }
        public AddAccountLegalEntityCommandHandlerTestsFixture()
        {
            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Account = ObjectActivator.CreateInstance <Account>().Set(a => a.Id, 1);

            Db.Accounts.Add(Account);
            Db.SaveChanges();

            Command = new AddAccountLegalEntityCommand(Account.Id, 2, 202, "ALE123", "Foo",
                                                       OrganisationType.CompaniesHouse, "REFNo", "Address", DateTime.UtcNow);

            Handler = new AddAccountLegalEntityCommandHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db));
        }
コード例 #11
0
        public RemoveAccountLegalEntityCommandHandlerTestsFixture()
        {
            Now                = DateTime.UtcNow;
            Account            = ObjectActivator.CreateInstance <Account>().Set(a => a.Id, 1);
            AccountLegalEntity = ObjectActivator.CreateInstance <AccountLegalEntity>().Set(ale => ale.Id, 2).Set(ale => ale.AccountId, Account.Id);
            Command            = new RemoveAccountLegalEntityCommand(Account.Id, AccountLegalEntity.Id, Now.AddHours(-1));
            Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder <ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);

            Db.Accounts.Add(Account);
            Db.AccountLegalEntities.Add(AccountLegalEntity);
            Db.SaveChanges();

            Handler           = new RemoveAccountLegalEntityCommandHandler(new Lazy <ProviderCommitmentsDbContext>(() => Db));
            UnitOfWorkContext = new UnitOfWorkContext();
        }
コード例 #12
0
 public void CreateInstanceOfInterfaceNotImplementedByAnyConcreteClass()
 {
     try
     {
         ObjectActivatorTests.TestActivator(container =>
         {
             var activator = new ObjectActivator(container);
             var obj       = activator.CreateInstance(typeof(ImplementedByNobodyInDifferentAssembly));
         });
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(ConcreteTypeResolutionException));
     }
 }
コード例 #13
0
 public void CreateInstanceOfInterfaceMappingToSeveralConcreteClasses()
 {
     ObjectActivatorTests.TestActivator <ImplementedMultipleByTypeInDifferentAssembly, ActivatorTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(ImplementedMultipleByTypeInDifferentAssembly));
         Assert.IsInstanceOfType(obj, typeof(ImplementedMultipleByTypeInDifferentAssembly));
     });
     ObjectActivatorTests.TestActivator <ImplementedMultipleByTypeInDifferentAssembly, ActivatorWithDependencyTest>(container =>
     {
         var activator = new ObjectActivator(container);
         var obj       = activator.CreateInstance(typeof(ImplementedMultipleByTypeInDifferentAssembly));
         Assert.IsInstanceOfType(obj, typeof(ImplementedMultipleByTypeInDifferentAssembly));
     });
 }
コード例 #14
0
 public void InitializeInstanceWithDependencyNotDefined()
 {
     try
     {
         ObjectActivatorTests.TestActivator <IDependentActivatorTest, ActivatorWithDependencyTest>(container =>
         {
             var activator = new ObjectActivator(container);
             var obj       = activator.CreateInstance(typeof(IDependentActivatorTest));
             activator.InitializeInstance(obj);
         });
     }
     catch (Exception ex)
     {
         Assert.IsInstanceOfType(ex, typeof(IoCRegistrationException));
     }
 }
コード例 #15
0
        public UpdateLevyDeclarationTransactionBalancesCommandHandlerTestsFixture()
        {
            Fixture = new Fixture();
            Now     = DateTime.UtcNow;

            EmployerReferenceNumbers = new List <string>
            {
                "AAA111",
                "BBB222",
                "CCC333"
            };

            Accounts = new List <Account>
            {
                Fixture.Create <Account>().Set(a => a.Id, 1),
                Fixture.Create <Account>().Set(a => a.Id, 2)
            };

            AccountPayeSchemes = new List <AccountPayeScheme>
            {
                new AccountPayeScheme(Accounts[0], EmployerReferenceNumbers[0], Now).Set(aps => aps.Id, 3),
                new AccountPayeScheme(Accounts[0], EmployerReferenceNumbers[1], Now).Set(aps => aps.Id, 4),
                new AccountPayeScheme(Accounts[1], EmployerReferenceNumbers[2], Now).Set(aps => aps.Id, 5)
            };

            Saga = ObjectActivator.CreateInstance <LevyDeclarationSaga>().Set(s => s.Id, 6);

            LevyDeclarationSagaTasks = AccountPayeSchemes
                                       .Select(aps => LevyDeclarationSagaTask.CreateImportPayeSchemeLevyDeclarationsTask(Saga.Id, aps.Id))
                                       .ToList();

            Command        = new UpdateLevyDeclarationTransactionBalancesCommand(Saga.Id);
            Db             = new EmployerFinanceDbContext(new DbContextOptionsBuilder <EmployerFinanceDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            UniformSession = new Mock <IUniformSession>();

            Db.AccountPayeSchemes.AddRange(AccountPayeSchemes);
            Db.LevyDeclarationSagas.Add(Saga);
            Db.LevyDeclarationSagaTasks.AddRange(LevyDeclarationSagaTasks);
            Db.SaveChanges();

            Handler = new UpdateLevyDeclarationTransactionBalancesCommandHandler(Db, UniformSession.Object);
        }
        public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture()
        {
            Fixture           = new Fixture();
            Now               = DateTime.UtcNow;
            UnitOfWorkContext = new UnitOfWorkContext();

            PayeSchemeRefs = new List <string>
            {
                "AAA111",
                "BBB222",
                "CCC333"
            };

            Accounts = new List <Account>
            {
                Fixture.Create <Account>(),
                Fixture.Create <Account>()
            };

            AccountPayeSchemes = new List <AccountPayeScheme>
            {
                new AccountPayeScheme(Accounts[0], PayeSchemeRefs[0], Now).Set(aps => aps.Id, 1),
                new AccountPayeScheme(Accounts[0], PayeSchemeRefs[1], Now).Set(aps => aps.Id, 2),
                new AccountPayeScheme(Accounts[1], PayeSchemeRefs[2], Now).Set(aps => aps.Id, 3)
            };

            Saga = ObjectActivator.CreateInstance <LevyDeclarationSaga>()
                   .Set(s => s.Id, 4)
                   .Set(s => s.PayrollPeriod, Now);

            Command = new UpdateLevyDeclarationSagaProgressCommand(Saga.Id);

            Db             = new EmployerFinanceDbContext(new DbContextOptionsBuilder <EmployerFinanceDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            UniformSession = new Mock <IUniformSession>();

            Db.AccountPayeSchemes.AddRange(AccountPayeSchemes);
            Db.LevyDeclarationSagas.Add(Saga);
            Db.SaveChanges();

            Handler = new UpdateLevyDeclarationSagaProgressCommandHandler(Db, UniformSession.Object);
        }
コード例 #17
0
        static async void Test1()
        {
            var             connectionString = "data source=**;database=**;uid=**;Password=**;connection reset=false;Connection Timeout=30;Connection Lifetime=30;min pool size=0; max pool size=50;";
            ObjectActivator oa = new ObjectActivator();

            using (var conn = new SqlConnection(connectionString))
            {
                using (var cmd = new SqlCommand("SELECT TOP 20 [ApiId],[InUser],[InDate] FROM [dbo].[ApiFamily]", conn))
                {
                    await conn.OpenAsync();

                    var reader = await cmd.ExecuteReaderAsync();

                    var list = oa.CreateInstance <ApiFamilyEntity>(reader).ToList();
                    Console.WriteLine($"The End!!! List Count = {list.Count}");
                    foreach (var item in list)
                    {
                        Console.WriteLine($"ApiId={item.ApiId}, InUser={item.InUser}, InDate={item.InDate}");
                    }
                }
            }
        }
コード例 #18
0
 public object ActivateObjectWithAPrivateParameterlessConstructor()
 {
     return(ObjectActivator.CreateInstance <ObjectWithPrivateProperties>());
 }
コード例 #19
0
 public object ActivateObjectWitNoParameterlessConstructor()
 {
     return(ObjectActivator.CreateInstance <ObjectWithNoParameterlessConstructor>());
 }
 public ObjectWithPrivateProperties Activate()
 {
     return(ObjectActivator.CreateInstance <ObjectWithPrivateProperties>());
 }
 private AccountUser CreateBasicUser()
 {
     return(ObjectActivator.CreateInstance <AccountUser>()
            .Set(x => x.AccountId, AccountId)
            .Set(x => x.UserRef, UserRef));
 }
コード例 #22
0
 private AccountUser CreateBasicMatchingAccountUserObject()
 {
     return(ObjectActivator.CreateInstance <AccountUser>()
            .Set(x => x.UserRef, Query.UserRef)
            .Set(x => x.AccountId, Query.AccountId));
 }