Пример #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);
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
 //[AuthorizeRbac("dataLinks:write")]
 public async Task <IActionResult> CreateDataLink(int accountId, int subscriptionId, [FromBody] DataLinkDto dataLink)
 {
     dataLink.FromSubscriptionId = subscriptionId;
     return(Ok(await _createDataLink.CreateDataLinkAsync(accountId, dataLink)));
 }