示例#1
0
        public void PreMergeGetsFiredWhenPulling(GitHooks sut, ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> origin, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange - Create origin and local repositories
            repository = origin.AddRepository(repository, signature, message);
            var tempPath        = RepositoryFixture.GetAvailableFolderPath();
            var clientContainer = containerFactory.Create <ObjectRepository>(tempPath);

            clientContainer.Clone(origin.Repositories.Single().RepositoryDescription.Path);

            // Arrange - Commit change on origin
            var change = repository.With(repository.Applications[0].Pages[0], p => p.Description, "foo");

            origin.Commit(change.Repository, signature, message);

            // Arrange - suscribe to hook
            MergeStartedEventArgs lastEvent = null;

            sut.MergeStarted += (_, args) => lastEvent = args;

            // Act - Pull commit from origin
            var pullResult = clientContainer.Pull(clientContainer.Repositories.Single().Id);
            var result     = pullResult.Apply(signature);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
        }
        public void PullRequiringMerge(ObjectRepository sut, IObjectRepositoryContainer <ObjectRepository> container, IObjectRepositoryContainerFactory containerFactory, Signature signature, string message)
        {
            // Arrange
            sut = container.AddRepository(sut, signature, message);
            var tempPath        = RepositoryFixture.GetAvailableFolderPath();
            var clientContainer = containerFactory.Create <ObjectRepository>(tempPath);

            clientContainer.Clone(container.Repositories.Single().RepositoryDescription.Path);

            // Arrange - Update source repository
            var change = sut.With(sut.Applications[0].Pages[0], p => p.Description, "foo");

            sut = container.Commit(change.Repository, signature, message);

            // Arrange - Update client repository
            var clientChange = sut.With(sut.Applications[0].Pages[0], p => p.Name, "bar");

            clientContainer.Commit(clientChange.Repository, signature, message);

            // Act
            var pullResult = clientContainer.Pull(clientContainer.Repositories.Single().Id);

            pullResult.Apply(signature);

            // Assert
            Assert.That(pullResult.RequiresMergeCommit, Is.True);
            Assert.That(clientContainer.Repositories.Single().Applications[0].Pages[0].Description, Is.EqualTo("foo"));
        }
        public void Customize(IFixture fixture)
        {
            fixture.Register(UniqueId.CreateNew);

            var serviceProvider  = fixture.Create <IServiceProvider>();
            var containerFactory = serviceProvider.GetRequiredService <IObjectRepositoryContainerFactory>();

            var container = containerFactory.Create <BlobRepository>(RepositoryFixture.GetAvailableFolderPath());

            fixture.Inject(container);
            fixture.Inject <IObjectRepositoryContainer <BlobRepository> >(container);
            fixture.Inject <IObjectRepositoryContainer>(container);

            Car CreateCar(int position) =>
            new Car.Builder(serviceProvider)
            {
                Id   = UniqueId.CreateNew(),
                Name = $"Car {position}",
                Blob = new StringBlob("Car blob")
            }.ToImmutable();
            fixture.Register(() => new BlobRepository(serviceProvider, container,
                                                      UniqueId.CreateNew(),
                                                      "Some repository",
                                                      new Version(1, 0, 0),
                                                      ImmutableList.Create <RepositoryDependency>(),
                                                      new LazyChildren <IMigration>(),
                                                      new LazyChildren <IObjectRepositoryIndex>(),
                                                      new StringBlob("a\nb\nc"),
                                                      new LazyChildren <Car>(ImmutableList.Create(CreateCar(1)))));
        }
        public void MergeSamePropertyConflict(IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // Act
            sut.Branch("newBranch");
            var updateName = page.With(p => p.Name == "modified name");

            sut.Commit(updateName.Repository, signature, message); // B
            sut.Checkout("master");
            var updateNameOther = page.With(p => p.Name == "yet again modified name");
            var commitC         = sut.Commit(updateNameOther.Repository, signature, message); // C
            var loaded          = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var merge           = loaded.Merge("newBranch");
            var chunk           = merge.ModifiedChunks.Single();

            chunk.Resolve(JToken.FromObject("merged name"));
            var mergeCommit = merge.Apply(signature); // D

            // Assert
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription())
                          .Compare(commitC, mergeCommit);

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo("yet again modified name"));
            Assert.That(changes[0].New.Name, Is.EqualTo("merged name"));
        }
示例#5
0
        protected override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);

            services.AddInternalMessageQueue();

            var descriptor = services.FirstOrDefault(x => x.ServiceType == typeof(EntityEventDelegateHandler <OrderMessageHandler>));

            if (descriptor != null)
            {
                services.Remove(descriptor);
                services.AddSingleton(OrderEvents);
            }

            var sp = services.BuildServiceProvider();

            using (var scope = sp.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;
                var db             = scopedServices.GetRequiredService <AdventureContext>();

                db.Database.EnsureCreated();

                RepositoryFixture.Seed(db).Wait();
            }
        }
        public void MergeFileDeletionChange(IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory)
        {
            // master:    A---C---D
            //             \     /
            // newBranch:   B---'

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // Act
            sut.Branch("newBranch");
            var updateName = page.With(p => p.Fields.Delete(page.Fields[1]));

            sut.Commit(updateName.Repository, signature, message); // B
            sut.Checkout("master");
            var updateDescription = page.With(p => p.Description == "modified description");
            var commitC           = sut.Commit(updateDescription.Repository, signature, message); // C
            var loaded            = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var mergeCommit       = loaded.Merge("newBranch").Apply(signature);                   // D

            // Assert
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription())
                          .Compare(commitC, mergeCommit);

            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Deleted));
            Assert.That(changes[0].Old.Id, Is.EqualTo(page.Fields[1].Id));
        }
示例#7
0
        public AddAsyncTest(RepositoryFixture fixture)
        {
            _context         = fixture.Context;
            _unitOfWork      = fixture.UnitOfWork;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            _context.Clear();
        }
        public SelectDataToProcessingTest(RepositoryFixture fixture)
        {
            _context         = fixture.Context;
            _unitOfWork      = fixture.UnitOfWork;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            _context.Clear();
        }
示例#9
0
        public IndexTest(RepositoryFixture fixture)
        {
            _context         = fixture.Context;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            controller = new ForecastErrorsController(fixture.UnitOfWork);
            _context.Clear();
        }
示例#10
0
        public GetLastDateTest(RepositoryFixture fixture)
        {
            _context          = fixture.Context;
            _unitOfWork       = fixture.UnitOfWork;
            _dateTimeMinValue = fixture.DateTimeMinValue;
            _startDate        = fixture.StartDate;
            _installationIds  = fixture.InstallationIds;

            _context.Clear();
        }
示例#11
0
        public void CommitPageNameUpdate(ObjectRepository sut, Page page, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage = page.With(p => p.Name == "modified");
            var commit       = sut.Commit(modifiedPage.Repository, signature, message);

            // Assert
            Assert.That(commit, Is.Not.Null);
        }
示例#12
0
        public DownloadInstallationInfosTest(RepositoryFixture fixture)
        {
            _unitOfWork      = fixture.UnitOfWork;
            _context         = fixture.Context;
            _installationIds = fixture.InstallationIds;

            _context.Clear();

            _downloaderMock = new Mock <IAirQualityDataDownloader <Installation> >();
        }
示例#13
0
        public void LoadLinkField(IObjectRepositoryLoader loader, ObjectRepository sut, LinkField linkField, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loaded          = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loadedLinkField = (LinkField)loaded.GetFromGitPath(linkField.GetFolderPath());

            // Assert
            Assert.That(loadedLinkField.PageLink.Link.Id, Is.EqualTo(linkField.PageLink.Link.Id));
        }
        public SaveAllAirQualityDataTest(RepositoryFixture fixture)
        {
            _context         = fixture.Context;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            _programController = new ProgramController(fixture.UnitOfWork);

            _context.Clear();
        }
示例#15
0
        public async void UpdateAsync_MustCheck_Parameters()
        {
            // Arrange
            var repository = new RepositoryFixture();

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.UpdateAsync(null));
        }
示例#16
0
        public void PreCommitCancelsCommitIfRequested(GitHooks sut, ObjectRepository instance, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            sut.CommitStarted += (_, args) => args.Cancel = true;

            // Act
            var commit = instance.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));

            // Assert
            Assert.That(commit, Is.Null);
        }
        public void ObjectRepositoryMergeChunkChangeResolveConflictOnlyOnce(Page page, string resolvedValue)
        {
            // Arrange
            var   path = RepositoryFixture.GetAvailableFolderPath();
            Field mergeBaseNode = page.Fields[0], branchNode = page.Fields[1], headNode = page.Fields[2];

            // Act
            var sut = new ObjectRepositoryPropertyChange(path, _nameProperty, CreateChunk(mergeBaseNode), CreateChunk(branchNode), CreateChunk(headNode));

            sut.Resolve(resolvedValue);
            Assert.Throws <GitObjectDbException>(() => sut.Resolve(resolvedValue));
        }
示例#18
0
        public void CreateAndLoadRepository(IObjectRepositoryLoader loader, ObjectRepository sut, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Act
            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription(inMemoryBackend));

            // Assert
            PAssert.IsTrue(AreFunctionnally.Equivalent <ObjectRepository>(() => sut == loaded));
            foreach (var apps in sut.Applications.OrderBy(v => v.Id).Zip(loaded.Applications.OrderBy(v => v.Id), (a, b) => new { source = a, desctination = b }))
            {
                PAssert.IsTrue(AreFunctionnally.Equivalent <Application>(() => apps.source == apps.desctination));
            }
        }
示例#19
0
        public UpdateTotalForecastErrorsTest(RepositoryFixture fixture)
        {
            _context         = fixture.Context;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            programController = new ProgramController(
                fixture.UnitOfWork,
                forecastErrorsCalculator:
                new PlainForecastErrorsCalculator(fixture.Config));

            _context.Clear();
        }
        public DownloadAllAirQualityDataTest(RepositoryFixture fixture)
        {
            _unitOfWork      = fixture.UnitOfWork;
            _context         = fixture.Context;
            _installationIds = fixture.InstallationIds;

            _minNumberOfMeasurements = fixture.Config.GetValue <short>(
                "AppSettings:AirlyApi:MinNumberOfMeasurements");

            _context.Clear();

            _downloaderMock = new Mock <IAirQualityDataDownloader <Measurements> >();
        }
示例#21
0
        public void Constructor_MustSet_Properties()
        {
            // Arrange
            var fixture   = new Fixture();
            var dbContext = new DbContextFixture();

            // Act
            var sut = new RepositoryFixture(dbContext, c => c.TestData);

            // Assert
            Assert.Equal(dbContext, sut.Configuration.Context);
            Assert.Equal(dbContext.TestData, sut.Configuration.DbSet);
        }
示例#22
0
        static (string, ObjectRepository) PushNewRemoteImpl(ObjectRepository repository, IObjectRepositoryContainer <ObjectRepository> container, Signature signature, string message)
        {
            var tempPath = RepositoryFixture.GetAvailableFolderPath();

            Repository.Init(tempPath, isBare: true);
            repository = container.AddRepository(repository, signature, message);
            repository.Execute(r => r.Network.Remotes.Add("origin", tempPath));

            var change = repository.With(repository.Applications[0].Pages[0], p => p.Description, "foo");

            repository = container.Commit(change.Repository, signature, message);

            container.Push(repository.Id, "origin");
            return(tempPath, repository);
        }
示例#23
0
        public CalculateForecastErrorsTest(RepositoryFixture fixture)
        {
            _config          = fixture.Config;
            _unitOfWork      = fixture.UnitOfWork;
            _context         = fixture.Context;
            _startDate       = fixture.StartDate;
            _installationIds = fixture.InstallationIds;

            _minNumberOfMeasurements = fixture.Config.GetValue <short>(
                "AppSettings:AirlyApi:MinNumberOfMeasurements");

            _forecastErrorsCalculator = new PlainForecastErrorsCalculator(_config);

            _context.Clear();
        }
        public void ObjectRepositoryMergeChunkChangeResolveConflict(Page page, string resolvedValue)
        {
            // Arrange
            var   path = RepositoryFixture.GetAvailableFolderPath();
            Field mergeBaseNode = page.Fields[0], branchNode = page.Fields[1], headNode = page.Fields[2];

            // Act
            var sut = new ObjectRepositoryPropertyChange(path, _nameProperty, CreateChunk(mergeBaseNode), CreateChunk(branchNode), CreateChunk(headNode));

            sut.Resolve(resolvedValue);

            // Assert
            Assert.That(sut.WasInConflict, Is.True);
            Assert.That(sut.IsInConflict, Is.False);
            Assert.That(sut.MergeValue, Is.SameAs(resolvedValue));
        }
示例#25
0
        public void PostCommitWhenPropertyChangeGetsFired(GitHooks sut, ObjectRepository instance, Page page, Signature signature, string message, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            CommitCompletedEventArgs lastEvent = null;

            sut.CommitCompleted += (_, args) => lastEvent = args;

            // Act
            instance.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage = page.With(p => p.Name == "modified");
            var commit       = instance.Commit(modifiedPage.Repository, signature, message);

            // Assert
            Assert.That(lastEvent, Is.Not.Null);
            Assert.That(lastEvent.CommitId, Is.EqualTo(commit));
        }
示例#26
0
        public void CreateLargeRepository(IFixture fixture, Signature signature, string message)
        {
            // Arrange
            var targetDir = RepositoryFixture.GetRepositoryPath("Benchmark");

            DirectoryUtils.Delete(targetDir);
            fixture.Customize(new MetadataCustomization(2, 200, 30));

            // Act
            var sut = fixture.Create <ObjectRepository>();

            sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(targetDir));

            // Assert
            // No assertion, the goal of this test is to create a repository to update Assets\Benchmark.zip
            Console.WriteLine($"Repository created at '{targetDir}'.");
        }
示例#27
0
        public void ResolveDiffsPageNameUpdate(ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            var originalCommit = sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var modifiedPage   = page.With(p => p.Name == "modified");
            var commit         = sut.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription(inMemoryBackend))
                          .Compare(originalCommit, commit);

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Modified));
            Assert.That(changes[0].Old.Name, Is.EqualTo(page.Name));
            Assert.That(changes[0].New.Name, Is.EqualTo(modifiedPage.Name));
        }
示例#28
0
        public void ResolveDiffsFieldAddition(IServiceProvider serviceProvider, ObjectRepository sut, Page page, Signature signature, string message, Func <RepositoryDescription, IComputeTreeChanges> computeTreeChangesFactory, InMemoryBackend inMemoryBackend)
        {
            // Arrange
            var originalCommit = sut.SaveInNewRepository(signature, message, RepositoryFixture.GetRepositoryDescription(inMemoryBackend));
            var field          = new Field(serviceProvider, Guid.NewGuid(), "foo");
            var modifiedPage   = page.With(p => p.Fields.Add(field));
            var commit         = sut.Commit(modifiedPage.Repository, signature, message);

            // Act
            var changes = computeTreeChangesFactory(RepositoryFixture.GetRepositoryDescription(inMemoryBackend))
                          .Compare(originalCommit, commit);

            // Assert
            Assert.That(changes, Has.Count.EqualTo(1));
            Assert.That(changes[0].Status, Is.EqualTo(ChangeKind.Added));
            Assert.That(changes[0].Old, Is.Null);
            Assert.That(changes[0].New.Name, Is.EqualTo(field.Name));
        }
        public void MergeTwoDifferentPropertiesWithMigrationChanged(IFixture fixture, IObjectRepositoryLoader loader, ObjectRepository sut, Page page, Signature signature, string message)
        {
            // master:    A-----D-----E---F
            //             \         /   /
            //              \   ,---'   /
            //               \ /   x   /
            // newBranch:     B---C---' (B contains a non-idempotent migration)

            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription); // A

            // B, C
            sut.Branch("newBranch");
            var updatedInstance = sut.With(i => i.Migrations.Add(fixture.Create <Migration>()));

            sut.Commit(updatedInstance.Repository, signature, message); // B
            var loaded     = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var updateName = loaded.Applications[1].Pages[1].With(p => p.Name == "modified name");

            loaded.Commit(updateName.Repository, signature, message); // C

            // D
            sut.Checkout("master");
            var updateDescription = page.With(p => p.Description == "modified description");

            sut.Commit(updateDescription.Repository, signature, message); // D
            loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());

            // E
            var mergeStep1 = loaded.Merge("newBranch");

            Assert.That(mergeStep1.IsPartialMerge, Is.True);
            mergeStep1.Apply(signature); // E

            // F
            loaded = loader.LoadFrom <ObjectRepository>(RepositoryFixture.GetRepositoryDescription());
            var mergeStep2 = loaded.Merge("newBranch");

            Assert.That(mergeStep2.IsPartialMerge, Is.False);
            mergeStep2.Apply(signature); // F
        }
示例#30
0
        public void MigrationScaffolderDetectsRequiredChanges(IFixture fixture, IServiceProvider serviceProvider, ObjectRepository sut, Signature signature, string message)
        {
            // Arrange
            var repositoryDescription = RepositoryFixture.GetRepositoryDescription();

            sut.SaveInNewRepository(signature, message, repositoryDescription);
            var updated = sut.With(i => i.Migrations.Add(fixture.Create <Migration>()));
            var commit  = sut.Commit(updated, signature, message);

            // Act
            var migrationScaffolder = new MigrationScaffolder(serviceProvider, repositoryDescription);
            var migrators           = migrationScaffolder.Scaffold(sut.CommitId, commit, MigrationMode.Upgrade);

            // Assert
            Assert.That(migrators, Has.Count.EqualTo(1));
            Assert.That(migrators[0].CommitId, Is.EqualTo(commit));
            Assert.That(migrators[0].Mode, Is.EqualTo(MigrationMode.Upgrade));
            Assert.That(migrators[0].Migrations, Has.Count.EqualTo(1));
        }