Пример #1
0
        public async Task GivenTwoCompaniesShouldFindCompanyByName()
        {
            var settingsBuilder = new CompanySettingsBuilder();
            var config          = settingsBuilder.GetSettings();
            var options         = new DbContextOptionsBuilder <CompanyContext>()
                                  .UseInMemoryDatabase(databaseName: "ShouldFindCompanyByAddress")
                                  .Options;

            using (var context = new CompanyContext(options))
            {
                await context.Database.EnsureCreatedAsync();

                var repository = new CompanyRepository(context);
                var company1   = mock.MockCompany("ABC");
                var company2   = mock.MockCompany("XYZ");
                await repository.Add(company1);

                await repository.Add(company2);

                var matchingCompanies = await repository.SearchForCompaniesByName("AB", config.SearchForCompanyByNameRecordCount);

                Assert.NotNull(matchingCompanies);
                Assert.Single(matchingCompanies);
                var company = matchingCompanies.First();
                Assert.Equal("ABC", company.Name);
            }
        }
        public async Task CreateCompanyDatabase()
        {
            var             builder = new CompanySettingsBuilder();
            CompanySettings config  = builder.GetSettings();
            var             options = new DbContextOptionsBuilder <CompanyContext>()
                                      .UseSqlServer(config.ConnectionString)
                                      .Options;

            using (var context = new CompanyContext(options))
            {
                // await context.Database.EnsureDeletedAsync();
            }
        }