Пример #1
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 SubscriptionsController(GetSubscriptionDelegate getSubscription, CreateSubscriptionDelegate createSubscriptionDelegate, UpdateSubscriptionDelegate updateSubscription)
 {
     _getSubscription            = getSubscription;
     _createSubscriptionDelegate = createSubscriptionDelegate;
     _updateSubscription         = updateSubscription;
 }