public void ShouldGetNoCurrentSchoolYearWhenAmbiguous()
        {
            // Under normal circumstances, 1 or 0 rows in the edfi.SchoolYearType
            // table will be marked as current. However, we should not use a
            // strict SingleOrDefault behavior when fetching the current year.
            // If we did, users would experience an exception when we would
            // rather give them the opportunity to fix their year setting.
            // So, when the table is ambiguous, we expect null, the same
            // as when there are zero records marked as current.

            GetNewSchoolYear(2000);
            GetNewSchoolYear(1999);
            GetNewSchoolYear(2001);
            GetCurrentSchoolYear().ShouldBe(null);

            // Create an ambiguous, meaningless selection of multiple years.
            using (var connection = TestConnectionProvider.CreateNewConnection(InstanceName, ApiMode))
                connection.Execute(@"UPDATE edfi.SchoolYearType SET CurrentSchoolYear='true'");

            // Rather than throwing, the user should experience this as no valid selection.
            GetCurrentSchoolYear().ShouldBe(null);

            // Users can correct the problem by selecting a year.
            SetSchoolYear(2000);
            GetCurrentSchoolYear().ShouldBeSchoolYear(2000, isCurrent: true);
        }
示例#2
0
        public async Task CountTheConnections()
        {
            var activeConnections = new ConcurrentDictionary <int, object>();

            var bus = Configure.With(new BuiltinHandlerActivator())
                      .Transport(t => t.Register(c =>
            {
                var connectionProvider = new TestConnectionProvider(SqlTestHelper.ConnectionString, activeConnections);
                var transport          = new SqlServerTransport(connectionProvider, "RebusMessages", "bimse", c.Get <IRebusLoggerFactory>(), c.Get <IAsyncTaskFactory>());

                transport.EnsureTableIsCreated();

                return(transport);
            }))
                      .Start();

            using (var printTimer = new Timer(1000))
            {
                printTimer.Elapsed += delegate
                {
                    Console.WriteLine("Active connections: {0}", activeConnections.Count);
                };
                printTimer.Start();

                using (bus)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }
        }
        public async Task CountTheConnections()
        {
            var activeConnections = new ConcurrentDictionary<int, object>();

            var bus = Configure.With(new BuiltinHandlerActivator())
                .Transport(t => t.Register(c =>
                {
                    var connectionProvider = new TestConnectionProvider(SqlTestHelper.ConnectionString, activeConnections);
                    var transport = new SqlServerTransport(connectionProvider, "RebusMessages", "bimse");

                    transport.EnsureTableIsCreated();

                    return transport;
                }))
                .Start();

            using (var printTimer = new Timer(1000))
            {
                printTimer.Elapsed += delegate
                {
                    Console.WriteLine("Active connections: {0}", activeConnections.Count);
                };
                printTimer.Start();

                using (bus)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }
        }
        public virtual void TeatCleanup()
        {
            CleanupNHibernateSession();

            TestConnectionProvider.CloseDatabase();

            EquivalenceComparer.ClearGlobalFilter();
            Clock.ResetToSystemClock();
        }
        public virtual void TestInitialize()
        {
            EquivalenceComparer.GlobalFilter =
                EquivalenceComparer.GlobalFilter.Union(NhAssert.PropertiesToIgnoreForDbComparison);
            _comparer = CreateComparer();

            TestConnectionProvider.CloseDatabase(); //just in case

            //ensure Nh by default is using the same session as the one started by our tests
            Nh.CurrentSession = CreateNHibernateSession();
        }
 private void SetStudentLimitedEnglishProficiencyDescriptor(int studentUsi, int?limitedEnglishProficiencyDescriptorId)
 {
     using (var sqlConnection = TestConnectionProvider.CreateNewConnection(null))
     {
         sqlConnection.Execute(@"
             UPDATE edfi.StudentEducationOrganizationAssociation
             SET LimitedEnglishProficiencyDescriptorId = @LimitedEnglishProficiencyDescriptorId
             WHERE StudentUSI = @StudentUsi"
                               , new { StudentUsi = studentUsi, LimitedEnglishProficiencyDescriptorId = limitedEnglishProficiencyDescriptorId });
     }
 }
 private void SetStudentCharacteristicDescriptor(int studentUsi, int studentCharacteristicDescriptorId, int edOrgId)
 {
     using (var sqlConnection = TestConnectionProvider.CreateNewConnection(null))
     {
         sqlConnection.Execute(@"
         INSERT INTO [edfi].[StudentEducationOrganizationAssociationStudentCharacteristic]
         (
             [EducationOrganizationId],
             [StudentUSI],
             [StudentCharacteristicDescriptorId]
         )
          VALUES
         (
             @EducationOrganizationId,
             @StudentUsi,
             @StudentCharacteristicDescriptorId
         )"
                               , new { EducationOrganizationId = edOrgId, StudentUsi = studentUsi, StudentCharacteristicDescriptorId = studentCharacteristicDescriptorId });
     }
 }
 private static void SetStudentRiskStatus(int studentUsi, string riskStatus, int edOrgId)
 {
     using (var sqlConnection = TestConnectionProvider.CreateNewConnection(null))
     {
         sqlConnection.Execute(@"
             INSERT INTO [edfi].[StudentEducationOrganizationAssociationStudentIndicator]
            (
                 [EducationOrganizationId],
                 [StudentUSI],
                 [IndicatorName],
                 [Indicator]
             )
             VALUES
             (
                 @EducationOrganizationId,
                 @StudentUsi,
                 @RiskStatus,
                 @RiskStatus
             )"
                               , new { EducationOrganizationId = edOrgId, StudentUsi = studentUsi, RiskStatus = riskStatus });
     }
 }
示例#9
0
        public async Task CountTheConnections()
        {
            var activeConnections = new ConcurrentDictionary <int, object>();

            var bus = Configure.With(new BuiltinHandlerActivator())
                      .Transport(t => t.Register(c =>
            {
                var connectionProvider = new TestConnectionProvider(MySqlTestHelper.ConnectionString, activeConnections);
                var transport          = new MySqlTransport(connectionProvider, "bimse", c.Get <IRebusLoggerFactory>(), c.Get <IAsyncTaskFactory>(), c.Get <IRebusTime>(), new MySqlTransportOptions(connectionProvider));

                transport.EnsureTableIsCreated();

                return(transport);
            }))
                      .Start();

            using (new Timer(_ => Console.WriteLine("Active connections: {0}", activeConnections.Count), null, 0, 1000))
            {
                using (bus)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            TestConnectionProvider.CloseDatabase();
            var cfg = NHConfigurator.Configuration;
            var conventionBuilder = new ConventionBuilder
            {
                DbSchemaOutputFile       = "schema.sql",
                DropTablesCreateDbSchema = true,
                OutputXmlMappingsFile    = "schema.hbm.xml",
                MappingsAssembly         = typeof(Entity).Assembly,
                ShowLogs       = true,
                FilterAssembly = t => t.IsSubclassOf(typeof(Entity)),
                Conventions    = new List <IAmConvention> {
                    new VersionConvention(),
                    new BidirectionalManyToManyRelationsConvention
                    {
                        BaseEntityType = typeof(Entity),
                    },
                    new BidirectionalOneToManyConvention
                    {
                        BaseEntityType = typeof(Entity),
                    },
                    new DefineBaseClassConvention
                    {
                        BaseEntityToIgnore = typeof(Entity)
                    },
                    new EnumConvention(),
                    new NamingConvention(),
                    new UnidirectionalManyToOne
                    {
                        BaseEntityType = typeof(Entity),
                    },
                    new UnidirectionalOneToManyConvention
                    {
                        BaseEntityType = typeof(Entity),
                    },
                    new ReadOnlyConvention
                    {
                        BaseEntityType = typeof(Entity),
                    }
                }
            };

            conventionBuilder.ProcessConfiguration(cfg);
            var session = SessionFactory.OpenSession();

            CurrentSessionContext.Bind(session);
            using (var tx = session.BeginTransaction())
            {
                //create a person
                Person p = new Person("Bruce", "Wayne");
                p.DateOfBirth   = new DateTime(1972, 6, 2);
                p.HomePhone     = "12345678";
                p.AltPhone      = "987675123";
                p.Address.Line1 = "123 Bruce Manor";
                p.Address.State = "GT";
                p.Address.City  = "Gotham";
                p.Address.Zip   = "99999";
                //save the person
                session.Save(p);
                Assert.IsTrue(p.Id != 0, "Save should give p it’s primary key");
                Person pVerify = (Person)session.Load(typeof(Person), p.Id);
                Assert.AreEqual(p, pVerify, "They weren’t the same");
            }
        }
        private void EnrollInFoodServiceProgram(int studentUsi, int schoolFoodServicesEligibilityDescriptorId, int edOrgId, int programTypeDescriptorId = 1, string programName = "Fake Program", DateTime?beginDate = null, DateTime?endDate = null)
        {
            var nonNullBeginDate = beginDate ?? DateTime.Now;

            EnrollStudentInProgram(studentUsi, edOrgId, programTypeDescriptorId, programName, nonNullBeginDate, endDate);

            using (var sqlConnection = TestConnectionProvider.CreateNewConnection(null))
            {
                sqlConnection.Execute(@"
                    INSERT INTO [edfi].[StudentSchoolFoodServiceProgramAssociation]
                    (
                        [BeginDate],
                        [EducationOrganizationId],
                        [ProgramEducationOrganizationId],
                        [ProgramName],
                        [ProgramTypeDescriptorId],
                        [StudentUSI]
                    )
                    VALUES
                    (
                        @BeginDate,
                        @EducationOrganizationId,
                        @EducationOrganizationId,
                        @ProgramName,
                        @ProgramTypeDescriptorId,
                        @StudentUsi
                    )
                    ",
                                      new
                {
                    BeginDate = nonNullBeginDate,
                    EducationOrganizationId        = edOrgId,
                    ProgramEducationOrganizationId = edOrgId,
                    ProgramName             = programName,
                    ProgramTypeDescriptorId = programTypeDescriptorId,
                    StudentUsi = studentUsi
                });

                sqlConnection.Execute(@"
                    INSERT INTO [edfi].[StudentSchoolFoodServiceProgramAssociationSchoolFoodServiceProgramService]
                    (
                        [BeginDate],
                        [EducationOrganizationId],
                        [ProgramEducationOrganizationId],
                        [ProgramName],
                        [ProgramTypeDescriptorId],
                        [SchoolFoodServiceProgramServiceDescriptorId],
                        [StudentUSI]
                    )
                     VALUES
                    (
                        @BeginDate,
                        @EducationOrganizationId,
                        @EducationOrganizationId,
                        @ProgramName,
                        @ProgramTypeDescriptorId,
                        @SchoolFoodServiceProgramServiceDescriptorId,
                        @StudentUsi
                    )",
                                      new
                {
                    BeginDate = nonNullBeginDate,
                    EducationOrganizationId        = edOrgId,
                    ProgramEducationOrganizationId = edOrgId,
                    ProgramName             = programName,
                    ProgramTypeDescriptorId = programTypeDescriptorId,
                    SchoolFoodServiceProgramServiceDescriptorId = schoolFoodServicesEligibilityDescriptorId,
                    StudentUsi = studentUsi
                });
            }
        }
 protected override void TearDownNHibernateSession()
 {
     TestConnectionProvider.CloseDatabase();
 }
 protected override void SetupNHibernateSession()
 {
     TestConnectionProvider.CloseDatabase();
     NHibernateSessionProvider.Init();
     BuildSchema();
 }