Esempio n. 1
0
        public async Task AddEmployeeAsyncTest_WithCoreectData_ShouldReturnTrue()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var service = new EmployeesService(repository, this.GetMockUserManager().Object);

            await repository.AddAsync(new SteuUser()
            {
                Id       = "asdasd",
                UserName = "******",
                Company  = new Company()
                {
                    Name = "Pesho Ltd",
                },
            });

            await repository.SaveChangesAsync();

            AddEmployeeInputModel model = new AddEmployeeInputModel()
            {
                FirstName       = "Gosho",
                LastName        = "Goshov",
                Username        = "******",
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******",
            };

            var actualResult = await service.AddEmployeeAsync("asdasd", model);

            Assert.True(actualResult);
        }
Esempio n. 2
0
        public async Task AddEmployeeAsyncTest_WithIncorrectUserId_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var service = new EmployeesService(repository, this.GetMockUserManager().Object);

            await repository.AddAsync(new SteuUser()
            {
                Id       = "asdasd",
                UserName = "******",
                Company  = new Company()
                {
                    Name = "Pesho Ltd",
                },
            });

            await repository.SaveChangesAsync();

            AddEmployeeInputModel model = new AddEmployeeInputModel()
            {
                FirstName       = "Gosho",
                LastName        = "Goshov",
                Username        = "******",
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******",
            };

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.AddEmployeeAsync("asd", model));
        }
Esempio n. 3
0
        public async Task GetCountOfLoadsAsync_WithOutData_ShouldReturnZero()
        {
            var          context = SteuDbContextInMemoryFactory.InitializeContext();
            LoadsService service = IntializeLoadService(context);

            var actualResult = await service.GetCountOfLoadsAsync();

            Assert.Equal(0, actualResult);
        }
Esempio n. 4
0
        public async Task GetAllAvaibleLoadsAsync_WithoutData_ShouldReturnEmptyList()
        {
            var          context = SteuDbContextInMemoryFactory.InitializeContext();
            LoadsService service = IntializeLoadService(context);

            var actualResult = await service.GetAllAvaibleLoadsAsync(1, 10);

            Assert.Empty(actualResult);
        }
Esempio n. 5
0
        public async Task AddNewsAsync_WithNullUserId_ShouldRetyrnArgumentNullException()
        {
            var         context    = SteuDbContextInMemoryFactory.InitializeContext();
            NewsService service    = this.IntializeNewsService(context);
            var         repository = new EfDeletableEntityRepository <News>(context);

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.AddNewsAsync("title", "content", null, null));
        }
Esempio n. 6
0
        public async Task GetOrderDetailsForNewMessageAsync_WithInvalidOrderId_ShouldRetyrnArgumentNullException()
        {
            var             context    = SteuDbContextInMemoryFactory.InitializeContext();
            MessagesService service    = this.IntializeMessagesService(context);
            var             repository = new EfDeletableEntityRepository <Message>(context);

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.GetOrderDetailsForNewMessageAsync <SendMessageInputModel>("or"));
        }
Esempio n. 7
0
        public async Task AddActionToLog_WithNullAction_ShouldReturnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeLogsService(context);
            var repository = new EfDeletableEntityRepository <Log>(context);

            Assert.Throws <ArgumentNullException>(()
                                                  => service.AddActionToLog("Pesho", null));
        }
Esempio n. 8
0
        public async Task GetAllLogsAsync_WithEmptyArray_ReturtListOfLogs()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeLogsService(context);
            var repository = new EfDeletableEntityRepository <Log>(context);

            var actualResult = await service.GetAllLogsAsync(1, 10);

            Assert.Empty(actualResult);
        }
Esempio n. 9
0
        public async Task GetOrCreateTownByName_WithData_ShouldReturnTown()
        {
            var          context    = SteuDbContextInMemoryFactory.InitializeContext();
            TownsService service    = this.IntializeTownsService(context);
            var          repository = new EfRepository <Town>(context);

            var actualResult = service.GetOrCreateTownByName("Sofia");

            Assert.Equal("Sofia", actualResult.Name);
        }
Esempio n. 10
0
        public async Task GetAllNewsAsync_WithOutData_ShouldReturnListOFNews()
        {
            var         context    = SteuDbContextInMemoryFactory.InitializeContext();
            NewsService service    = this.IntializeNewsService(context);
            var         repository = new EfDeletableEntityRepository <News>(context);

            var actualResult = await service.GetAllNewsAsync(1, 10, null);

            Assert.Empty(actualResult);
        }
Esempio n. 11
0
        public async Task GetAllTruckTypesAsyncTest_WithOutData_RreturnEmptyListOfTruckTypes()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeTruckTypesService(context);
            var repository = new EfRepository <TruckType>(context);

            var actualResult = await service.GetAllTruckTypesAsync <AllTruckTypesTruckEditViewModel>();

            Assert.Empty(actualResult);
        }
Esempio n. 12
0
        public async Task GetOrderDetailsForNewMessageAsync_WithCorrectData_ReturnModel()
        {
            var             context    = SteuDbContextInMemoryFactory.InitializeContext();
            MessagesService service    = this.IntializeMessagesService(context);
            var             repository = new EfDeletableEntityRepository <Message>(context);

            var actualResult
                = await service.GetOrderDetailsForNewMessageAsync <SendMessageInputModel>("orderId");

            Assert.Equal("Bulgaria", actualResult.CountryFrom);
        }
Esempio n. 13
0
        public async Task AddNewsAsync_WithCorrectAndNullPicture_ShouldAddNewsToRepository()
        {
            var         context    = SteuDbContextInMemoryFactory.InitializeContext();
            NewsService service    = this.IntializeNewsService(context);
            var         repository = new EfDeletableEntityRepository <News>(context);

            await service.AddNewsAsync("title", "content", null, "userId");

            var actualResult = await repository.All().ToListAsync();

            Assert.Single(actualResult);
        }
Esempio n. 14
0
        public async Task GetCountryByNameTest_WithNull_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();
            var repository = new EfRepository <Country>(context);

            var service = new CountriesService(repository);

            Assert.Throws <ArgumentNullException>(() => service.GetCountryByName(null));
        }
Esempio n. 15
0
        public async Task AddNewsAsync_WithCorrectData_ShouldAddNewsToRepository()
        {
            var         context    = SteuDbContextInMemoryFactory.InitializeContext();
            NewsService service    = this.IntializeNewsService(context);
            var         repository = new EfDeletableEntityRepository <News>(context);
            IFormFile   file       = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data", "dummy.txt");

            await service.AddNewsAsync("title", "content", file, "userId");

            var actualResult = await repository.All().ToListAsync();

            Assert.Single(actualResult);
        }
Esempio n. 16
0
        public async Task GetAllCountriesAsyncTest_Correct_ShouldReturnAllCountries()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();

            var repository   = new EfRepository <Country>(context);
            var service      = new CountriesService(repository);
            var actualResult = await service.GetAllCountriesAsync <AllCountiresEditLoadViewModel>();

            Assert.Equal(3, actualResult.Count);
        }
Esempio n. 17
0
        public async Task GetCountryByNameTest_WhtiCorrectData_ShouldRetunCountry()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();
            var repository = new EfRepository <Country>(context);
            var service    = new CountriesService(repository);

            var actualResult = service.GetCountryByName("Bulgaria");

            Assert.Equal("Bulgaria", actualResult.Name);
        }
Esempio n. 18
0
        public async Task AddActionToLog_WithCorrectData_ReturnTrue()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeLogsService(context);
            var repository = new EfDeletableEntityRepository <Log>(context);

            var actualResult = service.AddActionToLog("Pesho", "/");

            Assert.True(actualResult);

            var actualArray = await repository.All().ToListAsync();

            Assert.Single(actualArray);
        }
Esempio n. 19
0
        public async Task GetAddressOrCreateByCoutryNameAndTownName_WithNullTownTest_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            MapperInitializer.InitializeMapper();
            var repository     = new EfDeletableEntityRepository <Address>(context);
            var countryService = new Mock <ICountriesService>();
            var townService    = new Mock <ITownsService>();

            var service = new AddressesService(repository, countryService.Object, townService.Object);

            Assert.Throws <ArgumentNullException>(() => service.GetAddressOrCreateByCoutryNameAndTownName("Bulgaria", null));
        }
Esempio n. 20
0
        public async Task DeleteLoadByIdAsyncTest_WithIncorrectData_ShouldReturnArgumentNullException()
        {
            var          context    = SteuDbContextInMemoryFactory.InitializeContext();
            LoadsService service    = IntializeLoadService(context);
            var          repository = new EfDeletableEntityRepository <Order>(context);

            var order = new Order()
            {
                Id = "asdasd",
            };

            await repository.AddAsync(order);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.DeleteLoadByIdAsync("asd"));
        }
Esempio n. 21
0
        public async Task DeleteMessageByUserIdAsync_WithNullUserId_ShouldRetyrnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeDeleteMessagesService(context);
            var repository = new EfDeletableEntityRepository <Message>(context);

            Message message = new Message()
            {
                Content  = "content",
                SenderId = "userId",
            };
            await repository.AddAsync(message);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.DeleteMessageByUserIdAsync(null));
        }
Esempio n. 22
0
        public async Task GetPriorityTypeByNameAsync_WithInvalidPriorityTypeName_ShouldRetyrnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializePriorityTypesService(context);
            var repository = new EfRepository <PriorityType>(context);

            var priority = new PriorityType()
            {
                Name = "Normal",
            };

            await repository.AddAsync(priority);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.GetPriorityTypeByNameAsync("asd"));
        }
Esempio n. 23
0
        public async Task GetOrderByIdAsync_WithNullOrderId_ShouldReturnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeOrdersService(context);
            var repository = new EfDeletableEntityRepository <Order>(context);

            var order = new Order()
            {
                Id = "orderId",
            };

            await repository.AddAsync(order);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.GetOrderByIdAsync <SendMessageInputModel>(null));
        }
Esempio n. 24
0
        public async Task DeleteUserCompanyByCompanyIdAsyncTest_WithInCorrectData_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();
            await context.Companies.AddAsync(new Company()
            {
                Id   = "asdasd",
                Name = "Test Ltd",
            });

            await context.SaveChangesAsync();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <Company>(context);

            var service = new CompaniesService(repository);

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.DeleteUserCompanyByCompanyIdAsync("Test"));
        }
Esempio n. 25
0
        public async Task GetTruckTypeByNameAsync_WithNullTypeName_ShouldRetyrnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeTruckTypesService(context);
            var repository = new EfRepository <TruckType>(context);

            var truckType = new TruckType()
            {
                Name = "Normal",
            };

            await repository.AddAsync(truckType);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.GetTruckTypeByNameAsync(null));
        }
Esempio n. 26
0
        public async Task AddUserLikeModeratorAsync_WithNullUserId_ShouldReturnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeUsersService(context);
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var user = new SteuUser()
            {
                Id = "userId",
            };

            await repository.AddAsync(user);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.AddUserLikeModeratorAsync(null));
        }
Esempio n. 27
0
        public async Task CreateCompanyAsyncTest_WhitNullUser_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <Company>(context);

            var service = new CompaniesService(repository);

            var model = new CreateCompanyBindingModel()
            {
                Name       = "Test Ltd",
                UIC        = "123123123",
                UserId     = "asdasd asd asd asd ",
                LicenseUrl = "dadadasdadasd",
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.CreateCompanyAsync(model, null));
        }
Esempio n. 28
0
        public async Task AddUserLikeModeratorAsync_WithCorrectData_ShouldReturnTrue()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeUsersService(context);
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var user = new SteuUser()
            {
                Id = "userId",
            };

            await repository.AddAsync(user);

            await repository.SaveChangesAsync();

            var actualResult = await service.AddUserLikeModeratorAsync("userId");

            Assert.True(actualResult);
        }
Esempio n. 29
0
        public async Task ChangeUserIsAuthorizeSatusByUserIdAsync_WithNullStatus_ShouldReturnArgumentNullException()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeUsersService(context);
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var user = new SteuUser()
            {
                Id          = "userId",
                IsAuthorize = false,
            };

            await repository.AddAsync(user);

            await repository.SaveChangesAsync();

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.ChangeUserIsAuthorizeSatusByUserIdAsync("userId", null));
        }
Esempio n. 30
0
        public async Task GetTruckTypeByNameAsync_WithValidTruckTypeName_RreturnTruckType()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeTruckTypesService(context);
            var repository = new EfRepository <TruckType>(context);

            var truckType = new TruckType()
            {
                Name = "Normal",
            };

            await repository.AddAsync(truckType);

            await repository.SaveChangesAsync();

            var actualResult = await service.GetTruckTypeByNameAsync("Normal");

            Assert.Equal("Normal", actualResult.Name);
        }