Exemplo n.º 1
0
        public async Task GivenAnAccountDefinition_WhenICreateADataLinkBetweenTwoSubscriptions_ThenTheDataLinkShouldBePersisted()
        {
            // Setup:
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();

            var account = DtoProvider.CreateValidAccountDefinition();
            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            account = await createAccountDelegate.CreateAccountAsync(account);

            var dataLink = new DataLinkDto
            {
                FromSubscriptionId = 2, // Staging
                ToSubscriptionId   = 1, // Production
                DataLinkTypeId     = 1  // Customization
            };

            // System under test: CreateDataLinkDelegate
            var createDataLinkDelegate = new CreateDataLinkDelegate(db, Mapper);

            // Exercise: invoke CreateDataLink
            var createdDataLink = await createDataLinkDelegate.CreateDataLinkAsync(account.AccountId, dataLink);


            // Assert
            createdDataLink.From.Should().NotBeNullOrEmpty();
            createdDataLink.To.Should().NotBeNullOrEmpty();
            createdDataLink.Type.Should().NotBeNullOrEmpty().And.Be("Customization");

            db.DataLinks.Count().Should().Be(1);
        }
Exemplo n.º 2
0
        public async Task GivenAValidIdPDefinition_WhenICallTheCreateDelegate_ThenTheProviderShouldBePersisted()
        {
            // Setup: Create a database with an Account and two existing Subscriptions.
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();
            var account = DtoProvider.CreateValidAccountDefinition();

            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            account = await createAccountDelegate.CreateAccountAsync(account);

            var identityProvider = new IdentityProviderDto {
                Name = "Health Dialog Secondary IdP"
            };

            // System under test: CreateIdentityProviderDelegate
            var createIdentityProvider = new CreateIdentityProviderDelegate(db, Mapper);

            // Exercise: invoke Create Identity Provider
            identityProvider = await createIdentityProvider.CreateIdentityProvider(account.AccountId, identityProvider);

            // Assert: the number of Accounts in the InMemory database is still 1
            // Assert: the number of Subscriptions in the InMemory database is still 2
            // Assert: the number of Subscriptions in the InMemory database is now 2
            db.Accounts.Count().Should().Be(1, $"The number of {nameof(db.Accounts)} in the ClientsDb is not 1");
            db.Subscriptions.Count().Should().Be(2, $"The number of {nameof(db.Subscriptions)} in the ClientsDb is not 2");
            db.IdentityProviders.Count().Should().Be(2, $"The number of {nameof(db.IdentityProviders)} in the ClientsDb is not 2");

            identityProvider.IdentityProviderId.Should().NotBe(default);
        public async Task GivenAnAccountDefinition_WhenIHaveAValidAccount_ThenTheAccountShouldBePersisted()
        {
            // Setup: 1 Account with 2 Subscriptions
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();
            var account = DtoProvider.CreateValidAccountDefinition();

            // System under test: CreateAccountDelegate
            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            // Exercise: invoke CreateAccount
            account = await createAccountDelegate.CreateAccountAsync(account);

            // Assert: the number of Accounts in the InMemory database is now 1
            // Assert: the number of Subscriptions in the InMemory database is now 2
            db.Accounts.Count().Should().Be(1, $"The number of {nameof(db.Accounts)} in the ClientsDb is not 1");
            db.Subscriptions.Count().Should().Be(2, $"The number of {nameof(db.Subscriptions)} in the ClientsDb is not 2");
            db.IdentityProviders.Count().Should().Be(1, $"The number of {nameof(db.IdentityProviders)} in the ClientsDb is not 1");

            account.AccountId.Should().NotBe(default, $"The underlying provider should generate a value for {nameof(AccountDto.AccountId)}");
Exemplo n.º 4
0
        public async Task GivenADataLinkOperation_WhenICreateAnExistingDataLink_ThenTheDelegateShouldRaiseAnError()
        {
            // Setup:
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();

            var account = DtoProvider.CreateValidAccountDefinition();
            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            account = await createAccountDelegate.CreateAccountAsync(account);

            var dataLink = new DataLinkDto
            {
                FromSubscriptionId = 2, // Staging
                ToSubscriptionId   = 1, // Production
                DataLinkTypeId     = 1  // Customization
            };

            // System under test: CreateDataLinkDelegate
            var createDataLinkDelegate = new CreateDataLinkDelegate(db, Mapper);

            // Exercise: invoke CreateDataLink twice
            try
            {
                await createDataLinkDelegate.CreateDataLinkAsync(account.AccountId, dataLink);

                await createDataLinkDelegate.CreateDataLinkAsync(account.AccountId, dataLink);

                Assert.Fail($"An invocation to {nameof(CreateDataLinkDelegate.CreateDataLinkAsync)} should not have completed when a duplicate data link.");
            }
            catch (Exception e)
            {
                // Assert

                // Exception is the right type
                e.GetType().Should().Be <MalformedDataLinkException>();
                e.Message.Should().Be($"An existing DataLink from subscription with SubscriptionId = 2 to subscription with SubscriptionId = 1 already exists.");

                // Only one data link is persisted.
                db.DataLinks.Count().Should().Be(1);
            }
        }
Exemplo n.º 5
0
        public async Task GivenADataLinkOperation_WhenIPassAnInvalidAccount_ThenTheDelegateShouldRaiseAnError()
        {
            // Setup:
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();

            var account = DtoProvider.CreateValidAccountDefinition();
            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            account = await createAccountDelegate.CreateAccountAsync(account);

            var dataLink = new DataLinkDto
            {
                FromSubscriptionId = 2, // Staging
                ToSubscriptionId   = 1, // Production
                DataLinkTypeId     = 1  // Customization
            };

            // System under test: CreateDataLinkDelegate
            var createDataLinkDelegate = new CreateDataLinkDelegate(db, Mapper);

            // Exercise: invoke CreateDataLink twice
            try
            {
                await createDataLinkDelegate.CreateDataLinkAsync(-1, dataLink);

                Assert.Fail($"An invocation to {nameof(CreateDataLinkDelegate.CreateDataLinkAsync)} should not have completed with an invalid {nameof(AccountDto.AccountId)}.");
            }
            catch (Exception e)
            {
                // Assert

                // Exception is the right type
                e.GetType().Should().Be <AccountNotFoundException>();
                e.Message.Should().Be($"An account with AccountId = -1 doesn't exist.");

                // Nothing persisted
                db.DataLinks.Count().Should().Be(0);
            }
        }
Exemplo n.º 6
0
        public async Task GivenAnAccountDefinition_WhenTheSubscriptionIsValid_ThenTheSubscriptionShouldBePersisted()
        {
            // Setup: Create a database with an Account and two existing Subscriptions.
            await using var db = ClientsDbTestProvider.CreateInMemoryClientDb();
            var account = DtoProvider.CreateValidAccountDefinition();

            var createAccountDelegate = new CreateAccountDelegate(db, Mapper);

            account = await createAccountDelegate.CreateAccountAsync(account);

            var subscription = DtoProvider.CreateValidSubscriptionDefinition();

            // System under test: CreateSubscriptionDelegate
            var createSubscription = new CreateSubscriptionDelegate(db, Mapper);

            // Exercise: invoke CreateSubscription
            subscription = await createSubscription.CreateSubscriptionAsync(account.AccountId, subscription);

            // Assert: the number of Accounts in the InMemory database is still 1
            // Assert: the number of Subscriptions in the InMemory database is now 3
            db.Accounts.Count().Should().Be(1, $"The number of {nameof(db.Accounts)} in the ClientsDb is not 1");
            db.Subscriptions.Count().Should().Be(3, $"The number of {nameof(db.Subscriptions)} in the ClientsDb is not 3");

            subscription.SubscriptionId.Should().NotBe(default, $"The underlying provider should generate a value for {nameof(SubscriptionDto.SubscriptionId)}");
 public AccountsController(CreateAccountDelegate createAccount, GetAccountDelegate getAccount, UpdateAccountDelegate updateAccount)
 {
     _createAccount = createAccount;
     _getAccount    = getAccount;
     _updateAccount = updateAccount;
 }