Esempio n. 1
0
 public BaseCoordinatorTests()
 {
     _siteModel = new SiteModel(Guid.NewGuid(), StorageMutability.Immutable);
     _siteModel.SetStorageRepresentationToSupply(StorageMutability.Mutable);
 }
Esempio n. 2
0
        private void SetupDITfa(bool enableTfaService = true, GetProjectUidsRequest getProjectUidsRequest = null, GetProjectUidsResult getProjectUidsResult = null)
        {
            // this setup includes the DITagFileFixture. Done here to try to avoid random test failures.

            var moqStorageProxy = new Mock <IStorageProxy>();

            var moqStorageProxyFactory = new Mock <IStorageProxyFactory>();

            moqStorageProxyFactory.Setup(mk => mk.Storage(StorageMutability.Immutable)).Returns(moqStorageProxy.Object);
            moqStorageProxyFactory.Setup(mk => mk.Storage(StorageMutability.Mutable)).Returns(moqStorageProxy.Object);
            moqStorageProxyFactory.Setup(mk => mk.MutableGridStorage()).Returns(moqStorageProxy.Object);
            moqStorageProxyFactory.Setup(mk => mk.ImmutableGridStorage()).Returns(moqStorageProxy.Object);

            var moqSurveyedSurfaces = new Mock <ISurveyedSurfaces>();

            var moqSiteModels = new Mock <ISiteModels>();

            moqSiteModels.Setup(mk => mk.PrimaryMutableStorageProxy).Returns(moqStorageProxy.Object);

            DIBuilder
            .Continue()
            .Add(x => x.AddSingleton <IStorageProxyFactory>(moqStorageProxyFactory.Object))
            .Add(x => x.AddSingleton <ISiteModels>(moqSiteModels.Object))

            .Add(x => x.AddSingleton <ISurveyedSurfaces>(moqSurveyedSurfaces.Object))
            .Add(x => x.AddSingleton <IProductionEventsFactory>(new ProductionEventsFactory()))
            .Build();

            var newSiteModelGuidTfa = Guid.NewGuid();

            ISiteModel mockedSiteModel = new SiteModel(newSiteModelGuidTfa, StorageMutability.Immutable);

            mockedSiteModel.SetStorageRepresentationToSupply(StorageMutability.Mutable);

            var moqSiteModelFactory = new Mock <ISiteModelFactory>();

            moqSiteModelFactory.Setup(mk => mk.NewSiteModel(StorageMutability.Mutable)).Returns(mockedSiteModel);

            moqSiteModels.Setup(mk => mk.GetSiteModel(newSiteModelGuidTfa)).Returns(mockedSiteModel);

            // Mock the new site model creation API to return just a new site model
            moqSiteModels.Setup(mk => mk.GetSiteModel(newSiteModelGuidTfa, true)).Returns(mockedSiteModel);

            //Moq doesn't support extension methods in IConfiguration/Root.
            var moqConfiguration    = DIContext.Obtain <Mock <IConfigurationStore> >();
            var moqMinTagFileLength = 100;

            moqConfiguration.Setup(x => x.GetValueBool("ENABLE_TFA_SERVICE", It.IsAny <bool>())).Returns(enableTfaService);
            moqConfiguration.Setup(x => x.GetValueBool("ENABLE_TFA_SERVICE")).Returns(enableTfaService);
            moqConfiguration.Setup(x => x.GetValueInt("MIN_TAGFILE_LENGTH", It.IsAny <int>())).Returns(moqMinTagFileLength);
            moqConfiguration.Setup(x => x.GetValueInt("MIN_TAGFILE_LENGTH")).Returns(moqMinTagFileLength);

            var moqTfaProxy = new Mock <ITagFileAuthProjectV5Proxy>();

            if (enableTfaService && getProjectUidsRequest != null)
            {
                moqTfaProxy.Setup(x => x.GetProjectUids(It.IsAny <GetProjectUidsRequest>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(getProjectUidsResult);
            }

            DIBuilder
            .Continue()
            .Add(x => x.AddSingleton(moqConfiguration.Object))
            .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory()))
            .Add(x => x.AddSingleton(moqTfaProxy.Object))
            .Complete();
        }