public object GetService(Type serviceType) { if (serviceType == typeof(UsersController)) { var context = new BlogSystemContext(); var repository = new EfRepository<User>(context); return new UsersController(repository); } else if (serviceType == typeof(PostsController)) { var context = new BlogSystemContext(); var postsRepository = new EfRepository<Post>(context); var usersRepository = new EfRepository<User>(context); var tagsRepository = new EfRepository<Tag>(context); var commentsRepository = new EfRepository<Comment>(context); return new PostsController(postsRepository, usersRepository, tagsRepository, commentsRepository); } else if (serviceType == typeof(TagsController)) { var context = new BlogSystemContext(); var tagsRepository = new EfRepository<Tag>(context); var usersRepository = new EfRepository<User>(context); var postsRepository = new EfRepository<Post>(context); return new TagsController(tagsRepository, usersRepository, postsRepository); } else { return null; } }
public void RepositoryFindOne() { IRepository<Course> courseRepository = new EfRepository<Course>(_contextManager); courseRepository.AddNew(new Course() { Title = "Test course", Price = 900 }); var course = courseRepository.FindOne(1); Assert.IsNotNull(course); }
public void RepositoryQuery() { IRepository<Course> courseRepository = new EfRepository<Course>(_contextManager); courseRepository.AddNew(new Course() { Title = "Test course", Price = 900 }); courseRepository.AddNew(new Course() { Title = "Test course 2", Price = 1158.56M }); var courses = courseRepository.Find(c => c.Price > 1000).ToList(); Assert.AreEqual(1, courses.Count); }
public UnitOfWork() { categoryRepository = new EfRepository<Category>(context); commentRepository = new EfRepository<Comment>(context); postRepository = new EfRepository<Post>(context); threadRepository = new EfRepository<Thread>(context); userRepository = new EfRepository<User>(context); voteRepository = new EfRepository<Vote>(context); }
public void MoveAll() { IRepository<SqlVendor> repo = new EfRepository<SqlVendor>(); repo.Add(new SqlVendor() { Name = "Corsair" }); repo.SaveChanges(); }
public RSSFeedTests() { RSSFeedRepository = new EfRepository<RSSFeed>(); UserProfileRepository = new EfRepository<UserProfile>(); var fakeControllerContext = new Mock<ControllerContext>(); fakeControllerContext.Setup(t => t.HttpContext.User.Identity.Name).Returns("TestUser"); FakeControllerContext = fakeControllerContext.Object; RSSFeedPage = new RssFeedController(UserProfileRepository, RSSFeedRepository) { ControllerContext = FakeControllerContext }; }
public static void DeleteChilds(this IRepository<Student> sc, int studentId) { Student student = sc.All().Where(x => x.StudentId == studentId).FirstOrDefault(); var marksRepository = new EfRepository<Mark>(new SchoolContext()); if (student != null) { foreach (Mark mark in student.Marks) { marksRepository.Delete(mark.MarkId); } } }
public object GetService(Type serviceType) { var dbContext = new ForumDbContext(); if (serviceType == typeof(UsersController)) { var repository = new EfRepository<User>(dbContext); var userController = new UsersController(repository); return userController; } else if (serviceType == typeof(ThreadsController)) { var categoryRepository = new EfRepository<Category>(dbContext); var threadRepository = new EfRepository<Thread>(dbContext); var userRepository = new EfRepository<User>(dbContext); var threadController = new ThreadsController( categoryRepository, threadRepository, userRepository); return threadController; } else if (serviceType == typeof(PostsController)) { var postRepository = new EfRepository<Post>(dbContext); var userRepository = new EfRepository<User>(dbContext); var threadRepository = new EfRepository<Thread>(dbContext); var voteRepository = new EfRepository<Vote>(dbContext); var commentRepository = new EfRepository<Comment>(dbContext); var postsController = new PostsController( postRepository, userRepository, threadRepository, voteRepository, commentRepository); return postsController; } else if (serviceType == typeof(CategoriesController)) { var categoryRepository = new EfRepository<Category>(dbContext); var userRepository = new EfRepository<User>(dbContext); var threadRepository = new EfRepository<Thread>(dbContext); var categoriesController = new CategoriesController(categoryRepository, userRepository, threadRepository); return categoriesController; } else { return null; } }
public void InitTest() { xmlServiceMock = new Mock<IXmlService>(); webClientServiceMock = new Mock<IWebClientService>(); openWeatherServiceMock = new Mock<IOpenWeatherService>(); xmlService = new XmlService(); webClientService = new WebClientService(); openWeatherService = new OpenWeatherService(); IDbContext dbContext = new MeteoContext(); IRepository<Location> locationRepository = new EfRepository<Location>(dbContext); IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(dbContext); meteoService = new MeteoService(locationRepository, weatherForecastRepository); }
public static void DeleteChilds(this IRepository<School> sc, int schoolId) { var studentsRepo = new EfRepository<Student>(new SchoolContext()); var studentsFromSchool = studentsRepo.All().Where(x => x.School.SchoolId == schoolId).ToList(); foreach (Student student in studentsFromSchool) { studentsRepo.DeleteChilds(student.School.SchoolId); studentsRepo.Delete(student.StudentId); } }
public void Constructor_ShouldReturnObject() { // Arrange var context = new MsSqlDbContext(); var saveContext = new SaveContext(context); var repo = new EfRepository <Post>(context); var postService = new DataService <Post>(repo, saveContext); var mapper = AutoMapperConfig.Configuration.CreateMapper(); // Act var controller = new HomeController(postService, mapper); // Assert Assert.IsInstanceOf <HomeController>(controller); }
public async Task AddGenreAsyncWithCorrectDataShouldReturnCorrectResult() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var genresRepository = new EfDeletableEntityRepository <Genre>(dbContext); var groupGenresRepository = new EfRepository <GroupGenre>(dbContext); var genresService = new GenresService(groupGenresRepository, genresRepository); var actual = await genresService.AddGenreAsync(5, 1); var expected = 5; Assert.Equal(expected, actual); }
public void ReturnEntitiesOfGivenSet() { // Arrange var mockedDbContext = new Mock <MsSqlDbContext>(); var mockedSet = new Mock <DbSet <Book> >(); // Act mockedDbContext.Setup(x => x.Set <Book>()).Returns(mockedSet.Object); var mockedDbSet = new EfRepository <Book>(mockedDbContext.Object); // Assert //Assert.NotNull(mockedDbSet.All()); //Assert.IsInstanceOf(typeof(DbSet<Book>), mockedDbSet.All()); //Assert.AreSame(mockedDbSet.All(), mockedDbSet.DbSet); }
// if you want to use DATABASE USE it with this.db public string Get() { IRepository <Crafter> craftersRepo = new EfRepository <Crafter>(); var crafters = craftersRepo.All().ToList(); string getCrafter = ""; int i = 0; foreach (var crafter in crafters) { i++; getCrafter += i + " Crafter Name : " + crafter.CharacterName + " /*---*******---*/ "; } return(getCrafter); }
protected override LinieComanda CreateObject() { //check if ok? var comanda = new EfRepository <Comanda>(session).GetById(1); var produs = new EfRepository <Produs>(session).GetById(1); return(new LinieComanda { Comanda = comanda, Produs = produs, Cantitate = 99, ComandaId = 1, ProdusId = 1, }); }
public async Task CheckIfWhenUserLikesABeatItReturnsTrue() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("BeatsWaveVirtual"); var likeRepository = new EfRepository <Like>(new ApplicationDbContext(options.Options)); var beatRepository = new EfDeletableEntityRepository <Beat>(new ApplicationDbContext(options.Options)); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options)); var service = new LikeService(likeRepository, beatRepository, userRepository); await service.VoteAsync(1, "1"); var result = service.IsLikedByCurrentUser("1", 1); Assert.True(result); }
public async Task Can_get_by_id_products() { using var context = new AppDbContext(this.ContextOptions); var repository = new EfRepository(context); var controller = new Get(repository); var product = await controller.HandleAsncy(1); Assert.Equal("Teste 1", product.Description); Assert.Equal("http://teste.image.com/1", product.Image); var productTwo = await controller.HandleAsncy(2); Assert.Equal("Teste 2", productTwo.Description); Assert.Equal("http://teste.image.com/2", productTwo.Image); }
public void GetLakeAverageVoteShouldReturnIfLakeVotesIsNull() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var db = new ApplicationDbContext(options); var lakeRepository = new EfDeletableEntityRepository <Lake>(db); var lakeVoteRepository = new EfRepository <LakeVote>(db); var trophyVoteRepository = new EfRepository <TrophyVote>(db); var votesRepository = new EfRepository <Vote>(db); var service = new VotesService(lakeVoteRepository, trophyVoteRepository, votesRepository); Assert.Equal(0, service.GetLakeAverageVote(1)); }
public void EfRepo_Should_Call_GetDbSet() { //Arrange & Act FakeClass fake = new FakeClass(); var mockedDbSet = new Mock <IDbSet <FakeClass> >(); mockedDbSet.Setup(x => x.Add(fake)).Verifiable(); var mockedDbContext = new Mock <IEfSociumDbContext>(); mockedDbContext.Setup(c => c.GetDbSet <FakeClass>()).Returns(mockedDbSet.Object); EfRepository <FakeClass> repo = new EfRepository <FakeClass>(mockedDbContext.Object); //Assert mockedDbContext.Verify(c => c.GetDbSet <FakeClass>(), Times.Once); }
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()); }
// if you want to use DATABASE USE it with this.db public string Get() { IRepository <Gatherer> gatherersRepo = new EfRepository <Gatherer>(); var gatherers = gatherersRepo.All().ToList(); string getGatherer = ""; int i = 0; foreach (var gatherer in gatherers) { i++; getGatherer += i + " Gatherer Name : " + gatherer.CharacterName + " /*---*******---*/ "; } return(getGatherer); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Metric.Config.WithHttpEndpoint("http://localhost:1234/").WithAllCounters(); AllocConsole(); using (MobileManagementContext db = new MobileManagementContext()) { IRepository repository = new EfRepository(db); Application.Run(new MainForm(repository)); } }
public async Task GradeEssayAsyncTest() { var context = EssayCompetitionContextInMemoryFactory.InitializeContext(); var essay = await this.seeder.SeedEssayAsync(context); var essayRepository = new EfDeletableEntityRepository <Essay>(context); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var gradeRepository = new EfRepository <Grade>(context); var essayTeacherRepository = new EfDeletableEntityRepository <EssayTeacher>(context); var service = new TeacherService(essayRepository, categoryRepository, gradeRepository, essayTeacherRepository); await service.GradeEssayAsync("stava", 12, essay.Id); Assert.True(context.Grades.First(x => x.EssayId == essay.Id).Points == 12, "GradeEssayAsync method does not work correctly"); }
public void CanUpdateADealer() { string updatedDealerName = "Dealer 1 Updated"; using (var context = new DatabaseContext(_options)) { var repository = new EfRepository <Dealer>(context); var dealer1 = repository.Find(d => d.Name == "Dealer 1").First(); dealer1.Name = updatedDealerName; repository.Update(dealer1); var updatedDealer = repository.Find(d => d.Name == updatedDealerName).First(); Assert.AreEqual(updatedDealerName, updatedDealer.Name); repository.Dispose(); } }
public ProfilesServiceTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; var db = new ApplicationDbContext(options); this.userRepo = new EfDeletableEntityRepository <ApplicationUser>(db); var userFollow = new EfRepository <UserFollow>(db); var followRepo = new FollowService(userFollow, this.userRepo); this.service = new ProfileService(this.userRepo, followRepo); var map = new MapperInitializationProfile(); }
public void Delete_With_Cache_And_Ef() { var cachingStrategy = new StandardCachingStrategy<Contact, string>(); var dbPath = EfDataDirectoryFactory.Build(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); var repository = new EfRepository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath), cachingStrategy); repository.Add(new Contact() { ContactId = "1", Name = "Contact1"}); repository = new EfRepository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath), cachingStrategy); repository.Get("1"); repository.CacheUsed.ShouldBeTrue(); repository.Delete("1"); }
public async Task GetEssayInfoTest() { var context = EssayCompetitionContextInMemoryFactory.InitializeContext(); var essay = await this.seeder.SeedEssayAsync(context); var essayRepository = new EfDeletableEntityRepository <Essay>(context); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var gradeRepository = new EfRepository <Grade>(context); var essayTeacherRepository = new EfDeletableEntityRepository <EssayTeacher>(context); var service = new TeacherService(essayRepository, categoryRepository, gradeRepository, essayTeacherRepository); var result = service.HasEssayWithId(essay.Id); Assert.True(result, "GetEssayInfo method does not work correctly"); }
public void TestUpdate_ShouldCallDbContextSetUpdated() { // Arrange var mockedDbContext = new Mock <IDbContext>(); var repository = new EfRepository <FakeRepositoryType>(mockedDbContext.Object); var entity = new Mock <FakeRepositoryType>(); // Act repository.Update(entity.Object); // Assert mockedDbContext.Verify(c => c.SetUpdated(entity.Object), Times.Once); }
public static async Task <Booking> GetBookingIfHasMinPermissionOf(this ClaimsPrincipal claimsPrincipal, EfRepository repository, long bookingId, Permission minPermission) { return(claimsPrincipal.IsAdmin() ? await repository.FindByIdAsync <Booking>(bookingId) : await repository.Query <Booking>() .Where(booking => booking.Id == bookingId && (booking.BookedBy.Id == claimsPrincipal.GetUserId() || booking.Meeting.Firm.FirmUsers.Any(firmUser => firmUser.UserId == claimsPrincipal.GetUserId() && firmUser.Permission >= minPermission ))) .FirstOrDefaultAsync()); }
// if you want to use DATABASE USE it with this.db public IHttpActionResult Get() { IRepository <Hero> heroesRepo = new EfRepository <Hero>(); var heroes = heroesRepo.All().ToList(); string getHero = ""; int i = 0; foreach (var hero in heroes) { i++; getHero += i + " Hero Name : " + hero.CharacterName + " /*---*******---*/ "; } return(Ok(getHero)); }
public void ThrowNullReferenceException_WhenPassedArgumentIsNull() { // Arrange var mockedDbContext = new Mock <MsSqlDbContext>(); var mockedSet = new Mock <DbSet <Book> >(); // Act mockedDbContext.Setup(set => set.Set <Book>()).Returns(mockedSet.Object); var mockedDbSet = new EfRepository <Book>(mockedDbContext.Object); Book entity = null; // Assert Assert.That(() => mockedDbSet.Add(entity), Throws.InstanceOf <ArgumentNullException>()); }
public void ThrowArgumenNulltException_WhenArgumentIsNull() { //Arrange var mockedDbContext = new Mock <MsSqlDbContext>(); var mockedModel = new Mock <DbSet <Category> >(); var mockedCategory = new Mock <Category>(); //Act mockedDbContext.Setup(x => x.Set <Category>()).Returns(mockedModel.Object); var mockedDbSet = new EfRepository <Category>(mockedDbContext.Object); Category entity = null; //Assert Assert.Throws <ArgumentNullException>(() => mockedDbSet.Update(entity)); }
public async Task CheckGettingProcedureReviewsAsync() { ApplicationDbContext db = GetDb(); var repository = new EfDeletableEntityRepository <Procedure>(db); var procedureReviewsRepository = new EfRepository <Review>(db); var service = new ProceduresService( repository, procedureReviewsRepository, this.procedureProductsRepository.Object, this.procedureStylistsRepository.Object, this.skinProblemProceduresRepository.Object, this.appointmentsRepository.Object, this.categoriesService.Object); var procedure = new Procedure() { Id = "1" }; var firstReview = new Review() { Id = "1", ProcedureId = procedure.Id }; var secondReview = new Review() { Id = "2", ProcedureId = procedure.Id }; var thirdReview = new Review() { Id = "3" }; await db.Procedures.AddAsync(procedure); await db.Reviews.AddAsync(firstReview); await db.Reviews.AddAsync(secondReview); await db.Reviews.AddAsync(thirdReview); await db.SaveChangesAsync(); var procedures = await service.GetProcedureReviewsAsync <TestReviewModel>(procedure.Id); Assert.Equal(2, procedures.Count()); }
public async Task Should_List_Using_Filter() { // Arrange var options = new DbContextOptionsBuilder <ProductContext>() .UseInMemoryDatabase(databaseName: "Should_List_Using_Filter") .Options; var productEntities = new List <Product>(); var productA = new Product { Id = Guid.NewGuid(), Name = "Product1", Description = "Prod 1", Price = 10, DeliveryPrice = 5 }; productEntities.Add(productA); productEntities.Add(new Product { Id = Guid.NewGuid(), Name = "Product2", Description = "Prod 2", Price = 20, DeliveryPrice = 10 }); // Insert seed data into the database using one instance of the context using (var context = new ProductContext(options)) { context.Product.AddRange(productEntities); await context.SaveChangesAsync(); } // Use a clean instance of the context to run the test using (var context = new ProductContext(options)) { // Act var efRepo = new EfRepository <Product>(context); var filteredProducts = await efRepo.ListAsync(p => p.Name == productA.Name); // Assert Assert.NotNull(filteredProducts); Assert.True(filteredProducts.Count == 1); Assert.Collection <Product>(filteredProducts, item => Assert.Contains("Product1", item.Name)); } }
public async Task TestCreateAsyncMethodCorect() { ApplicationUser user = new ApplicationUser(); Category category = new Category(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Job>(new ApplicationDbContext(options.Options)); var studentRepo = new EfRepository <StudentJob>(new ApplicationDbContext(options.Options)); var jobService = new JobsService(repository, studentRepo); await jobService.CreateJob(user.Id, "test", "test", "test", category.Id, "Junior", "Pleven", 8000, "FullTime"); AutoMapperConfig.RegisterMappings(typeof(JobServicesTests.MyTestJob).Assembly); Assert.Equal(1, repository.All().Count()); }
public void ReturnDbSet() { // Arrange var mockedContext = new Mock <IBetterReadsDbContext>(); var mockedSet = new Mock <IDbSet <MockedModel> >(); mockedContext.Setup(x => x.Set <MockedModel>()).Returns(mockedSet.Object); var repository = new EfRepository <MockedModel>(mockedContext.Object); // Act var result = repository.All; // Assert Assert.AreEqual(mockedSet.Object, result); }
public async Task UpdateReadStatusAsync_WithNoNewNotifications_ShouldReturnMessage() { // Arrange var context = InMemoryDbContext.Initiliaze(); var notificationsRepository = new EfRepository <Notification>(context); var service = new NotificationsService(notificationsRepository); await this.SeedUsersAndPost(context); // Act string expectedResult = "There are no new notifications"; string actualResult = await service.UpdateReadStatusAsync("userId"); // Assert Assert.Equal(expectedResult, actualResult); }
static void Main(string[] args) { IDbContext context = new MeteoContext(); IRepository<Location> locationRepository = new EfRepository<Location>(context); IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(context); IMeteoService meteoService = new MeteoService(locationRepository, weatherForecastRepository); //Weather prognoza = meteoService.GetWeather("Bydgoszcz", "205-07-12"); //Console.WriteLine(prognoza); IXmlService xmlService = new XmlService(); List<string> cities = meteoService.GetCities("cities.xml", xmlService); foreach (var city in cities) { Console.WriteLine(city); } Console.ReadLine(); }
public async Task Can_delete_a_product_before_get_by_id() { using var context = new AppDbContext(this.ContextOptions); var repository = new EfRepository(context); var controllerGet = new Get(repository); var productByGet = await controllerGet.HandleAsncy(1); Assert.NotNull(productByGet); var deleteController = new Delete(repository); await deleteController.HandleAsync(productByGet.Id); var response = await controllerGet.HandleAsncy(productByGet.Id); Assert.Null(response); }
public async Task UserExistsByNameAsync_WithValidUserName_ShouldReturnTrue() { // Arrange var context = InMemoryDbContext.Initiliaze(); var userRepository = new EfDeletableEntityRepository <ApplicationUser>(context); var userFollowerRepository = new EfRepository <UserFollower>(context); var profileService = new ProfilesService(userRepository, userFollowerRepository); await this.SeedUsers(context); // Act bool result = await profileService.UserExistsByNameAsync("userOneUsername"); // Assert Assert.True(result); }
public async Task IsAdminAsync_WithValidUserId_ShouldReturnTrue() { // Arrange var context = InMemoryDbContext.Initiliaze(); var usersRepository = new EfRepository <ApplicationUser>(context); var rolesRepository = new EfRepository <ApplicationRole>(context); var service = new AdminService(usersRepository, rolesRepository); await this.SeedUsersAndRoles(context); // Act bool isAdmin = await service.IsAdminAsync("userOneId"); // Assert Assert.True(isAdmin); }
public OrdersServiceTests() { var options = new DbContextOptionsBuilder <PizzaLabDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new PizzaLabDbContext(options); var mapperProfile = new MappingConfiguration(); var conf = new MapperConfiguration(cfg => cfg.AddProfile(mapperProfile)); var mapper = new Mapper(conf); this._ordersRepository = new EfRepository <Order>(dbContext); var orderProductRepository = new EfRepository <OrderProduct>(dbContext); this._ordersService = new OrdersService(_ordersRepository, orderProductRepository, mapper); }
public void Delete_Loop_With_Cache_And_Ef() { var cachingStrategy = new StandardCachingStrategy<Contact, string>(); var dbPath = EfDataDirectoryFactory.Build(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); var repository = new EfRepository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath), cachingStrategy); repository.Add(new Contact() { ContactId = "1", Name = "Contact1", ContactTypeId = 1}); repository.Add(new Contact() { ContactId = "2", Name = "Contact2", ContactTypeId = 2}); repository.Add(new Contact() { ContactId = "3", Name = "Contact3", ContactTypeId = 2}); repository.FindAll(x => x.ContactTypeId == 2); repository = new EfRepository<Contact, string>(new TestObjectEntities("Data Source=" + dbPath), cachingStrategy); repository.Delete(x => x.ContactTypeId == 2); }
public void AddBugWhenBugIsValidShouldAddToDatabase() { // Arrange var bug = GetValidTestBug(); var databaseContext = new BugTrackerDbContext(); var repo = new EfRepository<Bug>(databaseContext) { bug }; // Act repo.SaveChanges(); var bugInDb = databaseContext.Bugs.Find(bug.Id); // Assert Assert.IsNotNull(bugInDb); Assert.AreEqual(bug.Text, bugInDb.Text); }
public void FindWhenObjectIsInDbShouldReturnObject() { // Arrange var bug = GetValidTestBug(); var databaseContext = new BugTrackerDbContext(); var repo = new EfRepository<Bug>(databaseContext); // Act databaseContext.Bugs.Add(bug); databaseContext.SaveChanges(); var bugInDb = repo.Find(bug.Id); // Assert Assert.IsNotNull(bugInDb); Assert.AreEqual(bug.Text, bugInDb.Text); }
public void CompoundKeyRepository_Should_Work() { var dbPath = EfDataDirectoryFactory.Build(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); ICompoundKeyRepository<User, string, int> repository = new EfRepository<User, string, int>(new TestObjectEntities("Data Source=" + dbPath)); repository.Add(new User { Username = "******", Age = 21, FullName = "Jeff - 21" }); repository.Add(new User { Username = "******", Age = 31, FullName = "Jeff - 31" }); repository.Add(new User { Username = "******", Age = 41, FullName = "Jeff - 41" }); repository.Add(new User { Username = "******", Age = 31, FullName = "Ben - 31" }); repository.Add(new User { Username = "******", Age = 41, FullName = "Ben - 41" }); repository.Add(new User { Username = "******", Age = 51, FullName = "Ben - 51" }); repository.Get("jeff", 31).FullName.ShouldEqual("Jeff - 31"); repository.Get("ben", 31).FullName.ShouldEqual("Ben - 31"); repository.Get("jeff", 41).FullName.ShouldEqual("Jeff - 41"); repository.FindAll(x => x.Age == 31).Count().ShouldEqual(2); }
public object GetService(Type serviceType) { if (serviceType == typeof(StudentsController)) { DbContext context = new StudentSystemContext(); var studentRepository = new EfRepository<Student>(context); var schoolRepository = new EfRepository<School>(context); var markRepository = new EfRepository<Mark>(context); return new StudentsController(studentRepository, schoolRepository, markRepository); } else if (serviceType == typeof(SchoolsController)) { DbContext context = new StudentSystemContext(); var schoolRepository = new EfRepository<School>(context); var studentRepository = new EfRepository<Student>(context); return new SchoolsController(schoolRepository, studentRepository); } else { return null; } }
private void GetMeteoInfo() { try { IXmlService xmlService = new XmlService(); WebClientService webClientService = new WebClientService(); OpenWeatherService openWeatherService = new OpenWeatherService(); IDbContext context = new MeteoContext(); IRepository<Location> locationRepository = new EfRepository<Location>(context); IRepository<WeatherForecast> weatherForecastRepository = new EfRepository<WeatherForecast>(context); IMeteoService meteoService = new MeteoService(locationRepository, weatherForecastRepository); List<string> cities = meteoService.GetCities(AppDomain.CurrentDomain.BaseDirectory + @"\cities.xml", xmlService); List<WeatherForecast> weatherList = meteoService.GetWeatherList(cities, 16, webClientService, xmlService, openWeatherService); meteoService.SaveWeatherList(weatherList); LogHelper.WriteToLog(logName, string.Format("forecast weather {0} saved", DateTime.Now)); } catch(Exception ex) { LogHelper.WriteToLog(logName, ex.Message); throw; } }
public SchoolsController(IRepository<School> schoolRepository, EfRepository<Student> studentRepository) { this.schoolRepository = schoolRepository; this.studentRepository = studentRepository; }
public void TestInit() { tran = new TransactionScope(); this.repo = new EfRepository<News>(new NewsContext()); }
public void RepositoryCreation() { IRepository<Course> courseRepository = new EfRepository<Course>(_contextManager); Assert.IsNotNull(courseRepository); }
public void RepositoryAddNew() { IRepository<Course> courseRepository = new EfRepository<Course>(_contextManager); courseRepository.AddNew(new Course() { Title = "Test course", Price = 900 }); Assert.AreEqual(1, courseRepository.Find().Count()); }