コード例 #1
0
            public async Task SameFileTest()
            {
                var service = MockContainer.GetExportedValue <ICompareService>();

                MockCompareConfigDocumentType.Setup(x => x.Read(It.IsAny <string>())).Returns(new CompareConfigDocument());
                MockReadFileService.Setup(x => x.GetJsonDocument(It.IsAny <string>(), It.IsAny <CompareConfigDocument>()))
                .Callback((string path, CompareConfigDocument config) =>
                {
                    Assert.IsTrue(path.StartsWith(Path.Combine(COMPAREPATH_SAME, PATH1)) ||
                                  path.StartsWith(Path.Combine(COMPAREPATH_SAME, PATH2)));
                    Assert.IsNotNull(config);
                })
                .ReturnsAsync((string path, CompareConfigDocument config) => new JsonDocument(path, new List <KeyValuePair <string, FieldType> >()));
                MockAnalyzeService.Setup(x => x.Compare(It.IsAny <JsonDocument>(), It.IsAny <JsonDocument>()))
                .Callback((JsonDocument document1, JsonDocument document2) =>
                {
                    Assert.IsNotNull(document1);
                    Assert.IsNotNull(document2);
                })
                .ReturnsAsync((JsonDocument document1, JsonDocument document2) => new CompareFile("article", new List <CompareItem>()));

                var calledCount_SplitObjectInObject = 0;
                var progress = new Progress <IProgressReport>(report =>
                {
                    Assert.AreEqual(1, report.Total);
                    Assert.AreEqual(calledCount_SplitObjectInObject++, report.Current);
                });

                var result = await service.Compare(Path.Combine(COMPAREPATH_SAME, PATH1), Path.Combine(COMPAREPATH_SAME, PATH2), "configFile");

                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("article", result[0].FileName);
            }
コード例 #2
0
 public void Component_is_not_registered()
 {
     using (var c = new MockContainer <DependsOnClass>())
     {
         Assert.IsNotNull(c.Subject);
     }
 }
コード例 #3
0
        public void SetUp()
        {
            _container = new MockContainer();
            object Resolver(Type type, object[] args) => _container.Resolve(type, args);

            DependencyResolver.ResolveUsing(Resolver);
        }
コード例 #4
0
        public void Initialize()
        {
            this.mocks = new MockContainer();
            this.mocks.PrepareMocks();

            this.mockContext = new Mock<IUnitOfWorkData>();
            this.mockContext.Setup(c => c.News).Returns(this.mocks.NewsRepositoryMock.Object);

            this.controller = new NewsController(this.mockContext.Object);
            this.controller.Request = new HttpRequestMessage
                {
                    RequestUri = new Uri("http://localhost")
                };
            this.controller.Configuration = new HttpConfiguration();
            this.controller.Configuration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            this.newsItem = new NewsBindingModel
                {
                    Title = "New News", 
                    Content = "New News Content", 
                    PublishDate = DateTime.Now
                };

            this.fakeNewsCountBefore = this.mockContext.Object.News.GetAll().Count();
        }
コード例 #5
0
        public void Session_Variable()
        {
            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .RestartProcesses()
                           .Pop()
                           .Push <IVariableService, MockVariableService>()
                           .GetValue(SessionManager.VariableName, s => new RestartManagerSession(s))
                           .Pop();

            var onRestartProgress = 0;

            using (fixture.UseServices(services))
            {
                var sut = fixture.Create()
                          .AddCommand(CommandName)
                          .AddStatement()
                          .AddCommand("Stop-RestartManagerSession");

                sut.Streams.Progress.DataAdded += (source, args) => ++ onRestartProgress;
                sut.Invoke();
            }

            services.Verify();
            Assert.Equal(2, onRestartProgress);
        }
コード例 #6
0
        public void Correctly_replaces_guid_tokens_across_files(MockContainer <TokenTemplateParser> tokenParser, string template)
        {
            string result1 = null; string result2 = null; var guid1 = Guid.NewGuid(); var guid2 = Guid.NewGuid(); var guid3 = Guid.NewGuid(); var guid4 = Guid.NewGuid();

            "Given I have a token template parser"
            ._(() => tokenParser = B.AutoMock <TokenTemplateParser>());

            "And it has two guids"
            ._(() => A.CallTo(() => tokenParser.GetMock <IGuidGenerator>().Create()).ReturnsNextFromSequence(guid1, guid2, guid3, guid4));

            "When I parse a template with guid tokens in one file"
            ._(() => result1 = tokenParser.Subject.Parse(new TokenDictionary(new Dictionary <string, Func <string> >()), @"proj1ID = %GUID-1%; proj2ID = %GUID-2%; lib1 = %GUID-1%"));

            "When I parse a template with guid tokens in one file"
            ._(() => result2 = tokenParser.Subject.Parse(new TokenDictionary(new Dictionary <string, Func <string> >()), @"proj1ID = %GUID-1%; proj2ID = %GUID-2%; lib1 = %GUID-1%"));

            "Then the guid tokens should be replaced in the first file"
            ._(() => result1.Should().Be(@"proj1ID = %GUID-1%; proj2ID = %GUID-2%; lib1 = %GUID-1%"
                                         .Replace("%GUID-1%", guid1.ToString("B"))
                                         .Replace("%GUID-2%", guid2.ToString("B"))));

            "Then the guid tokens should be replaced in the second file"
            ._(() => result2.Should().Be(@"proj1ID = %GUID-1%; proj2ID = %GUID-2%; lib1 = %GUID-1%"
                                         .Replace("%GUID-1%", guid1.ToString("B"))
                                         .Replace("%GUID-2%", guid2.ToString("B"))));
        }
コード例 #7
0
        public void RenamingAFileIgnoresTokenInFolderName(MockContainer <FileAndDirectoryTokenParser> parser,
                                                          DirectoryInfo directoryPath, string directory, ITokenDictionary tokenDictionary)
        {
            "Given I have a file and directory token parser"
            ._(() => parser = B.AutoMock <FileAndDirectoryTokenParser>());

            "And I have a directory on disk"
            ._(() =>
            {
                directory     = ServiceLocator.Resolve <IFileManager>().GetTemporaryDirectory();
                directoryPath = Directory.CreateDirectory("%context.ProjectName%");
            });

            "And I have a file in that directory"
            ._(() => File.Create(Path.Combine(directoryPath.FullName, "Class1.cs")));

            "And I have a token dictionary with the %context.ProjectName% set"
            ._(() => tokenDictionary = BuildA.TokenDictionary.WithToken("%context.ProjectName%", "ServiceStack").Build());


            "When I call parse on the file and directory parser"
            ._(() => parser.Subject.Parse(directoryPath, tokenDictionary));

            "Then is should not try to rename the file"
            ._(
                () =>
                A.CallTo(
                    () => parser.GetMock <IFileManager>().RenameFile(A <string> .Ignored, A <string> .Ignored))
                .MustNotHaveHappened())
            .Teardown(() => Directory.Delete(directory, true));
        }
コード例 #8
0
 public void Component_is_not_registered()
 {
     using (var c = new MockContainer<DependsOnClass>())
     {
         Assert.IsNotNull(c.Subject);
     }
 }
コード例 #9
0
        protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
        {
            RegisterRequiredTypesCalled = true;

            base.RegisterRequiredTypes(containerRegistry);

            var logger = new TextLogger();

            MockContainer.Setup(x => x.Resolve(typeof(ILoggerFacade))).Returns(logger);

            var moduleInitializer = new ModuleInitializer(MockContainer.Object, logger);

            MockContainer.Setup(x => x.Resolve(typeof(IModuleInitializer))).Returns(moduleInitializer);
            MockContainer.Setup(x => x.Resolve(typeof(IModuleManager))).Returns(new ModuleManager(moduleInitializer, DefaultModuleCatalog, logger));
            MockContainer.Setup(x => x.Resolve(typeof(IRegionBehaviorFactory))).Returns(new RegionBehaviorFactory(MockContainer.Object));

            var regionBehaviorFactory = new RegionBehaviorFactory(MockContainer.Object);

            MockContainer.Setup(x => x.Resolve(typeof(IRegionBehaviorFactory))).Returns(regionBehaviorFactory);

            MockContainer.Setup(x => x.Resolve(typeof(RegionAdapterMappings))).Returns(new RegionAdapterMappings());
            MockContainer.Setup(x => x.Resolve(typeof(SelectorRegionAdapter))).Returns(new SelectorRegionAdapter(regionBehaviorFactory));
            MockContainer.Setup(x => x.Resolve(typeof(ItemsControlRegionAdapter))).Returns(new ItemsControlRegionAdapter(regionBehaviorFactory));
            MockContainer.Setup(x => x.Resolve(typeof(ContentControlRegionAdapter))).Returns(new ContentControlRegionAdapter(regionBehaviorFactory));
        }
コード例 #10
0
        public void Creates_Session()
        {
            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .Pop()
                           .Push <IVariableService, MockVariableService>()
                           .GetValue <RestartManagerSession>(SessionManager.VariableName, () => null)
                           .SetValue <RestartManagerSession>(SessionManager.VariableName)
                           .Pop();

            using (fixture.UseServices(services))
            {
                var sut = fixture.Create()
                          .AddCommand(CommandName)
                          .AddParameter("PassThru");

                using (var session = sut.Invoke <RestartManagerSession>().Single())
                {
                    Assert.Equal(0, session.SessionId);
                    Assert.Equal("123abc", session.SessionKey);

                    services.Verify <IVariableService>(x => x.SetValue(SessionManager.VariableName, session));
                }
            }

            services.Verify();
        }
コード例 #11
0
        public void Session_Variable()
        {
            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .RegisterResources()
                           .GetProcesses()
                           .Pop()
                           .Push <IVariableService, MockVariableService>()
                           .GetValue(SessionManager.VariableName, s =>
            {
                var session = new RestartManagerSession(s);
                session.RegisterResources(files: new[] { @"C:\ShouldNotExist.txt" });

                return(session);
            })
                           .Pop();

            using (fixture.UseServices(services))
            {
                var output = fixture.Create()
                             .AddCommand(CommandName)
                             .AddStatement()
                             .AddCommand("Stop-RestartManagerSession")
                             .Invoke <IProcessInfo>();

                var expected = MockRestartManagerService.GetDefaultProcessesInfo(RebootReason.None);
                Assert.Equal(expected, output, ProcessComparer.Default);
            }

            services.Verify();
        }
コード例 #12
0
 public void Calls_are_wired_automatically()
 {
     using (var c = MockContainer.For <DependsOnService>())
     {
         c.Subject.CallService();
     }
 }
コード例 #13
0
 public void AssertWasCalled_is_not_verified()
 {
     using (var c = MockContainer.For <DependsOnService>())
     {
         c.AssertWasCalled <IService>(s => s.Call());
     }
 }
コード例 #14
0
 public void Mocks_are_registered_as_singletons()
 {
     using (var c = MockContainer.For <DependsOnService>())
     {
         Assert.AreSame(c.Subject.Service, c.Resolve <IService>());
     }
 }
コード例 #15
0
 public void Mocks_are_used_where_possible()
 {
     using (var c = MockContainer.For <DependsOnService>())
     {
         Assert.IsNotNull(c.Subject);
     }
 }
コード例 #16
0
        public void Register_All_Pipeline()
        {
            var path = typeof(RegisterResourceCommand).Assembly.Location;
            var file = new
            {
                Path        = path,
                LiteralPath = $@"Microsoft.PowerShell.Core\FileSystem::{path}",
            };
            var process       = Process.GetCurrentProcess();
            var processInfo   = new ProcessAdapter(process);
            var uniqueProcess = new RM_UNIQUE_PROCESS(processInfo);
            var service       = new
            {
                ServiceName = "ServiceApp",
            };

            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .RegisterResources(files: new[] { path }, processes: new[] { uniqueProcess }, services: new[] { "ServiceApp" })
                           .Pop();

            using (var session = new RestartManagerSession(services))
            {
                fixture.Create()
                .AddCommand(CommandName)
                .AddParameter("Session", session)
                .Invoke(new object[] { file, process, service });
            }

            services.Verify();
        }
コード例 #17
0
        public void Overrides_Disposed_Session()
        {
            RestartManagerSession original = null;
            var services = new MockContainer()
                           .Push <IRestartManagerService, MockRestartManagerService>()
                           .StartSession()
                           .Pop()
                           .Push <IVariableService, MockVariableService>()
                           .GetValue(SessionManager.VariableName, s => original = new RestartManagerSession(s))
                           .Pop();

            original.Dispose();
            using (fixture.UseServices(services))
            {
                using (original)
                {
                    var sut = fixture.Create()
                              .AddCommand(CommandName)
                              .AddParameter("PassThru");

                    using (var session = sut.Invoke <RestartManagerSession>().Single())
                    {
                        Assert.Equal(0, session.SessionId);
                        Assert.Equal("123abc", session.SessionKey);
                        Assert.NotSame(original, session);

                        services.Verify <IVariableService>(x => x.SetValue(SessionManager.VariableName, session));
                    }
                }
            }

            services.Verify();
        }
コード例 #18
0
        public void Register_All_Parameter()
        {
            var path          = typeof(RegisterResourceCommand).Assembly.Location;
            var process       = Process.GetCurrentProcess();
            var processInfo   = new ProcessAdapter(process);
            var uniqueProcess = new RM_UNIQUE_PROCESS(processInfo);

            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .RegisterResources(files: new[] { path }, processes: new[] { uniqueProcess }, services: new[] { "ServiceApp" })
                           .Pop();

            using (var session = new RestartManagerSession(services))
            {
                fixture.Create()
                .AddCommand(CommandName)
                .AddParameter("Path", path)
                .AddParameter("Process", process)
                .AddParameter("ServiceName", "ServiceApp")
                .AddParameter("Session", session)
                .Invoke();
            }

            services.Verify();
        }
コード例 #19
0
        public void TestInit()
        {
            _provider = new EmptyProvider();


            MockContainer
            .GetMock <IActionContainerResolvingService>()
            .Setup(x => x.Resolve(typeof(IEnumerable <MethodDescriptor>), It.IsAny <string>()))
            .Returns(() => _methodDescriptors);

            MockContainer
            .GetMock <IActionContainerResolvingService>()
            .Setup(x => x.Resolve(typeof(IActionProvider), It.IsAny <string>()))
            .Returns(() => _provider);

            MockContainer
            .GetMock <IActionContainerResolvingService>()
            .Setup(x => x.ResolveAll(typeof(IActionListener)))
            .Returns(() => new[] { new DefaultActionListener(MockContainer.GetMock <IActionContainerResolvingService>().Object) });


            _methodDescriptors = CreateMethodDescriptors();

            _serviceAgent = MockContainer.Create <ServiceAgent>();
        }
コード例 #20
0
        public void Simple()
        {
            var container = new MockContainer().TestScope(new List <string>()
            {
                "C", // Cancel command
                "y", // Confirm cancel all
                "Q"  // Quit
            });
            var renewalStore     = container.Resolve <real.IRenewalStore>();
            var renewalValidator = container.Resolve <RenewalValidator>(
                new TypedParameter(typeof(IContainer), container));
            var renewalExecutor = container.Resolve <RenewalExecutor>(
                new TypedParameter(typeof(RenewalValidator), renewalValidator),
                new TypedParameter(typeof(IContainer), container));
            var renewalCreator = container.Resolve <RenewalCreator>(
                new TypedParameter(typeof(IContainer), container),
                new TypedParameter(typeof(RenewalExecutor), renewalExecutor));
            var renewalManager = container.Resolve <RenewalManager>(
                new TypedParameter(typeof(IContainer), container),
                new TypedParameter(typeof(RenewalExecutor), renewalExecutor),
                new TypedParameter(typeof(RenewalCreator), renewalCreator));

            Assert.IsNotNull(renewalManager);
            renewalManager.ManageRenewals().Wait();
            Assert.AreEqual(0, renewalStore.Renewals.Count());
        }
コード例 #21
0
        public void Overrides_Session_Throws()
        {
            RestartManagerSession session = null;
            var services = new MockContainer(MockBehavior.Strict)
                           .Push <IRestartManagerService>()
                           .Pop()
                           .Push <IVariableService, MockVariableService>()
                           .GetValue(SessionManager.VariableName, s => session = new RestartManagerSession(s))
                           .Pop();

            using (fixture.UseServices(services))
            {
                using (session)
                {
                    var sut = fixture.Create()
                              .AddCommand(CommandName)
                              .AddParameter("PassThru");

                    var ex = Assert.Throws <CmdletInvocationException>(() => sut.Invoke());
                    Assert.IsType <ActiveSessionException>(ex.InnerException);
                }
            }

            services.Verify();
        }
コード例 #22
0
 public void Component_is_registered_as_instance()
 {
     using (var c = new MockContainer <DependsOnClass>())
     {
         c.Register(new Component());
         Assert.IsNotNull(c.Subject);
     }
 }
コード例 #23
0
        public void GetVariable_No_Service()
        {
            var services = new MockContainer();

            var actual = SessionManager.GetVariable(services, fixture.Variables);

            Assert.Same(sessionVariable, actual);
        }
コード例 #24
0
		public void TestInitialize()
		{
			_context = new MockContainer();

			_service = _context.Create<ApplicationPresenter>();

			_applicationData = _context.Create<ApplicationData>();
		}
コード例 #25
0
ファイル: AwbStateManagerTests.cs プロジェクト: UHgEHEP/test
        public void TestInitialize()
        {
            _context = new MockContainer();

            _stateManager = _context.Create<AwbStateManager>();
            _airWaybillId = _context.Create<long>();
            _stateId = _context.Create<long>();
        }
コード例 #26
0
        public void TestInitialize()
        {
            _context = new MockContainer();

            _stateManager = _context.Create <AwbStateManager>();
            _airWaybillId = _context.Create <long>();
            _stateId      = _context.Create <long>();
        }
コード例 #27
0
 public void Component_is_registered_as_instance()
 {
     using (var c = new MockContainer<DependsOnClass>())
     {
         c.Register(new Component());
         Assert.IsNotNull(c.Subject);
     }
 }
コード例 #28
0
        public void TestInitialize()
        {
            _context = new MockContainer();

            _service = _context.Create <ApplicationPresenter>();

            _applicationData = _context.Create <ApplicationData>();
        }
コード例 #29
0
            public async Task ConfigFileNotExist()
            {
                var service = MockContainer.GetExportedValue <ICompareService>();

                MockCompareConfigDocumentType.Setup(x => x.Read(It.IsAny <string>())).Throws <FileNotFoundException>();

                await AssertHelper.ExpectedExceptionAsync <FileNotFoundException>(() => service.Compare("path1", "path2", "configFile"));
            }
コード例 #30
0
        public void ThrowsIfResolverReturnsWrongType()
        {
            _container = new MockContainer();
            _container.Register(typeof(TypeWhichWillNotResolveCorrectly), new IncorrectType());
            DependencyService.Register <TypeWhichWillNotResolveCorrectly>();

            Assert.Throws <InvalidCastException>(() => DependencyService.Resolve <TypeWhichWillNotResolveCorrectly>());
        }
コード例 #31
0
        protected override IModuleCatalog CreateModuleCatalog()
        {
            CreateModuleCatalogCalled = true;

            var moduleCatalog = base.CreateModuleCatalog();

            MockContainer.Setup(x => x.Resolve(typeof(IModuleCatalog))).Returns(moduleCatalog);
            return(moduleCatalog);
        }
コード例 #32
0
        public void GetParameterOrVariable_No_Service()
        {
            var services = new MockContainer();

            RestartManagerSession session = null;
            var actual = SessionManager.GetParameterOrVariable(services, ref session, fixture.Variables);

            Assert.Same(sessionVariable, actual);
        }
コード例 #33
0
        public void TestInitialize()
        {
            const int count = 20;

            _context           = new MockContainer();
            _countries         = new List <CountryData>();
            _cities            = new List <CityData>();
            _localazedStates   = new Dictionary <long, string>();
            _stateAvailability = Enumerable.Range(0, count / 2).Select(x => (long)x).ToArray();
            _data         = _context.CreateMany <ApplicationData>(count).ToArray();
            _calculations = _data.Take(count / 2).ToDictionary(x => x.Id, x => _context.Create <long>());

            for (var i = 0; i < count; i++)
            {
                var country = new CountryData
                {
                    Id       = i,
                    Name     = _context.Create <string>(),
                    Position = i
                };
                _countries.Add(country);
                _cities.Add(new CityData
                {
                    Id       = i,
                    Name     = _context.Create <string>(),
                    Position = i
                });
                _localazedStates.Add(i, _context.Create <string>());

                _data[i].StateId       = i;
                _data[i].CountryId     = i / 2;
                _data[i].TransitCityId = i / 3;
            }

            _context.ApplicationFileRepository.Setup(x => x.GetInfo(It.IsAny <long[]>(), It.IsAny <ApplicationFileType>()))
            .Returns(new ReadOnlyDictionary <long, ReadOnlyCollection <FileInfo> >(new Dictionary <long, ReadOnlyCollection <FileInfo> >(0)));

            _context.IdentityService.SetupGet(x => x.Language).Returns(TwoLetterISOLanguageName.English);
            _context.CountryRepository.Setup(x => x.All(TwoLetterISOLanguageName.English)).Returns(_countries.ToArray());
            _context.CityRepository.Setup(x => x.All(TwoLetterISOLanguageName.English)).Returns(_cities.ToArray());
            _context.StateFilter.Setup(x => x.GetStateAvailabilityToSet()).Returns(_stateAvailability);
            _context.StateConfig.SetupGet(x => x.CargoOnTransitStateId).Returns(CargoOnTransitStateId);
            _context.ApplicationRepository.Setup(x => x.GetCalculations(It.IsAny <long[]>())).Returns(_calculations);
            _context.StateRepository.Setup(x => x.Get(It.IsAny <string>(), It.IsAny <long[]>())).Returns(
                (string lang, long[] ids) => ids.ToDictionary(
                    x => x,
                    x =>
                    new StateData
            {
                Name          = "State " + x,
                Position      = (int)x,
                LocalizedName = _localazedStates[x]
            }
                    ));

            _mapper = _context.Create <ApplicationListItemMapper>();
        }
コード例 #34
0
		public void TestInitialize()
		{
			const int count = 20;
			_context = new MockContainer();
			_countries = new List<CountryData>();
			_cities = new List<CityData>();
			_localazedStates = new Dictionary<long, string>();
			_stateAvailability = Enumerable.Range(0, count / 2).Select(x => (long)x).ToArray();
			_data = _context.CreateMany<ApplicationData>(count).ToArray();
			_calculations = _data.Take(count / 2).ToDictionary(x => x.Id, x => _context.Create<long>());

			for(var i = 0; i < count; i++)
			{
				var country = new CountryData
				{
					Id = i,
					Name = _context.Create<string>(),
					Position = i
				};
				_countries.Add(country);
				_cities.Add(new CityData
				{
					Id = i,
					Name = _context.Create<string>(),
					Position = i
				});
				_localazedStates.Add(i, _context.Create<string>());

				_data[i].StateId = i;
				_data[i].CountryId = i / 2;
				_data[i].TransitCityId = i / 3;
			}

			_context.ApplicationFileRepository.Setup(x => x.GetInfo(It.IsAny<long[]>(), It.IsAny<ApplicationFileType>()))
				.Returns(new ReadOnlyDictionary<long, ReadOnlyCollection<FileInfo>>(new Dictionary<long, ReadOnlyCollection<FileInfo>>(0)));

			_context.IdentityService.SetupGet(x => x.Language).Returns(TwoLetterISOLanguageName.English);
			_context.CountryRepository.Setup(x => x.All(TwoLetterISOLanguageName.English)).Returns(_countries.ToArray());
			_context.CityRepository.Setup(x => x.All(TwoLetterISOLanguageName.English)).Returns(_cities.ToArray());
			_context.StateFilter.Setup(x => x.GetStateAvailabilityToSet()).Returns(_stateAvailability);
			_context.StateConfig.SetupGet(x => x.CargoOnTransitStateId).Returns(CargoOnTransitStateId);
			_context.ApplicationRepository.Setup(x => x.GetCalculations(It.IsAny<long[]>())).Returns(_calculations);
			_context.StateRepository.Setup(x => x.Get(It.IsAny<string>(), It.IsAny<long[]>())).Returns(
				(string lang, long[] ids) => ids.ToDictionary(
					x => x,
					x =>
						new StateData
						{
							Name = "State " + x,
							Position = (int)x,
							LocalizedName = _localazedStates[x]
						}
					));

			_mapper = _context.Create<ApplicationListItemMapper>();
		}
コード例 #35
0
        public void Test_HaveAccessToClient_Sender()
        {
            var container = new MockContainer();
            var permissions = container.Create<ClientPermissions>();

            container.IdentityService.Setup(x => x.IsInRole(RoleType.Admin)).Returns(false);
            container.IdentityService.Setup(x => x.IsInRole(RoleType.Sender)).Returns(true);

            permissions.HaveAccessToClient(It.IsAny<ClientData>()).Should().BeTrue();
        }
コード例 #36
0
        public void Test_HaveAccessToClient_Sender()
        {
            var container   = new MockContainer();
            var permissions = container.Create <ClientPermissions>();

            container.IdentityService.Setup(x => x.IsInRole(RoleType.Admin)).Returns(false);
            container.IdentityService.Setup(x => x.IsInRole(RoleType.Sender)).Returns(true);

            permissions.HaveAccessToClient(It.IsAny <ClientData>()).Should().BeTrue();
        }
コード例 #37
0
ファイル: Unattended.cs プロジェクト: digicert/win-acme
        public void BasicSecret(string commandLine, bool allowEmpty, string?output)
        {
            var container = new MockContainer().TestScope(commandLine: commandLine);
            var mock      = container.Resolve <ArgumentsInputService>();
            var result    = mock.GetProtectedString <CentralSslArguments>(x => x.PfxPassword, allowEmpty).
                            GetValue().
                            Result;

            Assert.AreEqual(output, result?.Value);
        }
コード例 #38
0
        public void InitTests()
        {
            this.mocks = new MockContainer();
            this.mocks.PrepareMocks();

            this.mockContext = new Mock<INewsData>();
            this.mockContext.Setup(c => c.News).Returns(this.mocks.NewsRepositoryMock.Object);

            this.newsController = new NewsController(this.mockContext.Object);
            this.ConfigureController(this.newsController);
        }
コード例 #39
0
        public void Setup()
        {
            var container = new MockContainer();
            container.Register(typeof (ITestService), typeof (TestService));
            IoC.SetImplementation(container);

            _controller = new TestController();

            var route = "action test".ToRoute();
            _result = _controller.Execute(route);
        }
コード例 #40
0
		public void TestInitialize()
		{
			_context = new MockContainer();
			_applicationListController = new ApplicationListController(
				_context.ApplicationListPresenter.Object,
				_context.ClientRepository.Object,
				_context.SenderRepository.Object,
				_context.AwbRepository.Object,
				_context.CarrierRepository.Object,
				_context.StateConfig.Object,
				_context.IdentityService.Object,
				_context.ForwarderRepository.Object);
		}
コード例 #41
0
ファイル: ClientManagerTests.cs プロジェクト: UHgEHEP/test
		public void Test_Update_Not_HaveAccessToClient()
		{
			var container = new MockContainer();
			var clientId = container.Create<long>();
			var data = container.Create<ClientData>();

			container.ClientRepository.Setup(x => x.Get(clientId)).Returns(data);
			container.ClientPermissions.Setup(x => x.HaveAccessToClient(data)).Returns(false);

			var manager = container.Create<ClientManager>();

			manager.Update(clientId, It.IsAny<ClientModel>(), It.IsAny<TransitEditModel>());
		}
コード例 #42
0
        public void Test_HaveAccessToClient_ByIdentity_False()
        {
            var container = new MockContainer();
            var permissions = container.Create<ClientPermissions>();
            var data = container.Create<ClientData>();
			var userId = container.Create<long>();

            container.IdentityService.Setup(x => x.IsInRole(RoleType.Admin)).Returns(false);
			container.IdentityService.Setup(x => x.IsInRole(RoleType.Manager)).Returns(false);
            container.IdentityService.Setup(x => x.IsInRole(RoleType.Sender)).Returns(false);
			container.ClientRepository.Setup(x => x.GetByUserId(userId)).Returns(container.Create<ClientData>());
			container.IdentityService.Setup(x => x.Id).Returns(userId);

            permissions.HaveAccessToClient(data).Should().BeFalse();
        }
コード例 #43
0
		public void TestInitialize()
		{
			_context = new MockContainer();
			_service = _context.Create<ApplicationListPresenter>();
			_orders = new[]
			{
				new Order
				{
					OrderType = OrderType.State,
					Desc = false
				}
			};
			_stateIds = new[] { 0L };
			_models = _context.CreateMany<ApplicationListItem>().ToArray();
		}
コード例 #44
0
        public void FileAddsUpdatesAndDeletesList()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var list = TestResourceFactory.GetMockClassAObjects(22).Cast<MockClassC>().ToList();
            list.ForEach(i => i.WithId(i.GetHashCode()));

            var container = new MockContainer() { AsList = list };

            using (var repo = new MockFileRepository(_testName + ".xml", "."))
            {
                repo.Load();
                repo.Clear();

                list.ForEach(i => i.Id = repo.Add(i));
                repo.AddOrUpdate(list.First(), list.First().Id);
                repo.AddOrUpdate(TestResourceFactory.CreateRandom() as MockClassC, 0);

                repo.Flush();
            }

            using (var repo = new MockFileRepository(_testName + ".xml", "."))
            {
                repo.Load();

                repo.Delete(list.Last().Id);
                list.Remove(list.Last());

                foreach (var orig in list)
                {
                    var item = repo.Fetch(orig.Id);

                    Assert.AreEqual(item.Id, orig.Id);
                    Assert.AreEqual(item.Name, orig.Name);
                    Assert.AreEqual(item.GetSomeCheckSum[0], orig.GetSomeCheckSum[0]);
                    Assert.AreEqual(item.Location.X, orig.Location.X);
                    Assert.AreEqual(item.Location.Y, orig.Location.Y);
                    Assert.AreEqual(item.Location.Z, orig.Location.Z);
                    Assert.AreEqual(item.Location.W, orig.Location.W);
                    Assert.AreEqual(item.ReferenceCode, orig.ReferenceCode);
                    Assert.AreEqual(item.ReplicationID, orig.ReplicationID);
                }

                Assert.AreEqual(22, repo.Length);
            }
        }
コード例 #45
0
ファイル: MailSenderTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_context = new MockContainer();
			_context.SenderRepository.Setup(x => x.GetByUserId(TestConstants.TestAdminUserId)).Returns((long?)null);
			var configuration = new MailConfiguration();
			_sender = new MailSender(configuration);
			_mailFolder = configuration.GetConfiguration(TestConstants.TestAdminUserId)
				.SpecifiedPickupDirectory
				.PickupDirectoryLocation;

			if(Directory.Exists(_mailFolder))
			{
				foreach(var file in Directory.EnumerateFiles(_mailFolder))
				{
					File.Delete(file);
				}
			}
		}
コード例 #46
0
        public void SetupMock()
        {
            // Setup fake data
            this.mock = new MockContainer();
            var fakeUsers = this.mock.UsersRepositoryMock.Object;
            var fakePosts = this.mock.PostsRepositoryMock.Object;
            var fakeReplies = this.mock.RepliesRepositoryMock.Object;
            var context = new Mock<ITweeterLikeData>();

            // Setup repositories
            context.Setup(u => u.ApplicationUsers).Returns(fakeUsers);
            context.Setup(u => u.Posts).Returns(fakePosts);
            context.Setup(u => u.Replies).Returns(fakeReplies);

            // Setup idProvider
            var idProvider = new Mock<IUserIdProvider>();
            idProvider.Setup(p => p.GetUserId()).Returns("1");

            // Setup controller
            this.controller = new PostController(context.Object, idProvider.Object);
            this.controller.Request = new HttpRequestMessage();
            this.controller.Configuration = new HttpConfiguration();
        }
コード例 #47
0
 public void InitTest()
 {
     _mocks = new MockContainer();
     _mocks.PrepareMocks();
 }
コード例 #48
0
ファイル: MessageBuilderTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_container = new MockContainer();
			_builder = _container.Create<ApplicationMessageBuilder>();
		}
コード例 #49
0
ファイル: StateServiceTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_context = new MockContainer();
			_stateFilter = _context.Create<StateFilter>();
		}
コード例 #50
0
ファイル: ClientControllerTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_composition = new CompositionHelper(Settings.Default.MainConnectionString, Settings.Default.FilesConnectionString);
			_mock = new MockContainer();
			_controller = _composition.Kernel.Get<ClientController>();
		}
コード例 #51
0
ファイル: AwbUpdateManagerTests.cs プロジェクト: UHgEHEP/test
        public void TestInitialize()
        {
            _context = new MockContainer();

            _manager = _context.Create<AwbUpdateManager>();
        }
コード例 #52
0
ファイル: BillModelFactoryTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_container = new MockContainer();
			_factory = _container.Create<BillModelFactory>();
		}
コード例 #53
0
 public void InitTest()
 {
     this.mocks = new MockContainer();
     this.mocks.PrepareMocks();
 }
コード例 #54
0
ファイル: BindingContextTest.cs プロジェクト: Profit0004/mono
		public void TestIndexerWithMember ()
		{
			BindingContext bc = new BindingContext ();
			ArrayList data_source = new ArrayList ();
			BindingManagerBase a, b, c, d;
			
			data_source.AddRange (new string [] { "1", "2", "3", "4", "5" });

			a = bc [data_source, "Length"];
			b = bc [data_source, "Length"];

			Assert.AreSame (a, b, "INWM1");

			b = bc [data_source];
			Assert.IsFalse (object.ReferenceEquals (a, b), "INWM2");

			c = bc [data_source];
			Assert.AreSame (b, c, "INWM3");
			
			b = bc [data_source, "Length"];
			Assert.AreSame (a, b, "INWM4");

			// Non List type
			MockItem item = new MockItem ("Mono", -1);
			MockContainer container = new MockContainer ();
			container.Item = item;

			d = bc [container, "Item.Text"];
			Assert.AreEqual ("Mono", d.Current, "INWM5");
			Assert.AreEqual (1, d.Count, "INWM6");
			Assert.AreEqual (0, d.Position, "INWM7");

			d = bc [container, "Item.Text.Length"];
			Assert.AreEqual (4, d.Current, "INWM8");
			Assert.AreEqual (1, d.Count, "INWM9");
			Assert.AreEqual (0, d.Position, "INWM10");
		}
コード例 #55
0
		public void TestInitialize()
		{
			_container = new MockContainer();

			_templateRepositoryHelper = _container.Create<TemplateRepositoryHelper>();
		}
コード例 #56
0
		public void TestInitialize()
		{
			_context = new MockContainer();

			_manager = _context.Create<ApplicationAwbManager>();
		}
コード例 #57
0
ファイル: SenderServiceTests.cs プロジェクト: UHgEHEP/test
		public void TestInitialize()
		{
			_context = new MockContainer();
			_service = _context.Create<SenderService>();
		}
コード例 #58
0
 public void TestMethod1()
 {
     this.mocks = new MockContainer();
     this.mocks.PrepareMocks();
 }