Exemplo n.º 1
0
        public async Task AddAsyncCompanyShouldReturnCorrectDataFromDbContext(
            string name,
            string description,
            string logoImg,
            string officialSite,
            string userId,
            int categoryId)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Company>(dbContext);
            var service    = new CompaniesService(repository);
            int companyId  = await service.AddAsync(name, description, logoImg, officialSite, userId, categoryId);

            var result = service.GetById(companyId);

            Assert.Equal(1, result.Id);
            Assert.Equal(name, result.Name);
            Assert.Equal(description, result.Description);
            Assert.Equal(logoImg, result.LogoImage);
            Assert.Equal(officialSite, result.OfficialSite);
            Assert.Equal(userId, result.UserId);
            Assert.Equal(categoryId, result.CategoryId);
        }
Exemplo n.º 2
0
        public void GetByIdReturnsCompany()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfRepository <Company>(new ApplicationDbContext(options.Options));

            repository.AddAsync(new Company {
                Name = "Авангард ЕООД", Bulstat = "041835487509", VatNumber = $"BG{041835487509}", PhoneNumber = "+359 889 121 212", Address = "гр.Пловдив, ул.Марашев 5"
            });
            repository.AddAsync(new Company {
                Name = "ЕТ Саламандър", Bulstat = "63835487509", VatNumber = $"BG{041835487509}", PhoneNumber = "+359 889 211 212", Address = "гр.Пловдив, ул.Марашев 6"
            });
            repository.AddAsync(new Company {
                Name = "Тиесто Гранд", Bulstat = "041115487509", VatNumber = $"BG{041835487509}", PhoneNumber = "+359 889 121 211", Address = "гр.Пловдив, ул.Марашев 7"
            });
            repository.SaveChangesAsync();

            var routesService = new CompaniesService(repository);

            var routeFromDb = repository.AllAsNoTracking().FirstOrDefault(c => c.Name == "Тиесто Гранд");

            var route = routesService.GetById(routeFromDb.Id);

            Assert.Equal(routeFromDb.Id, route.Id);
            Assert.Equal(routeFromDb.Name, route.Name);
            Assert.Equal(routeFromDb.Bulstat, route.Bulstat);
            Assert.Equal(routeFromDb.Address, route.Address);
        }
Exemplo n.º 3
0
        public void TestGetCompanyById()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            AutoMapperConfig.RegisterMappings(typeof(MyTestCompany).Assembly);
            var repository = new EfDeletableEntityRepository <Company>(new ApplicationDbContext(options.Options));

            repository.AddAsync(new Company {
                Name = "test"
            }).GetAwaiter().GetResult();

            repository.SaveChangesAsync();
            var companyService = new CompaniesService(repository);
            var company        = companyService.GetById <MyTestCompany>(1);

            Assert.Equal("test", company.Name);
        }