private void SeedData() { var context = InMemoryDatabase.GetDbContext(); context.BuildingTypes.AddRange(TestData); context.SaveChanges(); }
private void SeedData() { var context = InMemoryDatabase.GetDbContext(); context.Addresses.AddRange(GetTestData); context.SaveChanges(); }
public async Task GetOrderByStatusWithCorrectStatusShouldReturnTheOrder() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var methodResult = new List <OrderByStatusViewModel>(); var orderFromDb = GetTestData().FirstOrDefault(); var expectedResult = Mapper.Map <Order, OrderByStatusViewModel>(orderFromDb, opt => opt.ConfigureMap() .ForMember(dest => dest.IssuerName, m => m.MapFrom(src => src.Issuer.UserName))); methodResult.Add(expectedResult); var orderStatus = orderFromDb.Status; var orderUser = orderFromDb.Issuer.UserName; var orderService = new Mock <IOrderService>(); orderService.Setup(g => g.GetOrdersByStatus <OrderByStatusViewModel>(orderStatus, orderUser)).Returns(methodResult); var actualResult = orderService.Object.GetOrdersByStatus <OrderByStatusViewModel>(orderStatus, orderUser).FirstOrDefault(); Assert.Same(expectedResult.IssuerName, actualResult.IssuerName); Assert.Same(expectedResult.OrderStatus, actualResult.OrderStatus); }
public async Task GetAllOrdersSortedByUserThenByCompanyShouldReturnAllOrdersInTheDataBase() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var methodResults = new List <AdminOrderViewModel>(); var ordersFromDb = GetTestData(); foreach (var order in ordersFromDb) { var mappedOrder = Mapper.Map <Order, AdminOrderViewModel>(order, opt => opt.ConfigureMap() .ForMember(dest => dest.IssuerName, m => m.MapFrom(src => src.Issuer.UserName))); methodResults.Add(mappedOrder); } var orderService = new Mock <IOrderService>(); orderService.Setup(g => g.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>()).Returns(methodResults); var actualResults = orderService.Object.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>(); for (int i = 0; i < methodResults.Count; i++) { Assert.Same(methodResults[i].IssuerName, actualResults[i].IssuerName); Assert.Same(methodResults[i].OrderStatus, actualResults[i].OrderStatus); } }
public void GetAllOrdersSortedByUserThenByCompanyWithNoOrdersInDataBaseShouldReturnEmpyList() { var context = InMemoryDatabase.GetDbContext(); var service = new OrderService(context); var actualResult = service.GetAllOrdersSortedByUserThenByCompany <AdminOrderViewModel>(); Assert.Empty(actualResult); }
public void GetAllInvoiceShouldReturnEmptyListIfThereIsNoIvoices() { var context = InMemoryDatabase.GetDbContext(); var service = new InvoiceService(context); var invoiceFromDb = service.GetAllInovoices <InvoiceViewModel>(); Assert.Empty(invoiceFromDb); }
public async Task DeleteUnexistingAddressShouldReturnFalse() { var context = InMemoryDatabase.GetDbContext(); var invalidId = 55; var addressServices = new AddressServices(context); var actualResult = await addressServices.DeleteAddressAsync(invalidId); Assert.IsFalse(actualResult, ShouldReturnFalseMessage); }
public void GetAllInvoiceByUserIdShouldReturnEmptyListIfThereIsNoSuchUser() { var context = InMemoryDatabase.GetDbContext(); var service = new InvoiceService(context); var fakeId = "Fake"; var invoiceFromDb = service.GetAllInovoicesByUserId <InvoiceViewModel>(fakeId); Assert.Empty(invoiceFromDb); }
public OfferServicesTests() { this.context = InMemoryDatabase.GetDbContext(); this.mapper = this.GetMapper(); this.imageServices = new Mock <IImageServices>(); this.cloudinaryServices = new Mock <ICloudinaryService>(); this.userServices = new Mock <IUserServices>(); this.realEstateServices = new Mock <IRealEstateServices>(); this.referenceNumberGenerator = new Mock <IReferenceNumberGenerator>(); this.SeedData(); }
public void GetOrderByStatusWithIncorrectParametersShouldReturnEmptyList() { var context = InMemoryDatabase.GetDbContext(); var service = new OrderService(context); var missingOrderStatus = OrderStatus.Accepted; var missingUserName = "******"; var actualResult = service.GetOrdersByStatus <OrderByStatusViewModel>(missingOrderStatus, missingUserName); Assert.Empty(actualResult); }
public async Task DeleteExistingAddressShouldReturnTrue() { var context = InMemoryDatabase.GetDbContext(); int idToDelete = 3; var addressToDelete = GetTestData.FirstOrDefault(x => x.Id == idToDelete); var addressServices = new AddressServices(context); var actualResult = await addressServices.DeleteAddressAsync(idToDelete); Assert.IsTrue(actualResult, ShouldReturnFalseMessage); Assert.That(addressToDelete.IsDeleted = true); }
public async Task CreateOrderAsyncShoulCreateANewOrder() { var context = InMemoryDatabase.GetDbContext(); var service = new OrderService(context); var clothing = new Clothing(); var issuerId = "id"; await service.CreateOrderAsync(clothing, issuerId); Assert.NotEmpty(context.Orders); }
public RealEstateServicesTests() { this.context = InMemoryDatabase.GetDbContext(); this.SeedData(); this.realEstateTypeServices = new Mock <IRealEstateTypeServices>(); this.citiesServices = new Mock <ICitiesServices>(); this.neighbourhoodServices = new Mock <INeighbourhoodServices>(); this.addressServices = new Mock <IAddressServices>(); this.villageServices = new Mock <IVillageServices>(); this.buildingTypeServices = new Mock <IBuildingTypeServices>(); this.heatingSystemServices = new Mock <IHeatingSystemServices>(); }
public async Task GetInvoiceByIdShouldReturnWithMissingIdNull() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var service = new InvoiceService(context); var fakeId = "FakeId"; var actualResult = service.GetInvoiceById <InvoiceViewModel>(fakeId); Assert.Null(actualResult); }
public void GetAllInvoiceShuldReturnAllInvoicesInTheDataBase() { var context = InMemoryDatabase.GetDbContext(); var service = new InvoiceService(context); var expectedResult = GetTestData(); var actualResult = service.GetAllInovoices <InvoiceViewModel>().ToList(); for (int i = 0; i < actualResult.Count(); i++) { Assert.Equal(expectedResult[i].Id, actualResult[i].Id); } }
public async Task OnCreateInvoiceAsyncServiceShouldCreateNewInvoice() { var context = InMemoryDatabase.GetDbContext(); var service = new InvoiceService(context); var userId = "userId"; var clothingId = "clothingId"; var orderId = "orderId"; await service.CreateInvoiceAsync(userId, clothingId, orderId); var actualResult = await context.Invoices.FirstOrDefaultAsync(); Assert.NotNull(actualResult); }
public async Task GetOrderFromDbByIdShouldReturnTheCorrectOrder() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var mockOrderService = new Mock <IOrderService>(); var expectedResult = GetTestData().First(); mockOrderService.Setup(g => g.GetOrderFromDbById(expectedResult.Id)).Returns(expectedResult); var service = mockOrderService.Object; var actualResult = service.GetOrderFromDbById(expectedResult.Id); Assert.Same(expectedResult, actualResult); }
public async Task GetOrderByIdWihtNonExistantIdShouldReturnNull() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var orderService = new Mock <IOrderService>(); var fakeId = "nonexistent"; var methodReturnValue = new OrderByStatusViewModel(); orderService.Setup(g => g.GetOrderById <OrderByStatusViewModel>("Id")).Returns(methodReturnValue); var service = orderService.Object; var actualResult = service.GetOrderById <OrderByStatusViewModel>(fakeId); Assert.Null(actualResult); }
public async Task GetOrderFromDbByIdWhitNoneexistenceIdShouldReturnNull() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var orderService = new Mock <IOrderService>(); var fakeId = "nonexistent"; var order = new Order(); orderService.Setup(g => g.GetOrderFromDbById("Id")).Returns(order); var service = orderService.Object; var actualResult = service.GetOrderFromDbById(fakeId); Assert.Null(actualResult); }
public async Task GetOrderByIdShouldReturnTheCorrectOrder() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var mockOrderService = new Mock <IOrderService>(); var methodReturnValue = new OrderByStatusViewModel(); var expectedResult = GetTestData().First(); mockOrderService.Setup(g => g.GetOrderById <OrderByStatusViewModel>(expectedResult.Id)).Returns(methodReturnValue); var service = mockOrderService.Object; var returnedOrder = service.GetOrderById <OrderByStatusViewModel>(expectedResult.Id); Assert.Same(expectedResult.Clothing.Name, returnedOrder.ClothingName); }
public async Task EditOrderStatusWithWrongStatusShouldNotChangeTheOrderStatus() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var orderService = new OrderService(context); var orderToEdit = context.Orders.FirstOrDefault(); var statusToChangeTo = "FakeStatus"; var orderId = orderToEdit.Id; await orderService.EditOrderStatusAsync(orderId, statusToChangeTo); var expectedResult = OrderStatus.Rejected; var actualResult = orderToEdit.Status; Assert.NotEqual(expectedResult, actualResult); }
public async Task OnCreateClothingAsyncServiceShouldCreateNewClothing() { IFormFile file = null; string filename = "SomeName"; Mock <ICloudinaryService> cloudinaryServiceMoq = new Mock <ICloudinaryService>(); var filemoq = cloudinaryServiceMoq.Setup(x => x.UploadDiagramImage(file, filename)).Returns(Task.Run(() => filename)); var context = InMemoryDatabase.GetDbContext(); string name = "Jacket"; string fabric = "Textile"; FormFile fileForDb = null; using (var stream = File.OpenRead("D:\\Ivteks72.App\\Ivteks72WebApp\\Ivteks72.App\\wwwroot\\lib\\pictures\\Location.png")) { fileForDb = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) { Headers = new HeaderDictionary(), ContentType = "application/pdf" }; } int quantity = 1; decimal pricePerUnit = 2.20m; var service = new ClothingService(context, cloudinaryServiceMoq.Object); var testClothing = new Clothing { ClothingDiagramURL = null, Fabric = fabric, Name = name, PricePerUnit = pricePerUnit, Quantity = quantity, }; var actualclothing = await service.CreateClothingAsync(name, fabric, fileForDb, quantity, pricePerUnit); Assert.NotNull(actualclothing); Assert.IsAssignableFrom(testClothing.GetType(), actualclothing); }
public async Task GetInvoiceByIdShouldReturnWithCorrectIdTheInvoice() { var context = InMemoryDatabase.GetDbContext(); await SeedData(context); var orderFromDb = GetTestData().FirstOrDefault(); var expectedResult = Mapper.Map <Invoice, InvoiceViewModel>(orderFromDb); var id = expectedResult.Id; var InvoiceService = new Mock <IInvoiceService>(); InvoiceService.Setup(g => g.GetInvoiceById <InvoiceViewModel>(id)).Returns(expectedResult); var actualResult = InvoiceService.Object.GetInvoiceById <InvoiceViewModel>(id); Assert.Equal(expectedResult.Id, actualResult.Id); }
public ReferenceNumbersGeneratorTests() { this.context = InMemoryDatabase.GetDbContext(); this.SeedData(); }
public ImageServicesTests() { this.context = InMemoryDatabase.GetDbContext(); //this.SeedData(); }
public HeatingSystemServicesTests() { context = InMemoryDatabase.GetDbContext(); this.SeedData(); }
public UsersServicesTests() { this.context = InMemoryDatabase.GetDbContext(); }
public BuildingTypeServicesTests() { this.context = InMemoryDatabase.GetDbContext(); this.SeedData(); }
public VisitorsSessionServicesTests() { this.context = InMemoryDatabase.GetDbContext(); this.SeedData(); }
public CitiesServicesTests() { this.context = InMemoryDatabase.GetDbContext(); this.SeedData(); }