Пример #1
0
        public async Task EditAsync_SouldReturn_False_IfCompanyDonotExists()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstCompany = new Company {
                Id = 1, Name = "Свеплина", Bulstat = "903097356", AccountablePerson = "H", Address = "k"
            };
            var secondCompany = new Company {
                Id = 2, Name = "Просперитет", Bulstat = "BG909087356", AccountablePerson = "Y", Address = "ko"
            };
            var thirdCompany = new Company {
                Id = 3, Name = "Тотал Щета", Bulstat = "903099066", AccountablePerson = "opk", Address = "top"
            };
            await db.Companies.AddRangeAsync(firstCompany, secondCompany, thirdCompany);

            await db.SaveChangesAsync();

            var companyService = new CompaniesService(db, mapper);

            var result = await companyService.EditAsync(4, "Ръст", "090987134", "Мария", "Бусманци 67");

            var editedCompany = await db.Companies.FindAsync(4);

            result
            .Should()
            .BeFalse();

            editedCompany
            .Should()
            .BeNull();
        }
Пример #2
0
        public async Task EditAsyncUpdatesExistingRoute()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfRepository <Company>(new ApplicationDbContext(options.Options));
            var company    = new Company {
                Name = "Авангард ЕООД"
            };
            await repository.AddAsync(company);

            await repository.SaveChangesAsync();

            var companiesService = new CompaniesService(repository);

            company.Bulstat     = "2638236483";
            company.VatNumber   = $"BG{company.Bulstat}";
            company.PhoneNumber = "+ 359 999 000 000";

            await companiesService.EditAsync(company);

            var updatedCompany = repository.AllAsNoTracking().FirstOrDefault(c => c.Name == "Авангард ЕООД");

            Assert.Equal(company.Bulstat, updatedCompany.Bulstat);
            Assert.Equal(company.VatNumber, updatedCompany.VatNumber);
            Assert.Equal(company.PhoneNumber, updatedCompany.PhoneNumber);
        }
Пример #3
0
        public async Task EditAsync_SouldReturn_True_IfEditDataPassedCorrectly()
        {
            var db     = this.GetDatabase();
            var mapper = this.GetMapper();

            var firstCompany = new Company {
                Id = 1, Name = "Свеплина", Bulstat = "903097356", AccountablePerson = "H", Address = "k"
            };
            var secondCompany = new Company {
                Id = 2, Name = "Просперитет", Bulstat = "BG909087356", AccountablePerson = "Y", Address = "ko"
            };
            var thirdCompany = new Company {
                Id = 3, Name = "Тотал Щета", Bulstat = "903099066", AccountablePerson = "opk", Address = "top"
            };
            await db.Companies.AddRangeAsync(firstCompany, secondCompany, thirdCompany);

            await db.SaveChangesAsync();

            var companyService = new CompaniesService(db, mapper);

            var result = await companyService.EditAsync(2, "Ръст", "090987134", "Мария", "Бусманци 67");

            var editedCompany = await db.Companies.FindAsync(2);

            result
            .Should()
            .BeTrue();

            editedCompany
            .Should()
            .BeOfType <Company>()
            .And
            .Match <Company>(c => c.Name == "Ръст" &&
                             c.Bulstat == "090987134" &&
                             c.AccountablePerson == "Мария" &&
                             c.Address == "Бусманци 67");
        }
Пример #4
0
        public async Task WhenEditCompanyWhereBulstatIsDifferentButEqualWithAnotherOne()
        {
            var companies       = new List <Company>();
            var mockCompanyRepo = new Mock <IDeletableEntityRepository <Company> >();

            mockCompanyRepo.Setup(x => x.All()).Returns(companies.AsQueryable());
            mockCompanyRepo.Setup(x => x.AddAsync(It.IsAny <Company>())).Callback(
                (Company company) => companies.Add(company));

            var mockHotelRepo = new Mock <IDeletableEntityRepository <Hotel> >();

            var service = new CompaniesService(mockCompanyRepo.Object, mockHotelRepo.Object);

            var firstCompany = new Company
            {
                Id      = 1,
                Address = "Първи май №2",
                Bulstat = "131071587",
                CityId  = 1,
                Email   = "*****@*****.**",
            };

            var secondCompany = new Company
            {
                Id      = 1,
                Address = "Първи май №2",
                Bulstat = "131071589",
                CityId  = 1,
                Email   = "*****@*****.**",
            };

            companies.Add(firstCompany);
            companies.Add(secondCompany);
            await service.EditAsync(1, 1, "NeykovEOOD", "131071589", "0888989844", "*****@*****.**", 1, "Първи май №2");

            Assert.Equal(2, companies.Count);
        }
Пример #5
0
        public async Task WhenEditCompanyWhereBulstatIsEqual()
        {
            var companies       = new List <Company>();
            var mockCompanyRepo = new Mock <IDeletableEntityRepository <Company> >();

            mockCompanyRepo.Setup(x => x.All()).Returns(companies.AsQueryable());
            mockCompanyRepo.Setup(x => x.AddAsync(It.IsAny <Company>())).Callback(
                (Company company) => companies.Add(company));

            var mockHotelRepo = new Mock <IDeletableEntityRepository <Hotel> >();

            var service = new CompaniesService(mockCompanyRepo.Object, mockHotelRepo.Object);

            var company = new Company
            {
                Id      = 1,
                Bulstat = "131071587",
            };

            companies.Add(company);
            await service.EditAsync(1, 1, "NeykovEOOD", "131071587", "0888989844", "*****@*****.**", 1, "Първи май №2");

            Assert.Single(companies);
        }