Advertisement
Iv555

Untitled

Dec 23rd, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. private Mock<UserManager<ApplicationUser>> mockUserManager;
  2.  
  3. public ApplicationDbContext GetDbContext()
  4. {
  5. DbContextOptionsBuilder<ApplicationDbContext> optionBuilder = new DbContextOptionsBuilder<ApplicationDbContext>()
  6. .UseInMemoryDatabase("TestShipment");
  7. ApplicationDbContext dbContext = new ApplicationDbContext(optionBuilder.Options);
  8. return dbContext;
  9. }
  10.  
  11. public EmployeeService GetEmployeeService()
  12. {
  13. EfDeletableEntityRepository<Employee> employeeRepo = new EfDeletableEntityRepository<Employee>(this.GetDbContext());
  14.  
  15. EfDeletableEntityRepository<Office> officeRepo = new EfDeletableEntityRepository<Office>(this.GetDbContext());
  16.  
  17. EfDeletableEntityRepository<Position> positionRepo = new EfDeletableEntityRepository<Position>(this.GetDbContext());
  18.  
  19. EfDeletableEntityRepository<Vehicle> vehicleRepo = new EfDeletableEntityRepository<Vehicle>(this.GetDbContext());
  20.  
  21. this.mockUserManager = new Mock<UserManager<ApplicationUser>>(
  22. Mock.Of<IUserStore<ApplicationUser>>(), null, null, null, null, null, null, null, null);
  23.  
  24. EmployeeService employeeService = new EmployeeService(employeeRepo, officeRepo, positionRepo, vehicleRepo, this.mockUserManager.Object);
  25.  
  26. return employeeService;
  27. }
  28.  
  29. public ShipmentService GetShipmentService()
  30. {
  31. EfDeletableEntityRepository<Shipment> shipmentRepo = new EfDeletableEntityRepository<Shipment>(this.GetDbContext());
  32.  
  33. EfDeletableEntityRepository<Customer> customerRepo = new EfDeletableEntityRepository<Customer>(this.GetDbContext());
  34.  
  35. EfDeletableEntityRepository<Employee> employeeRepo = new EfDeletableEntityRepository<Employee>(this.GetDbContext());
  36.  
  37. EfDeletableEntityRepository<EmployeeShipment> employeeShipmentRepo = new EfDeletableEntityRepository<EmployeeShipment>(this.GetDbContext());
  38.  
  39. EfDeletableEntityRepository<ShipmentVehicle> shipmentVehicleRepo = new EfDeletableEntityRepository<ShipmentVehicle>(this.GetDbContext());
  40.  
  41. EfDeletableEntityRepository<Vehicle> vehicleRepo = new EfDeletableEntityRepository<Vehicle>(this.GetDbContext());
  42.  
  43. EfDeletableEntityRepository<ShipmentTrackingPath> shipmentTrackingPathRepo = new EfDeletableEntityRepository<ShipmentTrackingPath>(this.GetDbContext());
  44.  
  45. ShipmentService shipmentService = new ShipmentService(shipmentRepo, customerRepo, employeeRepo, employeeShipmentRepo, shipmentVehicleRepo, vehicleRepo, shipmentTrackingPathRepo);
  46. return shipmentService;
  47. }
  48.  
  49. public CustomerService GetCustomerService()
  50. {
  51. EfDeletableEntityRepository<Customer> customerRepo = new EfDeletableEntityRepository<Customer>(this.GetDbContext());
  52.  
  53. CustomerService customerService = new CustomerService(customerRepo);
  54. return customerService;
  55. }
  56.  
  57. public CustomerFormModel GetCustomer1FormModel()
  58. {
  59. CustomerFormModel customerModel1 = new CustomerFormModel()
  60. {
  61. FirstName = "Gosho",
  62. MiddleName = "Goshev",
  63. LastName = "Marinov",
  64. Address = "Lazur block 33",
  65. City = "Bourgas",
  66. Country = "Bulgaria",
  67. CompanyName = string.Empty,
  68. PhoneNumber = "00359888111111",
  69. };
  70.  
  71. return customerModel1;
  72. }
  73.  
  74. public CustomerFormModel GetCustomer2FormModel()
  75. {
  76. CustomerFormModel customerModel2 = new CustomerFormModel()
  77. {
  78. FirstName = "Pesho",
  79. MiddleName = "Peshev",
  80. LastName = "Peshev",
  81. Address = "Vl. Varnenchik block 9",
  82. City = "Varna",
  83. Country = "Bulgaria",
  84. CompanyName = string.Empty,
  85. PhoneNumber = "00359888222222",
  86. };
  87.  
  88. return customerModel2;
  89. }
  90.  
  91. public EmployeeFormModel GetEmployeeFormModel()
  92. {
  93. EmployeeFormModel model = new EmployeeFormModel()
  94. {
  95. FirstName = "Milen",
  96. MiddleName = "Milenov",
  97. LastName = "Milenov",
  98. Address = "Zornitsa block 15",
  99. City = "Bourgas",
  100. Country = "Bulgaria",
  101. HiredOn = DateTime.Now.AddDays(-2),
  102. PhoneNumber = "00359987654314",
  103. OfficeId = 1,
  104. PositionId = 8,
  105. VehicleId = null,
  106. ResignOn = null,
  107. Salary = 1200,
  108. };
  109.  
  110. return model;
  111. }
  112.  
  113. [Fact]
  114.  
  115. public async Task GetShipmentForEditAsyncTest()
  116. {
  117. await this.GetCustomerService().CreateCustomerAsync(this.GetCustomer1FormModel());
  118.  
  119. Customer customer1 = await this.GetDbContext().Customers.FirstOrDefaultAsync();
  120.  
  121. await this.GetCustomerService().CreateCustomerAsync(this.GetCustomer2FormModel());
  122.  
  123. Customer customer2 = await this.GetDbContext().Customers.Skip(1).FirstOrDefaultAsync();
  124.  
  125. ShipmentFormModel model = new ShipmentFormModel()
  126. {
  127. TrackingNumber = "11111111112",
  128. SenderFirstName = customer1.FirstName,
  129. SenderLastName = customer1.LastName,
  130. SenderPhoneNumber = customer1.PhoneNumber,
  131. ReceiverFirstName = customer2.FirstName,
  132. ReceiverLastName = customer2.LastName,
  133. ReceiverPhoneNumber = customer2.PhoneNumber,
  134. PickUpAddress = customer1.Address,
  135. PickUpTown = customer1.City,
  136. PickUpCountry = customer1.Country,
  137. DestinationAddress = customer2.Address,
  138. DestinationTown = customer2.City,
  139. DestinationCountry = customer2.Country,
  140. Weight = 0.90,
  141. DeliveryWay = 0,
  142. DeliveryType = 0,
  143. ProductType = (ProductType)4,
  144. Price = 4.90m,
  145. };
  146. await this.GetShipmentService().CreateShipmentAsync(model);
  147.  
  148. Shipment shipment = await this.GetDbContext().Shipments.LastOrDefaultAsync();
  149.  
  150. ShipmentFormModel editModel = await this.GetShipmentService()
  151. .GetShipmentForEditAsync(shipment.Id);
  152.  
  153. Assert.Equal(shipment.TrackingNumber, editModel.TrackingNumber);
  154. Assert.Equal(shipment.PickupAddress, editModel.PickUpAddress);
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement