コード例 #1
0
        public async Task GetVisibleCompaniesAsyncShouldReturnVisibleCompanies()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            dbContext.CreditCompanies.AddRange(new List <CreditCompany>
            {
                new CreditCompany {
                    Name = "TBI", Hide = true
                },
                new CreditCompany {
                    Name = "UniCredit"
                },
                new CreditCompany {
                    Name = "ProCredit"
                },
            });
            await dbContext.SaveChangesAsync();

            var companies = await creditCompaniesService.GetVisibleCompaniesAsync();

            Assert.Equal(2, companies.Count());
        }
コード例 #2
0
        public async Task ShowCompanyAsyncShouldChangeHiteToTrue()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            var companyName = "TBI";

            dbContext.CreditCompanies.AddRange(new List <CreditCompany>
            {
                new CreditCompany {
                    Name = companyName, Hide = true
                },
                new CreditCompany {
                    Name = "UniCredit"
                },
                new CreditCompany {
                    Name = "ProCredit"
                },
            });
            await dbContext.SaveChangesAsync();

            var company = dbContext.CreditCompanies.FirstOrDefault(x => x.Name == companyName);

            await creditCompaniesService.ShowCompanyAsync(company);

            Assert.False(company.Hide);
        }
コード例 #3
0
        public async Task EditCompanyAsyncShouldEditCompany()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            var company = new CreditCompany()
            {
                Name     = "TBI",
                Interest = 12,
                Address  = "Sofia, Mladost 4",
            };

            dbContext.CreditCompanies.Add(company);
            await dbContext.SaveChangesAsync();

            company.Name     = "TBICredit";
            company.Interest = 10.5m;
            company.Address  = "Sofia, Mladost 1A";

            await creditCompaniesService.EditCompanyAsync(company);

            var editedCompany = await dbContext.CreditCompanies.FirstOrDefaultAsync(x => x.Name == company.Name);

            Assert.Equal(company.Name, editedCompany.Name);
            Assert.Equal(company.Interest, editedCompany.Interest);
            Assert.Equal(company.Address, editedCompany.Address);
        }
コード例 #4
0
        public async Task GetCompanyByIdAsyncShouldReturnCompany()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            var companyName = "TBI";

            dbContext.CreditCompanies.AddRange(new List <CreditCompany>
            {
                new CreditCompany {
                    Name = companyName
                },
                new CreditCompany {
                    Name = "UniCredit"
                },
                new CreditCompany {
                    Name = "ProCredit"
                },
            });
            await dbContext.SaveChangesAsync();

            var companyId = dbContext.CreditCompanies.FirstOrDefault(x => x.Name == companyName).Id;

            var company = await creditCompaniesService.GetCompanyByIdAsync(companyId);

            Assert.Equal(companyName, company.Name);
        }
コード例 #5
0
        public async Task AddCompanyAsyncNullEntityShouldNotAddCompany()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            CreditCompany company = null;
            await creditCompaniesService.AddCompanyAsync(company);

            var companies = dbContext.CreditCompanies.ToList();

            Assert.Empty(companies);
        }
コード例 #6
0
        public async Task AddCompanyAsyncShouldAddCompany()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var creditCompaniesService = new CreditCompaniesService(dbContext);

            var company = new CreditCompany {
                Name = "TBI"
            };
            await creditCompaniesService.AddCompanyAsync(company);

            var products = dbContext.CreditCompanies.ToList();

            Assert.Single(products);
            Assert.Equal(company.Name, products.First().Name);
        }