public async Task SendsFilter() { const string ModelName = FilterConstants.WorkOrder; const string FilterName = "testFilter"; const string FilterOptionKey = "1"; const string FilterOptionValue = "Option1"; const string ContractorReference = "cont_ref"; const string ContractorName = "cont_name"; const string TradeCode = "trade_code"; const string TradeName = "trade_name"; IOptions <FilterConfiguration> options = CreateFilterConfiguration(ModelName, FilterName, FilterOptionKey, FilterOptionValue); var mockScheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); var mockCurrentUserService = new CurrentUserServiceMock(); mockCurrentUserService.SetSecurityGroup(UserGroups.Agent); mockScheduleOfRatesGateway.Setup(m => m.GetLiveContractors()).ReturnsAsync(new Contractor(ContractorReference, ContractorName).MakeArray()); mockScheduleOfRatesGateway.Setup(m => m.GetTrades()).ReturnsAsync(new SorCodeTrade(TradeCode, TradeName).MakeArray()); var sut = new WorkOrderFilterProvider(options, mockScheduleOfRatesGateway.Object, mockCurrentUserService.Object); var result = await sut.GetFilter(); ValidateFilterSection(result, FilterName, FilterOptionKey, FilterOptionValue); ValidateFilterSection(result, FilterSectionConstants.Contractors, ContractorReference, ContractorName); ValidateFilterSection(result, FilterSectionConstants.Trades, TradeCode, TradeName); }
public void Setup() { _fixture = new Fixture(); _repairsGatewayMock = new MockRepairsGateway(); _authMock = new AuthorisationMock(); _authMock.SetPolicyResult("RaiseSpendLimit", true); _scheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); ContractorUsesExternalScheduler(false); _currentUserServiceMock = new CurrentUserServiceMock(); _featureManagerMock = new Mock <IFeatureManager>(); _featureManagerMock.Setup(fm => fm.IsEnabledAsync(It.IsAny <string>())).ReturnsAsync(true); _notificationMock = new NotificationMock(); _drsOptions = new DrsOptions { Login = "******", Password = "******", APIAddress = new Uri("https://apiAddress.none"), ManagementAddress = new Uri("https://managementAddress.none") }; _classUnderTest = new CreateWorkOrderUseCase( _repairsGatewayMock.Object, _scheduleOfRatesGateway.Object, new NullLogger <CreateWorkOrderUseCase>(), _currentUserServiceMock.Object, _authMock.Object, _featureManagerMock.Object, _notificationMock, Options.Create(_drsOptions) ); }
public void Setup() { _generator = CreateGenerator(); _repairsGatewayMock = new Mock <IRepairsGateway>(); _scheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); _repairsSnsServiceMock = new Mock <IRepairsSnsService>(); _scheduleOfRatesGateway.Setup(mock => mock.GetContractor(It.IsAny <string>())).ReturnsAsync(new RepairsApi.V2.Domain.Contractor { CanAssignOperative = true }); _currentUserServiceMock = new CurrentUserServiceMock(); _currentUserServiceMock.SetSecurityGroup(UserGroups.Agent, true); _currentUserServiceMock.SetSecurityGroup(UserGroups.Contractor, true); _workOrderCompletionGatewayMock = new MockWorkOrderCompletionGateway(); _handlerMock = new NotificationMock(); _featureManager = new Mock <IFeatureManager>(); OperativeRequired(false); _classUnderTest = new CompleteWorkOrderUseCase( _repairsGatewayMock.Object, _workOrderCompletionGatewayMock.Object, InMemoryDb.TransactionManager, _currentUserServiceMock.Object, _handlerMock, _featureManager.Object, _scheduleOfRatesGateway.Object, _repairsSnsServiceMock.Object, new NullLogger <CompleteWorkOrderUseCase>()); }
public ApplicationDbContextTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var currentUserService = new CurrentUserServiceMock(); _sutContext = new ApplicationDbContext(options, currentUserService); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _repairsGatewayMock = new MockRepairsGateway(); _currentUserServiceMock = new CurrentUserServiceMock(); _classUnderTest = new ContractorAcknowledgeVariationUseCase( _repairsGatewayMock.Object, _currentUserServiceMock.Object); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _currentUserServiceMock = new CurrentUserServiceMock(); _notifierMock = new NotificationMock(); _classUnderTest = new RejectWorkOrderStrategy( _currentUserServiceMock.Object, _notifierMock ); }
public async Task RunBeforeAnyTests() { // Create database container for integration tests var dockerSqlPort = await DockerDatabaseUtilities.EnsureDockerStartedAsync(); var dockerConnectionString = DockerDatabaseUtilities.GetSqlConnectionString(dockerSqlPort); // Build configuration, including the connection string from the database container var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .AddInMemoryCollection(new Dictionary <string, string> { { "ConnectionStrings:Database", dockerConnectionString } }) .AddEnvironmentVariables(); _configuration = builder.Build(); _env = Mock.Of <IWebHostEnvironment>(); var startup = new Startup(_configuration, _env); var services = new ServiceCollection(); services.AddLogging(); startup.ConfigureServices(services); #region Register mocks var descriptorCurrentUserService = services.FirstOrDefault(d => d.ServiceType == typeof(ICurrentUserService)); services.Remove(descriptorCurrentUserService !); services.AddTransient(_ => CurrentUserServiceMock.Create(_user).Object); var descriptorDateTimeProvider = services.FirstOrDefault(d => d.ServiceType == typeof(IDateTimeProvider)); services.Remove(descriptorDateTimeProvider !); services.AddTransient(_ => DateTimeProviderMock.Create(DateTime.UtcNow).Object); var descriptorStorageService = services.FirstOrDefault(d => d.ServiceType == typeof(IStorageService)); services.Remove(descriptorStorageService !); services.AddTransient(_ => StorageServiceMock.Create().Object); #endregion _scopeFactory = services.BuildServiceProvider().GetService <IServiceScopeFactory>() ?? throw new InvalidOperationException(); _checkpoint = new Checkpoint { TablesToIgnore = new[] { "__EFMigrationsHistory" }, DbAdapter = DbAdapter.Postgres }; EnsureDatabase(); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _repairsGatewayMock = new MockRepairsGateway(); _currentUserServiceMock = new CurrentUserServiceMock(); _jobStatusUpdateGatewayMock = new Mock <IJobStatusUpdateGateway>(); _notifier = new NotificationMock(); _classUnderTest = new RejectVariationUseCase( _repairsGatewayMock.Object, _currentUserServiceMock.Object, _jobStatusUpdateGatewayMock.Object, _notifier); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _currentUserServiceMock = new CurrentUserServiceMock(); _notifierMock = new NotificationMock(); _expectedName = "Expected Name"; _currentUserServiceMock.SetUser("1111", "*****@*****.**", _expectedName); _authorisationMock = new AuthorisationMock(); _authorisationMock.SetPolicyResult("RaiseSpendLimit", true); _classUnderTest = new ApproveWorkOrderStrategy( _currentUserServiceMock.Object, _notifierMock, _authorisationMock.Object ); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _repairsGatewayMock = new MockRepairsGateway(); _currentUserServiceMock = new CurrentUserServiceMock(); _jobStatusUpdateGateway = new Mock <IJobStatusUpdateGateway>(); _updateSorCodesUseCaseMock = new Mock <IUpdateSorCodesUseCase>(); _expectedName = "Expected Name"; _currentUserServiceMock.SetUser("1111", "*****@*****.**", _expectedName); _notifierMock = new NotificationMock(); _authorisationMock = new AuthorisationMock(); _authorisationMock.SetPolicyResult("VarySpendLimit", true); _classUnderTest = new ApproveVariationUseCase( _repairsGatewayMock.Object, _jobStatusUpdateGateway.Object, _currentUserServiceMock.Object, _updateSorCodesUseCaseMock.Object, _notifierMock, _authorisationMock.Object); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _authorisationMock = new AuthorisationMock(); _featureManagerMock = new FeatureManagerMock(); _currentUserServiceMock = new CurrentUserServiceMock(); _updateSorCodesUseCaseMock = new Mock <IUpdateSorCodesUseCase>(); _sheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); _sheduleOfRatesGateway.Setup(g => g.GetCost(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(10.0); _notifierMock = new NotificationMock(); _classUnderTest = new MoreSpecificSorUseCase( _authorisationMock.Object, _featureManagerMock.Object, _currentUserServiceMock.Object, _updateSorCodesUseCaseMock.Object, _sheduleOfRatesGateway.Object, _notifierMock); }
public static async Task <ClaimsPrincipal> RunAsUserAsync(string userName = "", string password = "", UserRole role = UserRole.Regular) { using var scope = _scopeFactory.CreateScope(); var dbContext = scope.ServiceProvider.GetService <ApplicationDbContext>() ?? throw new Exception("No user manager"); if (!string.IsNullOrEmpty(userName)) { var user = await dbContext.Users.SingleOrDefaultAsync(u => u.UserName == userName); if (user != null) { return(CurrentUserServiceMock.CreateMockPrincipal(user.Id, user.UserName)); } } else { userName = $"user{DateTime.Now.Ticks}"; } if (string.IsNullOrEmpty(password)) { password = Guid.NewGuid().ToString("N"); } var pwHasher = scope.ServiceProvider.GetRequiredService <IPasswordHasher>(); password = pwHasher.Hash(password); var newUser = new User(userName, userName + "@localhost", password, role); await dbContext.Users.AddAsync(newUser); await dbContext.SaveChangesAsync(); _user = CurrentUserServiceMock.CreateMockPrincipal(newUser.Id, newUser.UserName); return(_user); }
public async Task RestrictedContractorFilterForContractors() { const string ModelName = FilterConstants.WorkOrder; var mockCurrentUserService = new CurrentUserServiceMock(); mockCurrentUserService.SetSecurityGroup(UserGroups.Contractor); mockCurrentUserService.SetContractor("c1", "c2", "c3"); var mockScheduleOfRatesGateway = new Mock <IScheduleOfRatesGateway>(); mockScheduleOfRatesGateway.Setup(m => m.GetLiveContractors()).ReturnsAsync(BuildContractors("c1", "c3", "c4")); var filter = new FilterConfigurationBuilder().AddModel(ModelName, b => { }).Build(); var sut = new WorkOrderFilterProvider(Options.Create(filter), mockScheduleOfRatesGateway.Object, mockCurrentUserService.Object); var result = await sut.GetFilter(); result.Should().ContainKey(FilterSectionConstants.Contractors); result[FilterSectionConstants.Contractors].Should().HaveCount(2); result[FilterSectionConstants.Contractors].Should().ContainSingle(c => c.Key == "c1" && c.Description == "c1"); result[FilterSectionConstants.Contractors].Should().ContainSingle(c => c.Key == "c3" && c.Description == "c3"); }
public void Setup() { _userServiceMock = new CurrentUserServiceMock(); _userServiceMock.SetContractor(Array.Empty <string>()); _classUnderTest = new RepairsGateway(InMemoryDb.Instance, _userServiceMock.Object); }
public void SetUp() { _mockCurrentUserService = new CurrentUserServiceMock(); _classUnderTest = new HubUserController(_mockCurrentUserService.Object); }