public async Task CreateLoadAsyncTest_WithNullModelPropery_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); AddLoadInputModel model = new AddLoadInputModel() { CountryFrom = null, TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", SteuUserId = "asdasd", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, InputModel = new LoadCreateViewModel(), LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.CreateLoadAsync(model, "asdasd")); }
public async Task GetLoadDetailsByIdAsync_WithNullOrderId_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); var order = new Order() { Id = "orderId", IsDeleted = false, ExpireTime = DateTime.UtcNow.AddDays(7), Load = new Load(), SteuUser = new SteuUser() { Id = "asdasd", FirstName = "Pesho", }, }; await repository.AddAsync(order); await repository.SaveChangesAsync(); await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetLoadDetailsByIdAsync <DetailsLoadViewModel>(null)); }
public async Task GetAllCompanyLoadsByUserIdAsync_WithIncorectUserId_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); var order = new Order() { Id = "orderId", IsDeleted = false, ExpireTime = DateTime.UtcNow.AddDays(7), Load = new Load(), SteuUser = new SteuUser() { Id = "asdasd", Company = new Company() { Id = "companyId", }, }, }; await repository.AddAsync(order); await repository.SaveChangesAsync(); await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetAllCompanyLoadsByUserIdAsync(1, 10, "userId")); }
public async Task GetLoadDetailsByIdAsync_WithCorrectData_ShouldReturnDetailsLoadViewModel() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); var order = new Order() { Id = "orderId", IsDeleted = false, ExpireTime = DateTime.UtcNow.AddDays(7), Load = new Load(), SteuUser = new SteuUser() { Id = "asdasd", FirstName = "Pesho", }, }; await repository.AddAsync(order); await repository.SaveChangesAsync(); var actualresutlt = await service.GetLoadDetailsByIdAsync <DetailsLoadViewModel>("orderId"); Assert.Equal("Pesho", actualresutlt.SteuUserFirstName); }
public async Task GetCountOfLoadsAsync_WithData_ShouldReturnCount() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); var order = new Order() { Id = "orderId", IsDeleted = false, ExpireTime = DateTime.UtcNow.AddDays(7), Load = new Load(), SteuUser = new SteuUser() { Id = "userId", }, }; await repository.AddAsync(order); await repository.SaveChangesAsync(); var actualResult = await service.GetCountOfLoadsAsync(); Assert.Equal(1, actualResult); }
public async Task CreateLoadAsyncTest_WithCorrectData_ShouldReturnLoad() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); AddLoadInputModel model = new AddLoadInputModel() { CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", SteuUserId = "asdasd", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, InputModel = new LoadCreateViewModel(), LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", }; await service.CreateLoadAsync(model, "asdasd"); var actualResult = await repository.All().ToListAsync(); Assert.Single(actualResult); }
public async Task GetAllCompanyLoadsByUserIdAsync_WithNonUserLoads_ShouldReturnEmptyList() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); var order = new Order() { Id = "orderId", IsDeleted = false, ExpireTime = DateTime.UtcNow.AddDays(7), Load = new Load(), SteuUser = new SteuUser() { Id = "userId", Company = new Company() { Id = "company", }, }, }; await repository.AddAsync(order); await repository.SaveChangesAsync(); var actualResult = await service.GetAllCompanyLoadsByUserIdAsync(1, 10, "asdasd"); Assert.Empty(actualResult); }
public async Task GetCountOfLoadsAsync_WithOutData_ShouldReturnZero() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var actualResult = await service.GetCountOfLoadsAsync(); Assert.Equal(0, actualResult); }
public async Task GetAllAvaibleLoadsAsync_WithoutData_ShouldReturnEmptyList() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var actualResult = await service.GetAllAvaibleLoadsAsync(1, 10); Assert.Empty(actualResult); }
private static LoadsService IntializeLoadService(SteuDbContext context) { MapperInitializer.InitializeMapper(); var repository = new EfDeletableEntityRepository <Order>(context); var userService = new Mock <IUsersService>(); userService.Setup(x => x.GetUserByIdAsync("asdasd")) .ReturnsAsync(new SteuUser() { UserName = "******", FirstName = "Pesho", Id = "asdasd", Company = new Company() { Id = "companyId", }, }); var countriesService = new Mock <ICountriesService>(); var townService = new Mock <ITownsService>(); var truckTypesService = new Mock <ITruckTypesService>(); truckTypesService.Setup(x => x.GetTruckTypeByNameAsync("Normal")) .Returns(Task.FromResult(new TruckType() { Name = "Normal" })); var priorityTypesService = new Mock <IPriorityTypesService>(); priorityTypesService.Setup(x => x.GetPriorityTypeByNameAsync("Normal")) .Returns(Task.FromResult(new PriorityType() { Name = "Normal" })); var mapper = new Mock <IMapper>(); mapper.Setup( x => x.Map <DetailsLoadViewModel>(It.IsAny <Order>())) .Returns(new DetailsLoadViewModel() { SteuUserFirstName = "Pesho" }); var addressesService = new Mock <IAddressesService>(); var service = new LoadsService( repository, addressesService.Object, mapper.Object, priorityTypesService.Object, truckTypesService.Object, userService.Object); return(service); }
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")); }
public async Task GetAllAvaibleLoadsAsync_WithCorrectData_ShouldReturnListOfLoads() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { Id = "asdasd", Load = new Load(), ExpireTime = DateTime.UtcNow.AddDays(7), IsDeleted = false, }); await context.SaveChangesAsync(); var actualResult = await service.GetAllAvaibleLoadsAsync(1, 10); Assert.Single(actualResult); }
public async Task DeleteLoadByIdAsyncTest_WithCorrectData_ShouldLoadIsDeletedTrue() { 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(); var orders = await context.Orders.ToListAsync(); await service.DeleteLoadByIdAsync("asdasd"); Assert.True(orders[0].IsDeleted); }
public async Task EditLoadAsync_WithCorrectData_ShouldEditLoad() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { Id = "asdasd", Load = new Load(), }); await context.SaveChangesAsync(); EditLoadViewModel model = new EditLoadViewModel() { Id = "asdasd", CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", InputModel = new LoadEditViewModel(), }; await service.EditLoadAsync(model); var actualResult = await repository.All().ToListAsync(); Assert.Equal(12312231, actualResult[0].Price); }
public async Task GetAllAvaibleLoadsBySearchAsync_WhithNonExistingLoad_ShoulRetunEmptyList() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { AddressFrom = new Address() { Country = new Country() { Name = "Bulgaria" }, Town = new Town() { Name = "Sofia" }, }, ExpireTime = DateTime.UtcNow.AddDays(7), IsDeleted = false, Load = new Load(), }); await context.SaveChangesAsync(); SearchLoadInputModel model = new SearchLoadInputModel() { CountryTo = "Bulgaria", }; var actualResult = await service.GetAllAvaibleLoadsBySearchAsync <AllAvaibleLoadsBySearchViewModel>(model); Assert.Empty(actualResult); }
public async Task EditLoadAsync_WithIncorectOrderId_ShouldReturnArgumentNullException() { var context = SteuDbContextInMemoryFactory.InitializeContext(); LoadsService service = IntializeLoadService(context); var repository = new EfDeletableEntityRepository <Order>(context); await repository.AddAsync(new Order() { Id = "asdasd", Load = new Load(), }); await context.SaveChangesAsync(); EditLoadViewModel model = new EditLoadViewModel() { Id = "asd", CountryFrom = "Bulgaria", TownFrom = "Sofia", CountryTo = "Croatia", TownTo = "Zagreb", TruckTypeName = "Normal", Priority = "Normal", Circle = false, ExpireTime = DateTime.UtcNow, LoadDeliveryTime = DateTime.UtcNow, LoadTime = DateTime.UtcNow, LoadVolume = 100, LoadWeight = 20000, Price = 12312231, Referer = "dasada", InputModel = new LoadEditViewModel(), }; await Assert.ThrowsAsync <ArgumentNullException>(() => service.EditLoadAsync(model)); }