Esempio n. 1
0
        public async Task When_DeleteByIdAsync()
        {
            // Arrange

            var cosmosDatabase =
                _cosmosClient.GetDatabase(
                    _configuration["AzureCosmosDocumentStoreOptions:DatabaseId"]);

            var cosmosContainer =
                cosmosDatabase.GetContainer("accounts");

            var accountData =
                new AccountData(
                    _faker.Random.Number(10000, 99999).ToString());

            accountData.SystemOfRecord =
                _faker.PickRandom(
                    AccountData.SYSTEMOFRECORD_AUTOSUITE,
                    AccountData.SYSTEMOFRECORD_FISERVE,
                    AccountData.SYSTEMOFRECORD_ISERIES,
                    AccountData.SYSTEMOFRECORD_LEASEMASTER);
            accountData.PhoneNumber =
                _faker.Person.Phone;

            await cosmosContainer.CreateItemAsync(
                accountData,
                new PartitionKey(accountData.AccountNumber));

            var accountDataStoreOptions =
                new AccountDataStoreOptions(
                    _configuration["AzureCosmosDocumentStoreOptions:DatabaseId"],
                    _cosmosClient);

            var accountDataStore =
                new AccountDataStore(
                    accountDataStoreOptions);

            // Act

            await accountDataStore.DeleteByIdAsync(
                accountData.Id,
                accountData.AccountNumber);

            // Assert

            Func <Task> action = async() =>
                                 await cosmosContainer.ReadItemAsync <AccountData>(
                accountData.Id.ToString(),
                new PartitionKey(accountData.AccountNumber));

            action.Should().Throw <CosmosException>()
            .WithMessage("*Resource Not Found*");;
        }
Esempio n. 2
0
        public async Task When_FetchByIdAsync()
        {
            // Arrange

            var cosmosDatabase =
                _cosmosClient.GetDatabase(
                    _configuration["AzureCosmosDocumentStoreOptions:DatabaseId"]);

            var cosmosContainer =
                cosmosDatabase.GetContainer("accounts");

            var accountData =
                new AccountData(
                    _faker.Random.Number(10000, 99999).ToString());

            accountData.SystemOfRecord =
                _faker.PickRandom(
                    AccountData.SYSTEMOFRECORD_AUTOSUITE,
                    AccountData.SYSTEMOFRECORD_FISERVE,
                    AccountData.SYSTEMOFRECORD_ISERIES,
                    AccountData.SYSTEMOFRECORD_LEASEMASTER);
            accountData.PhoneNumber =
                _faker.Person.Phone;

            await cosmosContainer.CreateItemAsync(
                accountData,
                new PartitionKey(accountData.AccountNumber));

            var accountDataStoreOptions =
                new AccountDataStoreOptions(
                    _configuration["AzureCosmosDocumentStoreOptions:DatabaseId"],
                    _cosmosClient);

            var accountDataStore =
                new AccountDataStore(
                    accountDataStoreOptions);

            // Act

            var accountDataFetched =
                await accountDataStore.FetchByIdAsync(
                    accountData.Id);

            // Assert

            accountDataFetched.Should().NotBeNull();
            accountDataFetched.AccountNumber.Should().Be(accountData.AccountNumber);
            accountDataFetched.Id.Should().Be(accountData.Id);
            accountDataFetched.PhoneNumber.Should().Be(accountData.PhoneNumber);
            accountDataFetched.SystemOfRecord.Should().Be(accountData.SystemOfRecord);
        }
Esempio n. 3
0
        public async Task When_AddAsync()
        {
            // Arrange

            var accountData =
                new AccountData(
                    _faker.Random.Number(10000, 99999).ToString());

            accountData.SystemOfRecord =
                _faker.PickRandom(
                    AccountData.SYSTEMOFRECORD_AUTOSUITE,
                    AccountData.SYSTEMOFRECORD_FISERVE,
                    AccountData.SYSTEMOFRECORD_ISERIES,
                    AccountData.SYSTEMOFRECORD_LEASEMASTER);
            accountData.PhoneNumber =
                _faker.Person.Phone;

            var accountDataStoreOptions =
                new AccountDataStoreOptions(
                    _configuration["AzureCosmosDocumentStoreOptions:DatabaseId"],
                    _cosmosClient);

            var accountDataStore =
                new AccountDataStore(
                    accountDataStoreOptions);

            // Act

            await accountDataStore.AddAsync(
                accountData);

            // Assert

            var cosmosDatabase =
                _cosmosClient.GetDatabase(
                    accountDataStoreOptions.DatabaseId);

            var cosmosContainer =
                cosmosDatabase.GetContainer(
                    "accounts");

            var accountDataResponse =
                await cosmosContainer.ReadItemAsync <AccountData>(
                    accountData.Id.ToString(),
                    new PartitionKey(accountData.AccountNumber));

            accountDataResponse.StatusCode.Should().Be(HttpStatusCode.OK);
        }