Exemplo n.º 1
0
        private static IContext CreateContext(string contextName)
        {
            ContextFactory factory      = new ContextFactory();
            var            contextSetup = factory.Create(contextName, null);

            contextSetup.EnablePayloadDefinitionHash();

            List <IPayloadComponentId> payloadIds = new List <IPayloadComponentId>();

            Assembly currentAssembly = Assembly.GetAssembly(typeof(TestPayload));
            var      payloads        = ContextUtilities.FindPayloadComponents(currentAssembly);

            foreach (var payload in payloads)
            {
                var id = contextSetup.RegisterPayloadComponent(payload);
                payloadIds.Add(id);
            }

            IContext context = contextSetup.EndSetup();

            var           hash       = contextSetup.GetPayloadDefinitionHash();
            StringBuilder hashString = new StringBuilder(64);

            foreach (byte hashByte in hash)
            {
                hashString.Append(hashByte.ToString("x2"));
            }
            Console.WriteLine("Hash: {0}", hashString.ToString());

            TestPayload.SetId(context.FindPayloadId(nameof(TestPayload)));
            return(context);
        }
Exemplo n.º 2
0
        private async Task ExecuteAsync(WebhookEvent ev)
        {
            await RestoreStateAsync(ev.Source.UserId);

            if (ev.Type == WebhookEventType.Unfollow)
            {
                MessagingChatSettings.IsLineFrend = false;
                MessagingChatSettings.ChatStatus  = ChatStatusType.Init;
                await SaveStateAsync(ev.Source.UserId);

                return;
            }

            if (ev.Type == WebhookEventType.Follow)
            {
                MessagingChatSettings.IsLineFrend = true;
                MessagingChatSettings.ChatStatus  = ChatStatusType.Init;
            }

            await ContextFactory.Create(MessagingChatSettings.ChatStatus).ExecuteAsync(
                new ContextState
            {
                Client          = Client,
                SessionData     = MessagingSessionData,
                Settings        = MessagingChatSettings,
                WebhookEvent    = ev,
                StateStoreTable = StateStoreTable,
                Binder          = Binder,
            });

            await SaveStateAsync(ev.Source.UserId);
        }
Exemplo n.º 3
0
        public IActionResult Excluir(int idTool)
        {
            Tool query = new Tool();

            try
            {
                using (var bank = ContextFactory.Create(_appSettings.connectionString))
                {
                    query = (from tool in bank.Tool
                             where tool.idTool == idTool
                             select tool).SingleOrDefault();

                    if (query == null)
                    {
                        ShowNotificationRedirect(NotificationType.Error, $"Ferramenta procurada não existe");
                        return(RedirectToAction("Index", "Tool"));
                    }

                    query.isDeleted = true;
                    bank.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ShowNotification(NotificationType.Error, $"Erro ao acessar página: {ex.Message}");
                return(View(query));
            }

            ShowNotificationRedirect(NotificationType.Success, $"Ferramenta removida com sucesso");
            return(RedirectToAction("Index", "Tool"));
        }
Exemplo n.º 4
0
        public DeleteAccountResultDTO DeleteAccount(DeleteAccountInDTO dto)
        {
            DeleteAccountResultDTO result = new DeleteAccountResultDTO();

            using (BaseContext context = ContextFactory.Create())
            {
                IUnitOfWork           uow = new BaseUnitOfWork(context);
                IRepository <Account> accountRepository = uow.GetRepository <Account>();

                Account acc = accountRepository.GetAll(x => x.Id == dto.AccountId && x.CustomerId == dto.CustomerId && x.Status == 1).FirstOrDefault();
                if (acc == null)
                {
                    result.IsSuccess       = false;
                    result.ResponseMessage = "Geçersiz bir işlem yürütüldü. Lütfen bilgileri kontrol ederek tekrar deneyiniz.";
                }
                else
                {
                    acc.Status = 0;
                    accountRepository.Update(acc);
                    uow.SaveChanges();

                    result.IsSuccess       = true;
                    result.ResponseMessage = "Hesap başarıyla silindi.";
                }

                return(result);
            }
        }
Exemplo n.º 5
0
        public List <ActorRole> GetActorRolesForEntity(int actorId, int entityId, ClaimScope scope, bool includeClaims = false)
        {
            using (var context = ContextFactory.Create())
            {
                if (includeClaims)
                {
                    var roles = context.ActorRoles
                                .Include(r => r.Role)
                                .ThenInclude(r => r.RoleClaims)
                                .ThenInclude(rc => rc.Claim)
                                .Where(ar => ar.ActorId == actorId &&
                                       (ar.EntityId == entityId || ar.EntityId == Platform.AllId) &&
                                       ar.Role.ClaimScope == scope)
                                .ToList();

                    return(roles);
                }
                else
                {
                    var roles = context.ActorRoles
                                .Where(ar => ar.ActorId == actorId &&
                                       (ar.EntityId == entityId || ar.EntityId == Platform.AllId) &&
                                       ar.Role.ClaimScope == scope)
                                .ToList();

                    return(roles);
                }
            }
        }
Exemplo n.º 6
0
        public void Create_Some_Context_Instances_With_Default_Stores()
        {
            ReflectionHelper.ClearInternalContextCaches();

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var first = ContextFactory.Create <JsonContextWithSimpleIdentity>()
                        .WithMemoryFilesystem()
                        .Build();
            var firstElapsed = stopwatch.ElapsedTicks;

            stopwatch.Restart();
            var second = ContextFactory.Create <JsonContextWithSimpleIdentity>()
                         .WithMemoryFilesystem()
                         .Build();
            var secondElapsed = stopwatch.ElapsedTicks;

            var factor = firstElapsed / secondElapsed;

            // TODO: 1000 is the expected factor, but test conditions arent good
            // okay that's a lie => ClearInternalContextCaches is broken ^^
            Assert.True(factor > 2,
                        "Initializing a context with warm caches should be really really fast! (factor " + factor + ")");
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            var configuration = builder.Build();

            string connectionString = configuration.GetConnectionString("managerConnection");

            // Create an employee instance and save the entity to the database
            Employee employee = new Employee();

            employee.Name = DateTime.Now.ToString();

            Random random       = new Random();
            int    randomNumber = random.Next(0, 100);

            employee.Id = randomNumber;

            using (var context = ContextFactory.Create(connectionString))
            {
                context.Add(employee);
                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public IActionResult Create(Tool tool)
        {
            try
            {
                if (string.IsNullOrEmpty(tool.name))
                {
                    ShowNotification(NotificationType.Error, $"O nome é obrigatório");
                    return(View(tool));
                }

                if (string.IsNullOrEmpty(tool.link))
                {
                    ShowNotification(NotificationType.Error, $"O link de acesso da ferramenta é Obrigatorio");
                    return(View(tool));
                }

                using (var bank = ContextFactory.Create(_appSettings.connectionString))
                {
                    tool.isDeleted         = false;
                    tool.dateTimeInclusion = DateTime.Now;
                    bank.Tool.Add(tool);
                    bank.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ShowNotification(NotificationType.Error, $"Erro ao criar ferramenta: {ex.Message}");
                return(View(tool));
            }

            ShowNotificationRedirect(NotificationType.Success, $"Ferramenta criada com sucesso");
            return(RedirectToAction("Index", "Tool"));
        }
 private static void StoresTableShouldBeEmpty()
 {
     using (var context = ContextFactory.Create())
     {
         context.Stores.Should().BeEmpty();
     }
 }
Exemplo n.º 10
0
        public async Task InsertTestCommentAsync()
        {
            // arrange
            CommentModel       retrieved;
            CommentInsertModel inserted;

            using (var contextScope = ContextFactory.Create())
            {
                var activity = await GetTestActivityAsync();

                var person = await GetTestPersonAsync(activityId : activity.ActivityId);

                inserted = new CommentInsertModel()
                {
                    CommentActivityId = activity.ActivityId,
                    CommentPersonId   = person.PersonId,
                    CommentContent    = "Here's a comment from the test method."
                };

                // act
                var newId = await _repository.InsertCommentAsync(inserted);

                retrieved = await DbContext.QuerySingleOrDefaultAsync <CommentModel>($"Select * from Comment where CommentId = {newId}", commandType : CommandType.Text);
            }

            // assert
            Assert.IsTrue(inserted.CommentContent == retrieved.CommentContent, "Comment Content is not equal");
            Assert.IsTrue(inserted.CommentPersonId == retrieved.CommentPersonId, "Comment PersonId is not equal");
            Assert.IsTrue(inserted.CommentActivityId == retrieved.CommentActivityId, "Comment ActivityId is not equal");
        }
Exemplo n.º 11
0
        public List <ActorRole> GetActorRoles(int actorId, bool includeClaims = false)
        {
            using (var context = ContextFactory.Create())
            {
                if (includeClaims)
                {
                    var roles = context.ActorRoles
                                .Include(r => r.Role)
                                .ThenInclude(r => r.RoleClaims)
                                .ThenInclude(rc => rc.Claim)
                                .Where(ar => ar.ActorId == actorId)
                                .ToList();

                    return(roles);
                }
                else
                {
                    var roles = context.ActorRoles
                                .Where(ar => ar.ActorId == actorId)
                                .ToList();

                    return(roles);
                }
            }
        }
        public void UpdatesExistingResponses()
        {
            CreatePersistenceInitializer().Initialize();

            var seededResponses = StoreNumberFactory
                                  .Create(50)
                                  .Select(StoreInfoFactory.Create)
                                  .ToArray();

            _dataService.CreateNew(seededResponses);
            ContainsAllStores(seededResponses).Should().BeTrue();

            var originalResponses = seededResponses.Take(5);


            var updatedResponses = originalResponses
                                   .Select(CreateUpdatedResponse)
                                   .ToArray();

            _dataService.Update(updatedResponses);
            ContainsAllStores(updatedResponses).Should().BeTrue();


            using (var context = ContextFactory.Create())
            {
                context.Stores.Count().Should().Be(50);
                foreach (var r in updatedResponses)
                {
                    context.ShouldContainStoreEquivalentTo(r);
                }
            }

            _dataService.Update(new StoreInfo[] { });
        }
 public List <ActorClaim> GetActorClaims(int actorId)
 {
     using (var context = ContextFactory.Create())
     {
         var claims = context.ActorClaims.Include(c => c.Claim).Where(ac => ac.ActorId == actorId).ToList();
         return(claims);
     }
 }
 public ActorClaim Get(int id)
 {
     using (var context = ContextFactory.Create())
     {
         var claim = context.ActorClaims.Find(id);
         return(claim);
     }
 }
 public List <Claim> Get()
 {
     using (var context = ContextFactory.Create())
     {
         var claims = context.Claims.ToList();
         return(claims);
     }
 }
Exemplo n.º 16
0
 public void Update(ActorData updatedData)
 {
     using (var context = ContextFactory.Create())
     {
         context.ActorData.Update(updatedData);
         context.SaveChanges();
     }
 }
 public List <Role> GetRolesByClaim(int id)
 {
     using (var context = ContextFactory.Create())
     {
         var roles = context.RoleClaims.Where(rc => id == rc.ClaimId).Select(rc => rc.Role).Distinct().ToList();
         return(roles);
     }
 }
 public List <Claim> GetClaimsByRoles(List <int> ids)
 {
     using (var context = ContextFactory.Create())
     {
         var claims = context.RoleClaims.Where(rc => ids.Contains(rc.RoleId)).Select(rc => rc.Claim).Distinct().ToList();
         return(claims);
     }
 }
Exemplo n.º 19
0
 public void Update(Evaluation evaluation)
 {
     using (var context = ContextFactory.Create())
     {
         context.Evaluations.Update(evaluation);
         context.SaveChanges();
     }
 }
 public List <Actor> GetClaimActors(int claimId, int entityId)
 {
     using (var context = ContextFactory.Create())
     {
         var actors = context.ActorClaims.Where(ac => ac.ClaimId == claimId && ac.EntityId == entityId).Select(ac => ac.Actor).Distinct().ToList();
         return(actors);
     }
 }
Exemplo n.º 21
0
 public void Remove(EvaluationData data)
 {
     using (var context = ContextFactory.Create())
     {
         context.EvaluationData.Remove(data);
         context.SaveChanges();
     }
 }
 public Claim Get(ClaimScope scope, string name)
 {
     using (var context = ContextFactory.Create())
     {
         var claim = context.Claims.FirstOrDefault(c => c.ClaimScope == scope && c.Name == name);
         return(claim);
     }
 }
Exemplo n.º 23
0
 public Leaderboard Get(string token, int gameId)
 {
     using (var context = ContextFactory.Create())
     {
         var leaderboard = context.Leaderboards.Find(token, gameId);
         return(leaderboard);
     }
 }
Exemplo n.º 24
0
 public RemoveListingTest()
 {
     // Arrange
     Mediator = new Mock <IMediator>();
     Context  = ContextFactory.Create();
     Logger   = new Mock <ILogger <RemoveListingCommandHandler> >();
     Handler  = new RemoveListingCommandHandler(Mediator.Object, Context, Logger.Object);
 }
 public Role Get(int id)
 {
     using (var context = ContextFactory.Create())
     {
         var role = context.Roles.Find(id);
         return(role);
     }
 }
Exemplo n.º 26
0
 public List <Leaderboard> GetByGame(int gameId)
 {
     using (var context = ContextFactory.Create())
     {
         var leaderboards = context.Leaderboards.Where(l => l.GameId == gameId).ToList();
         return(leaderboards);
     }
 }
 public List <Role> Get(ClaimScope scope)
 {
     using (var context = ContextFactory.Create())
     {
         var roles = context.Roles.Where(r => r.ClaimScope == scope).ToList();
         return(roles);
     }
 }
 public List <Role> Get()
 {
     using (var context = ContextFactory.Create())
     {
         var roles = context.Roles.ToList();
         return(roles);
     }
 }
 public void Create(Actor actor)
 {
     using (var context = ContextFactory.Create())
     {
         context.Actors.Add(actor);
         context.SaveChanges();
     }
 }
 public Actor Get(int id)
 {
     using (var context = ContextFactory.Create())
     {
         var actor = context.Actors.Find(id);
         return(actor);
     }
 }
Exemplo n.º 31
0
        // Context currently instanciated and initializes the context.
        // therefore the test will fail due to insufficient setup.
        // TODO: Make ContextFactory testable.
        public void Create_OsIsWindows_ReturnsWindowsContext()
        {
            // Arrange
            var loader = Substitute.For<ILibraryLoader>();
            var libmapper = Substitute.For<ILibraryInterfaceMapper>();
            var factory = new ContextFactory(loader, libmapper, PlatformID.Win32NT);
        
            // Act
            var context = factory.Create(new ContextCreationParameters{ Device = 1, Window = 1});

            // Assert
            Assert.That(context, Is.InstanceOf<WindowsContext>());
            loader.Received(1).Load("GDI32");
            loader.Received(1).Load("OpenGL32");
        }