Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Mock<UserManager<ApplicationUser>> mockUserManager;
- public ApplicationDbContext GetDbContext()
- {
- DbContextOptionsBuilder<ApplicationDbContext> optionBuilder = new DbContextOptionsBuilder<ApplicationDbContext>()
- .UseInMemoryDatabase("TestShipment");
- ApplicationDbContext dbContext = new ApplicationDbContext(optionBuilder.Options);
- return dbContext;
- }
- public EmployeeService GetEmployeeService()
- {
- EfDeletableEntityRepository<Employee> employeeRepo = new EfDeletableEntityRepository<Employee>(this.GetDbContext());
- EfDeletableEntityRepository<Office> officeRepo = new EfDeletableEntityRepository<Office>(this.GetDbContext());
- EfDeletableEntityRepository<Position> positionRepo = new EfDeletableEntityRepository<Position>(this.GetDbContext());
- EfDeletableEntityRepository<Vehicle> vehicleRepo = new EfDeletableEntityRepository<Vehicle>(this.GetDbContext());
- this.mockUserManager = new Mock<UserManager<ApplicationUser>>(
- Mock.Of<IUserStore<ApplicationUser>>(), null, null, null, null, null, null, null, null);
- EmployeeService employeeService = new EmployeeService(employeeRepo, officeRepo, positionRepo, vehicleRepo, this.mockUserManager.Object);
- return employeeService;
- }
- public ShipmentService GetShipmentService()
- {
- EfDeletableEntityRepository<Shipment> shipmentRepo = new EfDeletableEntityRepository<Shipment>(this.GetDbContext());
- EfDeletableEntityRepository<Customer> customerRepo = new EfDeletableEntityRepository<Customer>(this.GetDbContext());
- EfDeletableEntityRepository<Employee> employeeRepo = new EfDeletableEntityRepository<Employee>(this.GetDbContext());
- EfDeletableEntityRepository<EmployeeShipment> employeeShipmentRepo = new EfDeletableEntityRepository<EmployeeShipment>(this.GetDbContext());
- EfDeletableEntityRepository<ShipmentVehicle> shipmentVehicleRepo = new EfDeletableEntityRepository<ShipmentVehicle>(this.GetDbContext());
- EfDeletableEntityRepository<Vehicle> vehicleRepo = new EfDeletableEntityRepository<Vehicle>(this.GetDbContext());
- EfDeletableEntityRepository<ShipmentTrackingPath> shipmentTrackingPathRepo = new EfDeletableEntityRepository<ShipmentTrackingPath>(this.GetDbContext());
- ShipmentService shipmentService = new ShipmentService(shipmentRepo, customerRepo, employeeRepo, employeeShipmentRepo, shipmentVehicleRepo, vehicleRepo, shipmentTrackingPathRepo);
- return shipmentService;
- }
- public CustomerService GetCustomerService()
- {
- EfDeletableEntityRepository<Customer> customerRepo = new EfDeletableEntityRepository<Customer>(this.GetDbContext());
- CustomerService customerService = new CustomerService(customerRepo);
- return customerService;
- }
- public CustomerFormModel GetCustomer1FormModel()
- {
- CustomerFormModel customerModel1 = new CustomerFormModel()
- {
- FirstName = "Gosho",
- MiddleName = "Goshev",
- LastName = "Marinov",
- Address = "Lazur block 33",
- City = "Bourgas",
- Country = "Bulgaria",
- CompanyName = string.Empty,
- PhoneNumber = "00359888111111",
- };
- return customerModel1;
- }
- public CustomerFormModel GetCustomer2FormModel()
- {
- CustomerFormModel customerModel2 = new CustomerFormModel()
- {
- FirstName = "Pesho",
- MiddleName = "Peshev",
- LastName = "Peshev",
- Address = "Vl. Varnenchik block 9",
- City = "Varna",
- Country = "Bulgaria",
- CompanyName = string.Empty,
- PhoneNumber = "00359888222222",
- };
- return customerModel2;
- }
- public EmployeeFormModel GetEmployeeFormModel()
- {
- EmployeeFormModel model = new EmployeeFormModel()
- {
- FirstName = "Milen",
- MiddleName = "Milenov",
- LastName = "Milenov",
- Address = "Zornitsa block 15",
- City = "Bourgas",
- Country = "Bulgaria",
- HiredOn = DateTime.Now.AddDays(-2),
- PhoneNumber = "00359987654314",
- OfficeId = 1,
- PositionId = 8,
- VehicleId = null,
- ResignOn = null,
- Salary = 1200,
- };
- return model;
- }
- [Fact]
- public async Task GetShipmentForEditAsyncTest()
- {
- await this.GetCustomerService().CreateCustomerAsync(this.GetCustomer1FormModel());
- Customer customer1 = await this.GetDbContext().Customers.FirstOrDefaultAsync();
- await this.GetCustomerService().CreateCustomerAsync(this.GetCustomer2FormModel());
- Customer customer2 = await this.GetDbContext().Customers.Skip(1).FirstOrDefaultAsync();
- ShipmentFormModel model = new ShipmentFormModel()
- {
- TrackingNumber = "11111111112",
- SenderFirstName = customer1.FirstName,
- SenderLastName = customer1.LastName,
- SenderPhoneNumber = customer1.PhoneNumber,
- ReceiverFirstName = customer2.FirstName,
- ReceiverLastName = customer2.LastName,
- ReceiverPhoneNumber = customer2.PhoneNumber,
- PickUpAddress = customer1.Address,
- PickUpTown = customer1.City,
- PickUpCountry = customer1.Country,
- DestinationAddress = customer2.Address,
- DestinationTown = customer2.City,
- DestinationCountry = customer2.Country,
- Weight = 0.90,
- DeliveryWay = 0,
- DeliveryType = 0,
- ProductType = (ProductType)4,
- Price = 4.90m,
- };
- await this.GetShipmentService().CreateShipmentAsync(model);
- Shipment shipment = await this.GetDbContext().Shipments.LastOrDefaultAsync();
- ShipmentFormModel editModel = await this.GetShipmentService()
- .GetShipmentForEditAsync(shipment.Id);
- Assert.Equal(shipment.TrackingNumber, editModel.TrackingNumber);
- Assert.Equal(shipment.PickupAddress, editModel.PickUpAddress);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement