Example #1
0
        public async Task Test_Passing_Null_Who_Throws_Exception()
        {
            // ARRANGE
            IOrganisation organisation = Create.Organisation();

            Mock <ILogger <IOrganisationService> > loggerMock =
                MockFactory.CreateLoggerMock <IOrganisationService>();

            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <CreateAsyncTests>(
                    nameof(this.Test_Passing_Valid_Values));

            await using DataContext dataContext = new DataContext(dbOptions);

            IVirtualBridgeData data =
                MockFactory.CreateVirtualBridgeData(
                    dataContext);

            IOrganisationService service = new OrganisationService(
                loggerMock.Object,
                data);

            // ACT
            await service.CreateAsync(
                who : null !,
                auditEvent : EAuditEvent.OrganisationMaintenance,
                organisation : organisation)
            .ConfigureAwait(false);
        }
Example #2
0
        public async Task Test_Passing_Valid_Values()
        {
            // ARRANGE
            IWho          who          = Create.Who();
            IOrganisation organisation = Create.Organisation();

            Mock <ILogger <IOrganisationService> > loggerMock =
                MockFactory.CreateLoggerMock <IOrganisationService>();

            Mock <IOrganisationRepository> organisationRepositoryMock =
                MockFactory.CreateRepositoryMock <IOrganisationRepository>();

            organisationRepositoryMock.Setup(x =>
                                             x.CreateAsync(
                                                 who,
                                                 It.IsAny <AuditHeaderWithAuditDetails>(),
                                                 organisation))
            .Returns(Task.CompletedTask);

            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <CreateAsyncTests>(
                    nameof(this.Test_Passing_Valid_Values));

            await using DataContext dataContext = new DataContext(dbOptions);

            IVirtualBridgeData data =
                MockFactory.CreateVirtualBridgeData(
                    dataContext,
                    organisationRepository: organisationRepositoryMock.Object);

            IOrganisationService service = new OrganisationService(
                loggerMock.Object,
                data);

            // ACT
            await service.CreateAsync(
                who : who,
                auditEvent : EAuditEvent.OrganisationMaintenance,
                organisation : organisation)
            .ConfigureAwait(false);

            // ASSERT
            organisationRepositoryMock.Verify(
                x => x.CreateAsync(
                    who,
                    It.IsAny <IAuditHeaderWithAuditDetails>(),
                    organisation),
                Times.Once);
        }
Example #3
0
        public async Task Test_Exception_Triggers_Rollback()
        {
            // ARRANGE
            IWho          who          = Create.Who();
            IOrganisation organisation = Create.Organisation();

            Mock <ILogger <IOrganisationService> > loggerMock =
                MockFactory.CreateLoggerMock <IOrganisationService>();

            DbContextOptions <DataContext> dbOptions =
                TestUtils.DbContextOptionsInMemory <CreateAsyncTests>(
                    nameof(this.Test_Passing_Valid_Values));

            await using DataContext dataContext = new DataContext(dbOptions);

            Mock <IOrganisationRepository> organisationRepositoryMock =
                MockFactory.CreateRepositoryMock <IOrganisationRepository>();

            organisationRepositoryMock.Setup(x =>
                                             x.CreateAsync(
                                                 It.IsAny <IWho>(),
                                                 It.IsAny <AuditHeaderWithAuditDetails>(),
                                                 It.IsAny <IOrganisation>()))
            .Throws <DeliberateException>();

            IVirtualBridgeData data =
                MockFactory.CreateVirtualBridgeData(
                    dataContext,
                    organisationRepository: organisationRepositoryMock.Object);

            IOrganisationService service = new OrganisationService(
                loggerMock.Object,
                data);

            // ACT
            await service.CreateAsync(
                who : who,
                auditEvent : EAuditEvent.OrganisationMaintenance,
                organisation : organisation)
            .ConfigureAwait(false);
        }