コード例 #1
0
        private async Task <long?> GetCurrentIPAddressIdAsync(IExecutionContext executionContext)
        {
            var command = new AddCurrentIPAddressIfNotExistsCommand();
            await _domainRepository
            .WithContext(executionContext)
            .ExecuteCommandAsync(command);

            return(command.OutputIPAddressId);
        }
コード例 #2
0
        public async Task WhenExists_ReturnsId()
        {
            const string address = "4.8.15.16";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            app.Mocks.MockIPAddress(address);
            var command1 = new AddCurrentIPAddressIfNotExistsCommand();
            await contentRepository.ExecuteCommandAsync(command1);

            var command2 = new AddCurrentIPAddressIfNotExistsCommand();
            await contentRepository.ExecuteCommandAsync(command2);

            command1.OutputIPAddressId.Should().BePositive().And.Be(command2.OutputIPAddressId);
        }
コード例 #3
0
        public async Task WhenNotExists_Adds(string address)
        {
            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            app.Mocks.MockIPAddress(address);
            var command = new AddCurrentIPAddressIfNotExistsCommand();
            await contentRepository.ExecuteCommandAsync(command);

            var dbIPAddress = await dbContext
                              .IPAddresses
                              .AsNoTracking()
                              .Where(i => i.IPAddressId == command.OutputIPAddressId)
                              .SingleOrDefaultAsync();

            using (new AssertionScope())
            {
                dbIPAddress.Should().NotBeNull();
                dbIPAddress.Address.Should().Be(address);
                dbIPAddress.CreateDate.Should().NotBeDefault();
            }
        }