public async Task AttachShipmentToDriverShouldChainDriverWithShipment() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); var currShipment = new Shipment { Width = 2, Length = 2, Height = 2, Weight = 200, CountOfPallets = 3, Comment = "Some Text", IsDelivered = true }; await db.Shipments.AddAsync(currShipment); await db.SaveChangesAsync(); var driver = new ApplicationUser { FirstName = "Ivan" }; var driversService = new DriversService(db); await driversService.AttachShipmentToDriverAsync(currShipment.Id, driver.Id); Assert.Equal(currShipment.DriverId, driver.Id); }
public DeliveriesManager(DeliveriesService deliveriesService, PurchasesService purchasesService, DeliveryPurchasesService deliveryPurchasesService, PurchaseUnitsService purchaseUnitsService, DriversService driversService) : base(deliveriesService) { _deliveriesService = deliveriesService; _purchaseUnitsService = purchaseUnitsService; _deliveryPurchasesService = deliveryPurchasesService; _deliveryPurchasesService = deliveryPurchasesService; _driversService = driversService; }
public async Task IsPhoneNotExistShouldReturnFalse() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); await db.Users.AddAsync(new ApplicationUser { PhoneNumber = "0888-111-222" }); await db.SaveChangesAsync(); var driversService = new DriversService(db); bool result = driversService.IsPhoneExist("0888-111-999"); Assert.False(result); }
public async void DriversService_GetAll_NoDrivers() { // Arrange var mockDriver = MockDriverData.GetEmptyEntityListAsync(); var mockDriverRepo = new MockDriverRepository().MockGetAll(mockDriver); var mockDriverLoggerRepo = new MockLoggerRepository <DriversService>(); var mockDriversService = new DriversService(mockDriverRepo.Object, mockDriverLoggerRepo.Object); // Act var drivers = await mockDriversService.GetDrivers(); // Assert Assert.Empty(drivers); mockDriverRepo.VerifyGetAllForDriver(Times.Once()); }
public async void DriversService_GetById_ValidId() { // Arrange var mockId = 13; var mockDriver = MockDriverData.GetSingleEntityAsync(); var mockDriverRepo = new MockDriverRepository().MockGetById(mockDriver); var mockDriverLoggerRepo = new MockLoggerRepository <DriversService>(); var mockDriversService = new DriversService(mockDriverRepo.Object, mockDriverLoggerRepo.Object); // Act var driver = await mockDriversService.GetDriver(mockId); // Assert Assert.Equal(mockId, driver.id); mockDriverRepo.VerifyGetByIdForDriver(Times.Once()); }
public async void DriversService_GetAllFilter_NoDrivers() { // Arrange var mockDriver = MockDriverData.GetEmptyEntityListAsync(); DriversResourceParameters parameters = new DriversResourceParameters { Name = "Vettel" }; var mockDriverRepo = new MockDriverRepository().MockGetByName(mockDriver); var mockDriverLoggerRepo = new MockLoggerRepository <DriversService>(); var mockDriversService = new DriversService(mockDriverRepo.Object, mockDriverLoggerRepo.Object); // Act var drivers = await mockDriversService.GetDrivers(parameters); //Assert Assert.Empty(drivers); mockDriverRepo.VerifyGetByNameForDriver(Times.Once()); }
public async Task IsDriverNotExistShouldReturnFalse() { var currUser = new ApplicationUser() { Email = "*****@*****.**" }; var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); await db.Users.AddAsync(currUser); await db.SaveChangesAsync(); var driversService = new DriversService(db); bool result = driversService.IsDriverExist("*****@*****.**"); Assert.False(result); }
public void DeleteDriverShouldDeleteDriverFromDb() { var listWithUsers = new List <ApplicationUser>() { new ApplicationUser() { Email = "*****@*****.**", FirstName = "Pesho", LastName = "Ivanov", PhoneNumber = "0888-123-456" }, new ApplicationUser() { Email = "*****@*****.**", FirstName = "Ginko", LastName = "Ivanov", PhoneNumber = "0888-123-456" }, new ApplicationUser() { Email = "*****@*****.**", FirstName = "Pesho", LastName = "Ivanov", PhoneNumber = "0888-123-456" } }; var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("different_Fucking_name"); var dbContx = new ApplicationDbContext(optionsBuilder.Options); dbContx.Users.AddRange(listWithUsers); dbContx.SaveChanges(); var driversService1 = new DriversService(dbContx); driversService1.DeleteDriver("*****@*****.**"); driversService1.DeleteDriver("*****@*****.**"); dbContx.SaveChanges(); int result = dbContx.Users.Count(); Assert.Equal(1, result); }
public async Task AddDriverShouldCreateNewDriverInDbAndPutItToDriverRole() { List <ApplicationUser> _users = new List <ApplicationUser>(); var input = new DriverInputModel() { Email = "*****@*****.**", Password = "******", FirstName = "Pesho", LastName = "Ivanov", PhoneNumber = "0888-123-456" }; var input1 = new DriverInputModel() { Email = "*****@*****.**", Password = "******", FirstName = "Gosho", LastName = "Ivanov", PhoneNumber = "0888-123-456" }; var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); UserManager <ApplicationUser> _userManager = MockUserManager <ApplicationUser>(_users).Object; var driversService = new DriversService(db, _userManager); await driversService.AddDriverAsync(input); await driversService.AddDriverAsync(input1); int result = _users.Count; string resultFirstName = _users.FirstOrDefault(u => u.FirstName == "Pesho").FirstName; Assert.Equal(2, result); Assert.Equal("Pesho", resultFirstName); }
public async Task ChangeShipmentDataShouldReplaceCurrShipmentWithNewData() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); var currShipment = new Shipment { Width = 2, Length = 2, Height = 2, Weight = 200, CountOfPallets = 3, Comment = "Some Text", IsDelivered = true }; await db.Shipments.AddAsync(currShipment); await db.SaveChangesAsync(); var editShipment = new EditShipment { ShipmentId = currShipment.Id, Width = 4, Length = 4, Height = 4, Weight = 400, CountOfPallets = 4, Comment = "Editted Text", IsDelivered = false }; var driversService = new DriversService(db); Task result = driversService.ChangeShipmentDataAsync(editShipment); Assert.True(result.IsCompletedSuccessfully); Assert.Equal(400, currShipment.Weight); }
public async Task GetShipmentShouldReturnSearchedShipment() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); var currShipment = new Shipment() { CountOfPallets = 333, LoadingDate = DateTime.UtcNow.AddDays(1), LoadingAddress = new Address() { Town = "Sofia" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" } }; //Направи ми 5 shipments и ги добави в db.Shipments var shipments = new List <Shipment>() { new Shipment() { CountOfPallets = 444, LoadingDate = DateTime.UtcNow.AddDays(2), LoadingAddress = new Address() { Town = "Ruse" }, UnloadingAddress = new Address() { Town = "Varna" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" } }, new Shipment() { CountOfPallets = 555, LoadingDate = DateTime.UtcNow.AddDays(3), LoadingAddress = new Address() { Town = "Plovdiv" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" } }, new Shipment() { CountOfPallets = 666, LoadingDate = DateTime.UtcNow.AddDays(4), LoadingAddress = new Address() { Town = "Plovdiv" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" } } }; shipments.Add(currShipment); await db.Shipments.AddRangeAsync(shipments); await db.SaveChangesAsync(); var driversService = new DriversService(db); var result = driversService.GetShipment(currShipment.Id); //Assert that count of Shipments per this page is 1 Assert.NotNull(result); }
public async Task GetMyShipmentsShouldReturnOnlyThisDriverShipments() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); var currDriver = new ApplicationUser() { FirstName = "Kiro", LastName = "Kirov" }; await db.Users.AddAsync(currDriver); await db.SaveChangesAsync(); //Направи ми 5 shipments и ги добави в db.Shipments var shipments = new List <Shipment>() { new Shipment() { CountOfPallets = 333, LoadingDate = DateTime.UtcNow.AddDays(1), LoadingAddress = new Address() { Town = "Sofia" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" }, DriverId = currDriver.Id }, new Shipment() { CountOfPallets = 444, LoadingDate = DateTime.UtcNow.AddDays(2), LoadingAddress = new Address() { Town = "Ruse" }, UnloadingAddress = new Address() { Town = "Varna" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" }, DriverId = currDriver.Id }, new Shipment() { CountOfPallets = 555, LoadingDate = DateTime.UtcNow.AddDays(3), LoadingAddress = new Address() { Town = "Plovdiv" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" }, Driver = currDriver }, new Shipment() { CountOfPallets = 666, LoadingDate = DateTime.UtcNow.AddDays(4), LoadingAddress = new Address() { Town = "Plovdiv" }, UnloadingAddress = new Address() { Town = "Ruse" }, Sender = new Participant() { Name = "Company1" }, Receiver = new Participant() { Name = "Company2" }, Driver = currDriver } }; await db.Shipments.AddRangeAsync(shipments); await db.SaveChangesAsync(); var driversService = new DriversService(db); var result = driversService.GetMyShipments(currDriver.Id, 2, 2); //Assert that count of Shipments per this page is 1 Assert.Equal(2, result.DriverShipmentsOfCurrentPage.Count()); }
public async Task GetAllShipmentsShouldReturnExactCountOfShipmentsPerPage() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("name"); var db = new ApplicationDbContext(optionsBuilder.Options); //Направи ми 5 shipments и ги добави в db.Shipments var shipments = new List <Shipment>() { new Shipment() { CountOfPallets = 333, LoadingDate = DateTime.UtcNow.AddDays(1), LoadingAddress = new Address() { Town = "Sofia" }, UnloadingAddress = new Address() { Town = "Ruse" } }, new Shipment() { CountOfPallets = 444, LoadingDate = DateTime.UtcNow.AddDays(2), LoadingAddress = new Address() { Town = "Ruse" }, UnloadingAddress = new Address() { Town = "Varna" } }, new Shipment() { CountOfPallets = 555, LoadingDate = DateTime.UtcNow.AddDays(3), LoadingAddress = new Address() { Town = "Plovdiv" }, UnloadingAddress = new Address() { Town = "Ruse" } }, new Shipment() { CountOfPallets = 666, LoadingDate = DateTime.UtcNow.AddDays(4), LoadingAddress = new Address() { Town = "Burgas" }, UnloadingAddress = new Address() { Town = "Ruse" } }, new Shipment() { CountOfPallets = 777, LoadingDate = DateTime.UtcNow.AddDays(5), LoadingAddress = new Address() { Town = "Aitos" }, UnloadingAddress = new Address() { Town = "Vidin" } } }; await db.Shipments.AddRangeAsync(shipments); await db.SaveChangesAsync(); var driversService = new DriversService(db); var result = driversService.GetAllShipments(2, 3); //Assert that count of Shipment per this page are 2 Assert.Equal(2, result.ShipmentsOfCurrPage.Count()); }
public DriversManager(DriversService driversService, DeliveriesService deliveriesService) : base(driversService) { _deliveriesService = deliveriesService; _driversService = driversService; }