Esempio n. 1
0
        public void Write_user_via_scope_should_work()
        {
            // arrange
            var entity = new DummyEntity {
                Name = "Bob"
            };

            // act
            using (var scope = DbContextScopeFactory.Create())
            {
                var dbContext = scope.Get <DummyDbContext>();
                dbContext.Add(entity);

                scope.SaveChanges();
            }

            // assert
            using (var scope = DbContextScopeFactory.CreateReadOnly())
            {
                var dbContext = scope.Get <DummyDbContext>();

                var users = dbContext.DummyEntities.ToArray();
                Assert.AreEqual(1, users.Length);
            }
        }
Esempio n. 2
0
        public HomeController()
        {
            var dbContextScopeFactory     = new DbContextScopeFactory();
            var mockAppointmentRepository = new MockAppointmentRepository();

            this.appointmentSearchService = new AppointmentSearchService(dbContextScopeFactory, mockAppointmentRepository);
        }
Esempio n. 3
0
        public async Task Update_entity_should_call_refresh_entities_async_in_parent_scope()
        {
            // arrange
            var dummyEntity = new DummyEntity {
                Name = "Bob"
            };

            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                await dbContext.DummyEntities.AddAsync(dummyEntity);

                await dbContext.SaveChangesAsync();
            }
            CalledMethods.Clear();

            // act
            using (var dbContext = DbContextScopeFactory.Open <DummyDbContext>())
            {
                var savedDummyEntity = await dbContext.DummyEntities.FindAsync(dummyEntity.Id);

                savedDummyEntity.Name = "Alice";
                await dbContext.SaveChangesAsync();
            }

            // assert
            assertCallOrder("SaveChangesAsync", "RefreshEntitiesInParentScopeAsync-SKIP", "Dispose");
        }
Esempio n. 4
0
        public void Scope_and_open_and_save_on_open_context_should_make_entity_in_parent_visible()
        {
            // arrange
            var openEntity = new DummyEntity {
                Name = "Bob"
            };
            DummyEntity scopeEntity;

            /*
             * PROBLEM here:
             * - the inner dbContext is joining the outer dbContext
             * - the tracked dbContext in the outer/parent is not the proxy, thus, no updates were populated.
             * -> maybe the proxy-dbContexts may never "join" the parent scope?
             * -> maybe we should replace or stack the joined dbScopes?
             * --> who is disposing the inner-most dbContext then and how?
             */

            // act
            using (var scope = DbContextScopeFactory.Create())
            {
                var scopeDbContext = scope.Get <DummyDbContext>();

                using (var openDbContext = DbContextScopeFactory.Open <DummyDbContext>())
                {
                    openDbContext.Add(openEntity);
                    openDbContext.SaveChanges();
                }

                scopeEntity = scopeDbContext.Find <DummyEntity>(openEntity.Id);
            }

            // assert
            Assert.AreEqual(openEntity.Id, scopeEntity.Id);
        }
Esempio n. 5
0
        private async Task CreateRecurringPayments()
        {
            var settingsManager = new SettingsManager(new SettingsAdapter());

            try
            {
                Debug.WriteLine("RecurringPayment Job started.");
                ApplicationContext.DbPath = GetLocalFilePath();

                var ambientDbContextLocator = new AmbientDbContextLocator();
                var dbContextScopeFactory   = new DbContextScopeFactory();

                await new RecurringPaymentManager(
                    new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory),
                    new PaymentService(ambientDbContextLocator, dbContextScopeFactory))
                .CreatePaymentsUpToRecur();

                Debug.WriteLine("RecurringPayment Job finished.");
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            finally
            {
                settingsManager.LastExecutionTimeStampRecurringPayments = DateTime.Now;
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        public override async void Initialize()
        {
            var dbContextScopeFactory = new DbContextScopeFactory();
            var ambientDbContextLocator = new AmbientDbContextLocator();

            using (dbContextScopeFactory.Create())
            {
                await ambientDbContextLocator.Get<ApplicationContext>().Database.MigrateAsync();
            }

            if (Mvx.Resolve<Session>().ValidateSession())
            {
                if (CurrentPlatform == AppPlatform.UWP)
                {
                    RegisterAppStart<AccountListViewModel>();
                }
                else
                {
                    RegisterAppStart<MainViewModel>();
                }
            } else
            {
                RegisterAppStart<LoginViewModel>();
            }
        }
Esempio n. 7
0
        internal void DoTests()
        {
            var order = new Order {
                Name = "lama", Customer = new Customer {
                    Name = "heheszka"
                },
                Items = new List <OrderItem> {
                    new OrderItem {
                        Code = "Test", Value = 2
                    }
                }
            };
            var order2 = new Order {
                Name = "lama2", Customer = new Customer {
                    Name = "heheszka2"
                },
                Items = new List <OrderItem> {
                    new OrderItem {
                        Code = "Test", Value = 2
                    }
                }
            };

            using (var session = DbContextScopeFactory.Create())
            {
                OrderRepository.Add(order);
                OrderRepository.Add(order2, new HashSet <string> {
                    "Customer"
                });
                session.SaveChanges();
                var orders = OrderRepository.GetAll(new List <string> {
                    "Customer"
                });
            }
        }
Esempio n. 8
0
        private async Task CheckRecurringPayments(JobParameters args)
        {
            try
            {
                Debug.WriteLine("RecurringPayment Job started.");
                DataAccess.ApplicationContext.DbPath =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                 DatabaseConstants.DB_NAME);

                var ambientDbContextLocator = new AmbientDbContextLocator();
                var dbContextScopeFactory   = new DbContextScopeFactory();

                await new RecurringPaymentManager(
                    new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory),
                    new PaymentService(ambientDbContextLocator, dbContextScopeFactory))
                .CreatePaymentsUpToRecur();

                Debug.WriteLine("RecurringPayment Job finished.");
                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                Debug.Write(ex);
            }
        }
Esempio n. 9
0
        public async Task UpdateMovie_ShoulAddNewMovieActor_WhenOtherExistsPreviously()
        {
            var movieUnderTest          = TestMovieSeededWithRelatedInfo;
            var secondRelationUnderTest = new MovieActor
            {
                Movie       = movieUnderTest,
                MovieId     = movieUnderTest.Id,
                Person      = TestActorNotSeeded,
                PersonId    = TestActorNotSeeded.Id,
                AsCharacter = "Paco"
            };

            using var context = DbContextScopeFactory.Create();

            movieUnderTest.ActorList.Add(secondRelationUnderTest);
            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();

            var existingFirstRelation  = MoviesContext.MovieActors.Find(movieUnderTest.Id, TestActorSeeded.Id);
            var existingSecondRelation = MoviesContext.MovieActors.Find(movieUnderTest.Id, TestActorNotSeeded.Id);
            var existingSecondPerson   = MoviesContext.People.Find(TestActorNotSeeded.Id);
            var existingMovie          = MoviesContext.Movies.Find(movieUnderTest.Id);

            existingFirstRelation.Should().BeEquivalentTo(TestMovieActorSeeded);
            existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest);
            existingSecondPerson.Should().Be(TestActorNotSeeded);
            existingMovie.Should().Be(movieUnderTest);
        }
Esempio n. 10
0
        public void TestDbContextScopeWorks()
        {
            using var context = DbContextScopeFactory.CreateReadOnly();
            var moviesContext = AmbientDbContextLocator.Get <MoviesContext>();

            Assert.IsNotNull(moviesContext.Movies.Find(TestMovieSeededWithoutRelatedInfo.Id));
        }
Esempio n. 11
0
        public async Task UpdateMovie_ShouldAddRatingSourceAndRating_WhenRatingSourceNotExists()
        {
            using var context = DbContextScopeFactory.Create();
            var movieUnderTest  = TestMovieSeededWithoutRelatedInfo;
            var newRatingSource = fixture.Build <RatingSource>()
                                  .With(x => x.Ratings, new List <Rating>())
                                  .Create();
            var relationUnderTest = new Rating
            {
                Movie    = movieUnderTest,
                MovieId  = movieUnderTest.Id,
                Source   = newRatingSource,
                SourceId = newRatingSource.Id
            };

            movieUnderTest.Ratings.Add(relationUnderTest);

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();
            var existingMovie        = MoviesContext.Movies.Find(movieUnderTest.Id);
            var existingRelation     = MoviesContext.Ratings.Find(movieUnderTest.Id, newRatingSource.Id);
            var existingRatingSource = MoviesContext.RatingSources.Find(newRatingSource.Id);

            existingMovie.Should().Be(movieUnderTest);
            existingRelation.Should().BeEquivalentTo(relationUnderTest);
            existingRatingSource.Should().Be(newRatingSource);
        }
Esempio n. 12
0
        public async Task UpdateMovie_ShouldThrowException_WhenMovieNotExists()
        {
            using var context = DbContextScopeFactory.Create();
            var newMovie = TestMovieNotSeeded;

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(newMovie));
        }
Esempio n. 13
0
        public async Task UpdateMovie_ShoulAddSecondMovieCompany_WhenOtherExistsPreviously()
        {
            var movieUnderTest          = TestMovieSeededWithRelatedInfo;
            var secondRelationUnderTest = new MovieCompany
            {
                Movie     = movieUnderTest,
                MovieId   = movieUnderTest.Id,
                Company   = TestCompanyNotSeeded,
                CompanyId = TestCompanyNotSeeded.Id
            };

            using var context = DbContextScopeFactory.Create();
            movieUnderTest.CompanyList.Add(secondRelationUnderTest);
            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();

            var existingFirstRelation  = MoviesContext.MovieCompanies.Include(x => x.Company).Single(x => x.MovieId == movieUnderTest.Id && x.CompanyId == TestCompanySeeded.Id);
            var existingSecondRelation = MoviesContext.MovieCompanies.Find(movieUnderTest.Id, TestCompanyNotSeeded.Id);
            var existingSecondCompany  = MoviesContext.Companies.Find(TestCompanyNotSeeded.Id);
            var existingMovie          = MoviesContext.Movies.Find(movieUnderTest.Id);

            existingFirstRelation.Should().BeEquivalentTo(TestMovieCompanySeeded);
            existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest);
            existingSecondCompany.Should().Be(TestCompanyNotSeeded);
            existingMovie.Should().Be(movieUnderTest);
        }
Esempio n. 14
0
        public async Task UpdateMovie_ShoulAddSecondMovieSimilar_WhenOtherExistsPreviously()
        {
            var movieUnderTest          = TestMovieSeededWithRelatedInfo;
            var secondRelationUnderTest = new MovieSimilar
            {
                Movie     = movieUnderTest,
                MovieId   = movieUnderTest.Id,
                Similar   = TestMovieNotSeeded,
                SimilarId = TestMovieNotSeeded.Id
            };

            using var context = DbContextScopeFactory.Create();
            movieUnderTest.Similars.Add(secondRelationUnderTest);
            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();

            var existingFirstRelation  = MoviesContext.MovieSimilars.Find(movieUnderTest.Id, TestMovieSeededWithoutRelatedInfo.Id);
            var existingSecondRelation = MoviesContext.MovieSimilars.Find(movieUnderTest.Id, TestMovieNotSeeded.Id);
            var existingSecondSimilar  = MoviesContext.Movies.Find(TestMovieNotSeeded.Id);
            var existingMovie          = MoviesContext.Movies.Find(movieUnderTest.Id);

            existingFirstRelation.Should().BeEquivalentTo(TestMovieSimilarSeeded);
            existingSecondRelation.Should().BeEquivalentTo(secondRelationUnderTest);
            existingSecondSimilar.Should().Be(TestMovieNotSeeded);
            existingMovie.Should().Be(movieUnderTest);
        }
Esempio n. 15
0
        public async Task UpdateMovie_ShouldAddWriterAndMovieWriter_WhenWriterNotExists()
        {
            using var context = DbContextScopeFactory.Create();
            var movieUnderTest    = TestMovieSeededWithoutRelatedInfo;
            var relationUnderTest = new MovieWriter
            {
                Movie    = movieUnderTest,
                MovieId  = movieUnderTest.Id,
                Person   = TestWriterNotSeeded,
                PersonId = TestWriterNotSeeded.Id
            };

            movieUnderTest.WriterList.Add(relationUnderTest);

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();
            var existingMovie    = MoviesContext.Movies.Find(movieUnderTest.Id);
            var existingRelation = MoviesContext.MovieWriters.Find(movieUnderTest.Id, TestWriterNotSeeded.Id);
            var existingWriter   = MoviesContext.People.Find(TestWriterNotSeeded.Id);

            existingMovie.Should().Be(movieUnderTest);
            existingRelation.Should().BeEquivalentTo(relationUnderTest);
            existingWriter.Should().Be(TestWriterNotSeeded);
        }
Esempio n. 16
0
        public async Task UpdateMovie_ShouldAddCompanyAndMovieCompany_WhenCompanyNotExists()
        {
            using var context = DbContextScopeFactory.Create();
            var movieUnderTest    = TestMovieSeededWithoutRelatedInfo;
            var relationUnderTest = new MovieCompany
            {
                Movie     = movieUnderTest,
                MovieId   = movieUnderTest.Id,
                Company   = TestCompanyNotSeeded,
                CompanyId = TestCompanyNotSeeded.Id
            };

            movieUnderTest.CompanyList.Add(relationUnderTest);

            await MovieDetailsDbAccess.UpdateMovie(Mapper.Map <UpdateMovieDetailsDto>(movieUnderTest));

            context.SaveChanges();
            var existingMovie    = MoviesContext.Movies.Find(movieUnderTest.Id);
            var existingRelation = MoviesContext.MovieCompanies.Find(movieUnderTest.Id, TestCompanyNotSeeded.Id);
            var existingCompany  = MoviesContext.Companies.Find(TestCompanyNotSeeded.Id);

            existingMovie.Should().Be(movieUnderTest);
            existingRelation.Should().BeEquivalentTo(relationUnderTest);
            existingCompany.Should().Be(TestCompanyNotSeeded);
        }
Esempio n. 17
0
        public async Task GetAllMovies_ShouldGetAllMovies()
        {
            using var context = DbContextScopeFactory.CreateReadOnly();
            var movies = await MovieListsDbAccess.GetMoviesFromLocal();

            movies.Should().BeEquivalentTo(InitialMovieListItemDtos);
        }
Esempio n. 18
0
        public void Add_100_OrderItem()
        {
            var dbContextScopeFactory   = new DbContextScopeFactory();
            var ambientDbContextLocator = new AmbientDbContextLocator();

            var orderFactory = new OrderFactory();

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                var personRepository = new PersonRepository(ambientDbContextLocator);
                var orderRepository  = new OrderRepository(ambientDbContextLocator);

                var person = personRepository.GetByName("ding.p");
                var order  = orderFactory.CreateOrder(person);
                orderRepository.Add(order);

                for (int i = 0; i < 100; i++)
                {
                    var orderItem = order.CreateItem("A-" + i);

                    order.OrderLine.Add(orderItem);
                }

                dbContextScope.SaveChanges();
            }
        }
Esempio n. 19
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine("RecurringPaymentTask started.");

            ApplicationContext.DbPath = DatabaseConstants.DB_NAME;

            try
            {
                var dbContextScopeFactory   = new DbContextScopeFactory();
                var ambientDbContextLocator = new AmbientDbContextLocator();

                await new RecurringPaymentManager(
                    new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory),
                    new PaymentService(ambientDbContextLocator, dbContextScopeFactory))
                .CreatePaymentsUpToRecur();
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
                Debug.WriteLine("RecurringPaymentTask stopped due to an error.");
            }
            finally
            {
                Debug.WriteLine("RecurringPaymentTask finished.");
                deferral.Complete();
            }
        }
 public StepDefinition[] GetStepDefinitions()
 {
     using (DbContextScopeFactory.CreateReadOnly())
     {
         return(_stepDefinitionRepository.GetAll().ToArray());
     }
 }
 public void DeleteRole(string roleId)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _roleRepository.Delete(r => r.Id == roleId);
         dbContextScope.SaveChanges();
     }
 }
 public void DeleteStep(Guid id)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _programStepRepositor.Delete(p => p.Id == id);
         dbContextScope.SaveChanges();
     }
 }
Esempio n. 23
0
 public void DeleteUser(string userId)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _userRepository.Delete(u => u.Id == userId);
         dbContextScope.SaveChanges();
     }
 }
 public void DeleteJointPoint(Guid id)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _jointPointRepository.Delete(p => p.Id == id);
         dbContextScope.SaveChanges();
     }
 }
 public void UpdateJointPoint(JointPoint point)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _jointPointRepository.Update(point);
         dbContextScope.SaveChanges();
     }
 }
 public void UpdateCartesianPoint(CartesianPoint point)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _cartesianPointRepository.Update(point);
         dbContextScope.SaveChanges();
     }
 }
 public void DeleteProgram(Guid id)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _robotProgramRepository.Delete(p => p.Id == id);
         dbContextScope.SaveChanges();
     }
 }
 public void UpdateStep(ProgramStep step)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _programStepRepositor.Update(step);
         dbContextScope.SaveChanges();
     }
 }
 public void AddProgram(RobotProgram program)
 {
     using (var dbContextScope = DbContextScopeFactory.Create())
     {
         _robotProgramRepository.Add(program);
         dbContextScope.SaveChanges();
     }
 }
Esempio n. 30
0
        private static DbContextScopeFactory CreateDbContextScopeFactory(string connectString)
        {
            var dbcontextFactory = new DbContextFactory(connectString);

            var dbContextScopeFactory = new DbContextScopeFactory(dbcontextFactory);

            return(dbContextScopeFactory);
        }