Beispiel #1
0
        static async Task AsyncMain()
        {
            var dispatcher = await SetupDispatcher();

            var patientId = Guid.NewGuid().ToString();

            var admitPatient = new AdmitPatient(patientId, "Tony Ferguson", 32, DateTime.UtcNow, 10);
            await dispatcher.Dispatch(admitPatient);

            var transferPatientOne = new TransferPatient(patientId, 76);
            await dispatcher.Dispatch(transferPatientOne);

            var transferPatientTwo = new TransferPatient(patientId, 34);
            await dispatcher.Dispatch(transferPatientTwo);

            var dischargePatient = new DischargePatient(patientId);
            await dispatcher.Dispatch(dischargePatient);


            Console.ReadLine();
        }
Beispiel #2
0
    public async Task EndToEndTest()
    {
        var ct                = new CancellationTokenSource().Token;
        var eventStore        = GetEventStore();
        var dispatcher        = SetupDispatcher(eventStore);
        var connectionFactory = new ConnectionFactory("PatientManagement");
        await connectionFactory.EnsureDatabaseExistsAsync(ct);

        var projections = new List <IProjection>
        {
            new WardViewProjection(connectionFactory),
            new PatientDemographicProjection(connectionFactory)
        };

        var projectionManager = new ProjectionManager.ProjectionManager(
            eventStore,
            connectionFactory,
            projections);

        await projectionManager.StartAsync(ct);

        var patientId = Guid.NewGuid();

        var admitPatient = new AdmitPatient(patientId, "Tony Ferguson", 32, DateTime.UtcNow, 10);
        await dispatcher.Dispatch(admitPatient, ct);

        await retryPolicy.ExecuteAsync(async token =>
        {
            using var session = connectionFactory.Connect();
            var patient       = await session.LoadAsync <Patient>(patientId.ToString(), token);

            Assert.NotNull(patient);
            Assert.Equal(patientId.ToString(), patient.Id);
            Assert.Equal(admitPatient.PatientName, patient.PatientName);
            Assert.Equal(admitPatient.AgeInYears, patient.AgeInYears);
            Assert.Equal(admitPatient.WardNumber, patient.WardNumber);
        }, ct);

        var transferPatientOne = new TransferPatient(patientId, 76);
        await dispatcher.Dispatch(transferPatientOne, ct);

        await retryPolicy.ExecuteAsync(async token =>
        {
            using var session = connectionFactory.Connect();
            var patient       = await session.LoadAsync <Patient>(patientId.ToString(), token);

            Assert.NotNull(patient);
            Assert.Equal(transferPatientOne.WardNumber, patient.WardNumber);
        }, ct);

        var transferPatientTwo = new TransferPatient(patientId, 34);
        await dispatcher.Dispatch(transferPatientTwo, ct);

        await retryPolicy.ExecuteAsync(async token =>
        {
            using var session = connectionFactory.Connect();
            var patient       = await session.LoadAsync <Patient>(patientId.ToString(), token);

            Assert.NotNull(patient);
            Assert.Equal(transferPatientTwo.WardNumber, patient.WardNumber);
        }, ct);

        var dischargePatient = new DischargePatient(patientId);
        await dispatcher.Dispatch(dischargePatient, ct);

        await retryPolicy.ExecuteAsync(async token =>
        {
            using var session = connectionFactory.Connect();
            var patient       = await session.LoadAsync <Patient>(patientId.ToString(), token);

            Assert.Null(patient);
        }, ct);
    }