public void ReadTest() { var action = ReadAction <ActionPush>(ETALON); Assert.IsNotNull(action); AssertAction.AreEqual(GetActionPush(), action, "PushData"); }
public static ServiceProvider BuildServiceProvider() { var services = new ServiceCollection(); services.AddDbContext <ScenarioContext>(); services.AddTransient(typeof(IGenericRepository <>), typeof(GenericRepository <>)); services.AddTransient <IScenarioRepository, ScenarioRepository>(); services.AddTransient <IFolderRepository, FolderRepository>(); services.AddSingleton <IReflectedCollection, ReflectedCollection>(); services.AddTransient <IVariableAction, VariableAction>(); services.AddTransient <IMethodAction, MethodAction>(); services.AddTransient <IAssertAction, AssertAction>(); services.AddTransient <IExecutor, Executor>(serviceProvider => { var reflectedCollection = serviceProvider.GetService <IReflectedCollection>(); var variableAction = serviceProvider.GetService <IVariableAction>(); var methodAction = new MethodAction(variableAction, reflectedCollection); var assertAction = new AssertAction(variableAction); return(new Executor(variableAction, methodAction, assertAction)); }); services.AddTransient <IScenarioCreatorService, ScenarioCreatorService>(); services.AddTransient <IScenarioExecutorService, ScenarioExecutorService>(); services.AddTransient <IScenarioListService, ScenarioListService>(); return(services.BuildServiceProvider()); }
private void TestSearchBeforeJoin(Action performSearch, AssertAction assertAction, bool isRepresented) { _isJoin = true; // Create the member and employer. var member = CreateMember(); var representative = isRepresented ? CreateRepresentative(member) : null; var employer = CreateEmployer(member); var initialCredits = employer == null ? 0 : GetCredits(employer.Id); _emailServer.ClearEmails(); // Search. performSearch(); // Assert. var loggedInViewings = 0; var notLoggedInViewings = 0; var reason = AssertSearchPages(false, ref employer, member, representative, assertAction, ref loggedInViewings, ref notLoggedInViewings); AssertData(employer, member, reason, loggedInViewings, notLoggedInViewings, initialCredits); }
private void AssertWithClaimsPrincipal(AssertAction assertAction, ResolveFieldContext <object> context) { if (ClaimsPrincipalAssertion != null) { var graphRequestContext = context.UserContext as IGraphRequestContext; if (graphRequestContext == null || !ClaimsPrincipalAssertion(graphRequestContext.HttpRequest.Security.ClaimsPrincipal, assertAction)) { var message = $"{assertAction} execution has been denied due to insufficient permissions."; throw new ExecutionError(message, new SecurityException(message)); } } }
private async Task <List <TSource> > InternalBatchAsync <TSource>( IResolveFieldContext <object> context, string sourceName, AssertAction assertAction, Func <ClaimsPrincipal, AssertAction, bool> claimsPrincipalAssertion) where TSource : class { AssertWithClaimsPrincipal(assertAction, context, claimsPrincipalAssertion); var items = context.GetArgument <IEnumerable <TSource> >(sourceName).ToList(); var ctx = context.GetGraphRequestContext(); if (assertAction == AssertAction.BatchCreate) { await TransformObjects(items.Select(x => (object)x).ToList(), ctx, MutationActions.BatchCreate); } if (assertAction == AssertAction.BatchCreateOrUpdate) { await TransformObjects(items.Select(x => (object)x).ToList(), ctx, MutationActions.BatchCreateOrUpdate); } var cloned = items.Clone(); var batchItems = new Dictionary <Type, BatchModelList>(); try { var edges = _connectionEdgeResolver.HandleConnectionEdges(items, (model) => { var key = model.GetType(); BatchModelList itemsList; if (batchItems.ContainsKey(key)) { itemsList = batchItems[key]; } else { itemsList = new BatchModelList(key); batchItems[key] = itemsList; } itemsList.Add(model); }); switch (assertAction) { case AssertAction.BatchCreate: if (edges.Count > 0) { await _graphQlRepositoryProvider.GetRepository(typeof(ConnectionEdge)).BatchAddAsync(edges, ctx); } foreach (var batchItem in batchItems) { var mutationActionItem = new MutationActionItem <TSource> { Action = MutationActions.BatchCreate, RequestContext = ctx, ObjectItems = batchItem.Value.Items, RepositoryProvider = _graphQlRepositoryProvider }; await _mutationActionsProvider.HandlePreActions(mutationActionItem); await _graphQlRepositoryProvider.GetRepository(batchItem.Key).BatchAddAsync(batchItem.Key, batchItem.Value.Items, ctx); await _mutationActionsProvider.HandlePostActions(mutationActionItem); } break; case AssertAction.BatchCreateOrUpdate: if (edges.Count > 0) { await _graphQlRepositoryProvider.GetRepository(typeof(ConnectionEdge)).BatchAddOrUpdateAsync(edges, ctx); } foreach (var batchItem in batchItems) { var mutationActionItem = new MutationActionItem <TSource> { Action = MutationActions.BatchCreateOrUpdate, RequestContext = ctx, ObjectItems = batchItem.Value.Items, RepositoryProvider = _graphQlRepositoryProvider }; await _mutationActionsProvider.HandlePreActions(mutationActionItem); await _graphQlRepositoryProvider.GetRepository(batchItem.Key).BatchAddOrUpdateAsync(batchItem.Key, batchItem.Value.Items, ctx); await _mutationActionsProvider.HandlePostActions(mutationActionItem); } break; default: throw new InvalidOperationException("This internal method is only for batch operations."); } return(cloned); } catch (Exception e) { _logger.LogError(e, "An error has occured while performing a batch add operation."); throw; } }
public void ShouldPass() { AssertAction.Throws <Exception>(() => { throw new Exception(); }); }
public void ShouldFailByPredicate() { AssertAction.Throws <Exception>(() => { throw new Exception(); }, e => e.InnerException != null); }
public void ShouldFail() { AssertAction.Throws <ArgumentException>(() => { throw new Exception(); }); }
public void ShouldPassWithPredicate() { var message = "message"; AssertAction.Throws <Exception>(() => { throw new Exception(message); }, e => e.Message == message); }
private bool DefaultAssertion(ClaimsPrincipal claimsPrincipal, AssertAction assertAction) { return(claimsPrincipal.IsInRole("Eklee.User.Read")); }
private async Task <List <TSource> > InternalBatchAsync <TSource>( ResolveFieldContext <object> context, string sourceName, AssertAction assertAction) where TSource : class { AssertWithClaimsPrincipal(assertAction, context); var items = context.GetArgument <IEnumerable <TSource> >(sourceName).ToList(); var ctx = context.UserContext as IGraphRequestContext; var batchItems = new Dictionary <Type, List <object> >(); try { var edges = _connectionEdgeResolver.HandleConnectionEdges(items, (model) => { var key = model.GetType(); List <object> itemsList; if (batchItems.ContainsKey(key)) { itemsList = batchItems[key]; } else { itemsList = new List <object>(); batchItems[key] = itemsList; } itemsList.Add(model); }); switch (assertAction) { case AssertAction.BatchCreate: if (edges.Count > 0) { await _graphQlRepositoryProvider.GetRepository(typeof(ConnectionEdge)).BatchAddAsync(edges, ctx); } foreach (var batchItem in batchItems) { await _graphQlRepositoryProvider.GetRepository(batchItem.Key).BatchAddAsync(batchItem.Key, batchItem.Value, ctx); } break; case AssertAction.BatchCreateOrUpdate: if (edges.Count > 0) { await _graphQlRepositoryProvider.GetRepository(typeof(ConnectionEdge)).BatchAddOrUpdateAsync(edges, ctx); } foreach (var batchItem in batchItems) { await _graphQlRepositoryProvider.GetRepository(batchItem.Key).BatchAddOrUpdateAsync(batchItem.Key, batchItem.Value, ctx); } break; default: throw new InvalidOperationException("This internal method is only for batch operations."); } if (_searchMappedModels.TryGetMappedSearchType <TSource>(out var mappedSearchType)) { var mappedInstances = items.Select(item => Convert.ChangeType(_searchMappedModels.CreateInstanceFromMap(item), mappedSearchType)).ToList(); await _graphQlRepositoryProvider.GetRepository(mappedSearchType) .BatchAddAsync(mappedSearchType, mappedInstances, ctx); } return(context.GetArgument <IEnumerable <TSource> >(sourceName).ToList()); } catch (Exception e) { _logger.LogError(e, "An error has occured while performing a batch add operation."); throw; } }
public void ReadTest() { var action = ReadAction <ActionDefineFunction2>(_etalon); AssertAction.AreEqual(GetActionDefineFunction2(), action, "DefineFunction2"); }
private bool DefaultAssertion(ClaimsPrincipal claimsPrincipal, AssertAction assertAction) { return(claimsPrincipal.IsInRole("Eklee.Admin.Writer")); }
public void PopulateForm(AssertAction model) { _model = model; TxtBoxName.Text = _model.Name; }
private bool DefaultTenantAssertion(ClaimsPrincipal claimsPrincipal, AssertAction assertAction) { return(claimsPrincipal.IsInRole("Eklee.User.TestToFail")); }
public void ReadTest() { var action = ReadAction <ActionWith>(_etalon); AssertAction.AreEqual(GetActionWith(), action, "ActionWith"); }