public static void InitialiseDatabase(ManagementAPIReadModel managementApiReadModel,
                                              SeedingType seedingType)
        {
            try
            {
                if (managementApiReadModel.Database.IsSqlServer())
                {
                    managementApiReadModel.Database.Migrate();
                }

                managementApiReadModel.SaveChanges();
            }
            catch (Exception ex)
            {
                String connString = managementApiReadModel.Database.GetDbConnection().ConnectionString;

                Exception newException = new Exception($"Connection String [{connString}]", ex);
                throw newException;
            }
        }
Esempio n. 2
0
        public async Task ReportingManager_GetNumberOfMembersByTimePeriodReport_ByYear_ReportDataReturned()
        {
            String databaseName = Guid.NewGuid().ToString("N");
            ManagementAPIReadModel             context       = this.GetContext(databaseName);
            List <GolfClubMembershipReporting> reportingData = new List <GolfClubMembershipReporting>();

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2019, 08, 16),
                DateOfBirth      = DateTime.Now.AddYears(-20),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 1,
                PlayerGender     = "M",
                PlayerName       = "Test Player 1"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2019, 08, 16),
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 2,
                PlayerGender     = "M",
                PlayerName       = "Test Player 2"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2018, 08, 16),
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 2,
                PlayerGender     = "M",
                PlayerName       = "Test Player 3"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2018, 07, 15),
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 4"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2018, 07, 14),
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 5"
            });

            reportingData.Add(new GolfClubMembershipReporting
            {
                DateJoined       = new DateTime(2017, 06, 13),
                DateOfBirth      = DateTime.Now.AddYears(-25),
                PlayerId         = Guid.NewGuid(),
                GolfClubId       = GolfClubTestData.AggregateId,
                GolfClubName     = GolfClubTestData.Name,
                HandicapCategory = 3,
                PlayerGender     = "M",
                PlayerName       = "Test Player 6"
            });
            context.GolfClubMembershipReporting.AddRange(reportingData);
            context.SaveChanges();

            Func <ManagementAPIReadModel> contextResolver = () => { return(context); };

            ReportingManager reportingManager = new ReportingManager(contextResolver);

            GetNumberOfMembersByTimePeriodReportResponse reportData = await reportingManager.GetNumberOfMembersByTimePeriodReport(GolfClubTestData.AggregateId, TimePeriod.Year.ToString(), CancellationToken.None);

            reportData.GolfClubId.ShouldBe(GolfClubTestData.AggregateId);
            reportData.TimePeriod.ShouldBe(TimePeriod.Year);
            reportData.MembersByTimePeriodResponse.ShouldNotBeNull();
            reportData.MembersByTimePeriodResponse.ShouldNotBeEmpty();
            reportData.MembersByTimePeriodResponse.Count.ShouldBe(3);
            reportData.MembersByTimePeriodResponse[0].Period.ShouldBe("2017");
            reportData.MembersByTimePeriodResponse[0].NumberOfMembers.ShouldBe(1);
            reportData.MembersByTimePeriodResponse[1].Period.ShouldBe("2018");
            reportData.MembersByTimePeriodResponse[1].NumberOfMembers.ShouldBe(4);
            reportData.MembersByTimePeriodResponse[2].Period.ShouldBe("2019");
            reportData.MembersByTimePeriodResponse[2].NumberOfMembers.ShouldBe(6);
        }