Exemple #1
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);
Exemple #2
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);
        }
        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)}");
Exemple #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);
            }
        }
Exemple #5
0
        public DxfrTest()
        {
            _settings = new AdapterSettings();

            _baseDirectory = Directory.GetCurrentDirectory();
            _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin"));
            _settings["BaseDirectoryPath"] = _baseDirectory;
            Directory.SetCurrentDirectory(_baseDirectory);

            _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config"));

            _settings["ProjectName"]           = "12345_000";
            _settings["ApplicationName"]       = "ABC";
            _settings["GraphName"]             = "Lines";
            _settings["Identifier"]            = "90002-RV";
            _settings["ExecutingAssemblyName"] = "NUnit.Tests";
            _settings["GraphBaseUri"]          = "http://www.example.com/";
            _dxfrProvider = new DtoProvider(_settings);

            ResetDatabase();
        }
Exemple #6
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);
            }
        }
Exemple #7
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)}");
Exemple #8
0
 public DataTransferService()
 {
     _dtoProvider = new DtoProvider(ConfigurationManager.AppSettings);
 }