public async Task GetHotOffersCarsAsync_ShouldReturnLastFourCars() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var carRepository = new EfDeletableEntityRepository <Car>(context); var homeService = new HomeService(carRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedCarsAsync(context); var hotOffersCars = await homeService.GetHotOffersCarsAsync(); var result = hotOffersCars.Any(c => c.Make == "Opel"); Assert.False(result, ErrorMessage); }
public async Task Delete_WithCorrectData_ShouldReturnCorrectResult() { var errorMessagePrefix = "ProductsService DeleteByIdAsync() method does not work properly."; var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedData(dbContext); this.productsService = new ProductsService(dbContext); var testId = dbContext.Products.First().To <ProductsServiceModel>().Id; var actualResult = await this.productsService.DeleteByIdAsync(testId); Assert.True(actualResult, errorMessagePrefix); }
public async Task All_ReturnsCorectly() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var promoCodeRepository = new EfDeletableEntityRepository <PromoCode>(context); var promoCodeService = new PromoCodeService(promoCodeRepository); var promoCodesTestSeeder = new PromoCodesTestSeeder(); await promoCodesTestSeeder.SeedPromoCodesAsync(context); var result = await promoCodeService.All <PromoCodeViewModel>(); Assert.Equal(2, result.Count()); }
public async Task CloseAsyncSetsProjectsStatusToFinished() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var projectsRepository = new EfDeletableEntityRepository <Project>(dbContext); var service = this.InitializeService(projectsRepository, dbContext); await service.CloseAsync(1, "someExec"); var result = projectsRepository.All().Where(p => p.Id == 1).Select(p => p.Status).FirstOrDefault(); Assert.Equal(3, (int)result); }
public async Task CreateAsyncReturnsProjectsId() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var projectsRepository = new EfDeletableEntityRepository <Project>(dbContext); var service = this.InitializeService(projectsRepository, dbContext); var actualResult = await service.CreateAsync("Title", "description", "authorId"); var expectedResult = projectsRepository.All().Where(p => p.Title == "Title").Select(p => p.Id).FirstOrDefault(); Assert.Equal(expectedResult, actualResult); }
public async Task GetByUserIdAsync_ShouldThrownException_WithInvalidUser() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var seeder = new Seeder(); await seeder.SeedDonorAsync(context); var userManager = this.GetUserManagerMock(context); var donorService = new DonorService(context, userManager.Object); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await donorService.GetByUserIdAsync("invalidId"); }); }
public async Task GetVotes_WithDummyData_ShouldReturnCorrectResult() { var errorMessagePrefix = "VotesService GetVotesAsync() method does not work properly."; var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedData(dbContext); this.votesService = new VotesService(dbContext); var expectedResult = dbContext.Votes.First().ServiceId; var actualResult = await this.votesService.GetVotesAsync <VotesServiceModel>(expectedResult); Assert.True(expectedResult == actualResult.Id, errorMessagePrefix + " " + "Id is not return properly."); }
public async Task RateFreelancerAsyncDecreasesStars() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var service = this.InitializeService(usersRepository, dbContext); await service.RateFreelancerAsync("TestUser1", "TestUser8", -1, " "); var user = usersRepository.All().Where(u => u.Id == "TestUser8").FirstOrDefault(); Assert.Equal(-1, user.Stars); }
public async Task DeleteByIdAsync_WithIncorrectData_ShouldThrowArgumentNullException(string incorrectId) { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var topicReportRepository = new EfDeletableEntityRepository <TopicReport>(context); var topicReportsService = new TopicReportsService(topicReportRepository); // Act // Assert await Assert.ThrowsAsync <ArgumentException>(async() => { await topicReportsService.DeleteByIdAsync(incorrectId); }); }
public async Task GetAllDeletedUsersShouldBeOneTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var userManager = this.GetUserManagerMock(); var rolesRepository = new EfDeletableEntityRepository <ApplicationRole>(dbContext); var service = new UsersService(usersRepository, userManager.Object, rolesRepository, null, null, null, null); await SeedDataAsync(dbContext); var result = service.GetAllDeletedUsers().Count(); Assert.Equal(1, result); }
public async Task GetRandomFreelancersReturnsOnlyAssignedtoCategoryUsers() { MapperInitializer.InitializeMapper(); var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var service = this.InitializeService(usersRepository, dbContext); var user = usersRepository.All().LastOrDefault(); var freelancers = service.GetRandomFreelancers <FreelancerViewModel>(user); Assert.All(freelancers, freelancer => Assert.NotEmpty(freelancer.Categories)); }
public async Task GetIdByName_WithIncorrectData_ShouldThrowArgumentException(string categoryName) { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); // Act // Assert await Assert.ThrowsAsync <ArgumentException>(async() => { categoriesService.GetIdByName(categoryName); }); }
public async Task CreateAsyncAddsEntity() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var projectOfferUsersRepository = new EfRepository <ProjectOfferUser>(dbContext); var service = new ProjectOfferUsersService(projectOfferUsersRepository); var freelancers = new List <string> { "Test1", "Test2" }; await service.CreateAsync(1, freelancers); Assert.Equal(2, projectOfferUsersRepository.All().Count()); }
public async Task CreateAsync_WithEmptyNameShouldThrowArgumentNullException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var asphaltMixtureService = new AsphaltMixtureService(context); var createAsphaltMixtureServiceModel = new CreateAsphaltMixtureServiceModel(); var asphaltMixtureType = " "; createAsphaltMixtureServiceModel.Type = asphaltMixtureType; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await asphaltMixtureService.CreateAsync(createAsphaltMixtureServiceModel); }); }
public async Task GetAllAsync_ShouldReturnCorrectResult() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var countriesRepository = new EfDeletableEntityRepository <Country>(context); var countriesService = new CountriesService(countriesRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedCountriesAsync(context); var countries = await countriesService.GetAllAsync <CountriesServiceAllModel>(); var count = countries.ToList().Count; Assert.True(count == 8, ErrorMessage); }
public async Task CloseAsyncSetsProjectsExecutor() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var projectsRepository = new EfDeletableEntityRepository <Project>(dbContext); var service = this.InitializeService(projectsRepository, dbContext); await service.CloseAsync(1, "TestUser1"); var result = projectsRepository.All().Where(p => p.Id == 1).Select(p => p.ExecutorId).FirstOrDefault(); Assert.Equal("TestUser1", result); }
public async Task GetByUserIdAsync_ShouldThrow_NullReferenceException_WithNonExistentPatient() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var seeder = new Seeder(); await seeder.SeedPatientAsync(context); var userManager = this.GetUserManagerMock(context); var patientService = new PatientService(context, userManager.Object); await Assert.ThrowsAsync <NullReferenceException>(async() => { await patientService.GetByPatientIdAsync("invalidId"); }); }
public async Task GetMostWantedReturnsFiveEntities() { MapperInitializer.InitializeMapper(); var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await SeedDataAsync(dbContext); var projectsRepository = new EfDeletableEntityRepository <Project>(dbContext); var service = this.InitializeService(projectsRepository, dbContext); var actualResult = service.GetMostWanted <ProjectTitleAndApplicantsViewModel>().Count(); Assert.Equal(5, actualResult); }
public async Task CreateAsync_WithEmptyNameShouldThrowArgumentNullException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var roadObjectService = new RoadObjectService(context); var createRoadObjectServiceModel = new CreateRoadObjectServiceModel(); var roadObjectName = " "; createRoadObjectServiceModel.Name = roadObjectName; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await roadObjectService.CreateAsync(createRoadObjectServiceModel); }); }
public async Task GetAllWithPaging_ShouldReturnCorrectResult(int?take, int skip) { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var countriesRepository = new EfDeletableEntityRepository <Country>(context); var countriesService = new CountriesService(countriesRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedCountriesAsync(context); var countries = await countriesService.GetAllWithPagingAsync <CountryServiceDetailsModel>(take, skip); var countriesCount = countries.ToList().Count; Assert.True(take == countriesCount, ErrorMessage); }
public async Task MostPurchased_ReturnsCorrectly() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var orderProductsRepository = new EfDeletableEntityRepository <OrderProduct>(context); var orderProductsService = this.GetOrderProductService(orderProductsRepository, context); var orderTestSeeder = new OrderTestSeeder(); var orderProductsTestSeeder = new OrderProductsTestSeeder(); await orderTestSeeder.SeedOrdersForMostPurchased(context); var products = await orderProductsService.MostPurchased <ProductSingleViewModel>(); Assert.Equal(5, products.Count()); }
public async Task GetAllUserOrders_WithUserWithNoOrders_ShouldReturnAnEmptyCollection() { string onNonEmptyCollectionErrorMessage = "The method did not return an empty collection with no user orders."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var orderService = new OrderService(context); // Seeding only one user with no orders var userId = await this.SeedSingleUser(context); var methodResult = await orderService.GetAllUserOrders(userId); AssertExtensions.EmptyWithMessage(methodResult, onNonEmptyCollectionErrorMessage); }
public async Task CreateAsyncAddsEntity() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryProjectsRepository = new EfRepository <CategoryProject>(dbContext); var service = new CategoryProjectsService(categoryProjectsRepository); var categoriesIds = new List <int> { 4, 6 }; await service.CreateAsync(1, categoriesIds); Assert.Equal(2, categoryProjectsRepository.All().Count()); }
public void GetHospitalsBloodBagsByHospitalIdShouldThrowExceptionTest() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); var bloodBankRepository = new EfDeletableEntityRepository <BloodBank>(dbContext); var bagRepository = new EfDeletableEntityRepository <BloodBag>(dbContext); var hospitalDataRepository = new EfDeletableEntityRepository <HospitalData>(dbContext); var service = new BloodBanksService( bloodBankRepository, bagRepository, hospitalDataRepository); Assert.Throws <ArgumentException>(() => service.GetHospitalBloodBagsById("123")); }
public async Task HospitalsInCity_ShouldReturnCorectData() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var seeder = new Seeder(); await seeder.SeedHospitals(context); var hospitalService = new HospitalService(context); var actualResult = hospitalService.HospitalsInCity(1).Result; var expectedResult = context.Hospitals.Where(x => x.CityId == 1); Assert.NotNull(actualResult); Assert.IsAssignableFrom <IEnumerable <HospitalServiceModel> >(actualResult); Assert.True(actualResult.Count() == expectedResult.Count()); }
public async Task GetByIdAsync_ShouldSuccessfullyGet() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var truckService = new TruckService(context); await truckService.GetByIdAsync(1); var expectedResult = "TRN 1"; var actualResult = await truckService.GetByIdAsync(1); Assert.True(expectedResult == actualResult.RegistrationNumber); }
public async Task RemoveAllCartProducts_WithInvalidUser_ShouldReturnFalse() { string onTrueErrorMessage = "The method returned true with invalid user Id."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var productService = new Mock <IProductService>(); var shoppingCartService = new ShoppingCartService(context, productService.Object); // Seeding only User var userId = "FakeUserId"; var methodResult = await shoppingCartService.RemoveAllCartProducts(userId); Assert.False(methodResult, onTrueErrorMessage); }
public async Task GetCartProductsByUserId_WithInvalidUser_ShouldReturnAnEmptyCollection() { string onNonEmptyCollectionErrorMessage = "The method did not return an empty collection upon invalid user."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var productService = new Mock <IProductService>(); var shoppingCartService = new ShoppingCartService(context, productService.Object); // Seeding only User var userId = "FakeUserId"; var methodResult = await shoppingCartService.GetCartProductsByUserId(userId); AssertExtensions.EmptyWithMessage(methodResult, onNonEmptyCollectionErrorMessage); }
public async Task AddProductsToOrder_WithNonExistingOrderAndGivenProducts_ShouldReturnFalse() { string onTrueErrorMessage = "The method returned true upon invalid orderId."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var orderService = new OrderService(context); var products = await this.GetProductsForOrder(); var orderId = "FakeOrderId"; var methodResult = await orderService.AddProductsToOrder(orderId, products); Assert.False(methodResult, onTrueErrorMessage); }
public async Task GetDonorsPatientsByDonorsUserIdAsync_WithIncorectUserId_ShouldThrowException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var seeder = new Seeder(); await seeder.SeedDonorsPatientsAsync(context); var userManager = this.GetUserManagerMock(context); var patientService = new PatientService(context, userManager.Object); var donorsPatientsService = new DonorsPatientsService(context, patientService, userManager.Object); await Assert.ThrowsAsync <NullReferenceException>(async() => { await donorsPatientsService.GetDonorsPatientsByDonorsUserIdAsync("invalidId"); }); }