public void EditSubscribeTest()
        {
            //ARRANGE
            RepositoryEditItem <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> > repositoryItem = new RepositoryEditItem <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context);

            MemoryCacheRepository <ObjectMappingForTest> cacheTestClass = new MemoryCacheRepository <ObjectMappingForTest>();
            HandlerCRUD <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> > processingObjectTestCalss = new HandlerCRUD <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> >(repositoryItem);
            FetchDomainData <ObjectMappingForTest> fetchDomainDataTestClass = new FetchDomainData <ObjectMappingForTest>(_uow);

            //ACT
            CacheCRUDBLLDecorator <ObjectMappingForTest, EditParamOfCRUDOperation <ObjectMappingForTest> > processingObjectCacheDecorator = new EditCacheCRUDBLLDecorator <ObjectMappingForTest>(processingObjectTestCalss, cacheTestClass);
            var resultSave = processingObjectCacheDecorator.Execute(new EditParamOfCRUDOperation <ObjectMappingForTest>()
            {
                Item = new ObjectMappingForTest()
                {
                    Id = 1, IntValue = 22, IntValue2 = 33
                }
            }).Result;


            ObjectMappingForTest resultFromCache = cacheTestClass.GetByIdAsync(1).Result;
            ObjectMappingForTest resultFromDB    = fetchDomainDataTestClass.GetByIdAsync(1).Result;


            //ASSERT
            Assert.IsNotNull(resultFromCache);                                //В кеше есть данные

            Assert.AreEqual(resultFromDB.IntValue, resultFromCache.IntValue); //Проверка, что данные добавленные одинаковые
            Assert.AreEqual(resultFromDB.IntValue2, resultFromCache.IntValue2);
            Assert.AreEqual(33, resultFromDB.IntValue2);
        }
Exemplo n.º 2
0
 public void SetUp()
 {
     _configuration = MockRepository.GenerateMock <IAntiCsrfConfiguration>();
     _configuration.Stub(arg => arg.MemoryCacheName).Return("cache");
     _repository = new MemoryCacheRepository(_configuration);
     _sessionId  = Guid.Parse("710f7634-b013-4fb8-abf5-97c98e4993c3");
     _nonce      = Guid.Parse("0dd344d0-7115-4c0e-864a-afaecb339138");
     _repository.AddAsync(_sessionId, _nonce, DateTime.UtcNow, DateTime.MaxValue.ToUniversalTime());
 }
Exemplo n.º 3
0
        public CustomThrottlingHandler()
            : base( )
        {
            base.Policy = new ThrottlePolicy(1, 3)
            {
                IpThrottling = true,
                //scope to clients
                ClientThrottling = true,

                EndpointThrottling = true
            };
            Repository = new MemoryCacheRepository();
        }
        public void DeleteInCacheAndDataBaseTest()
        {
            //ARRANGE
            RepositoryAddItem <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >       repositoryAddItem    = new RepositoryAddItem <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context);
            RepositoryDeleteItem <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> > repositoryDeleteItem = new RepositoryDeleteItem <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context);

            MemoryCacheRepository <ObjectMappingForTest> cacheTestClass = new MemoryCacheRepository <ObjectMappingForTest>();
            HandlerCRUD <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >    processingObjectTestCalss       = new HandlerCRUD <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(repositoryAddItem);
            HandlerCRUD <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> > processingDeleteObjectTestClass = new HandlerCRUD <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> >(repositoryDeleteItem);
            FetchDomainData <ObjectMappingForTest> fetchDomainDataTestClass = new FetchDomainData <ObjectMappingForTest>(_uow);

            //ACT
            CacheCRUDBLLDecorator <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >    processingObjectCacheDecorator       = new AddCacheCRUDBLLDecorator <ObjectMappingForTest>(processingObjectTestCalss, cacheTestClass);
            CacheCRUDBLLDecorator <ObjectMappingForTest, DeleteParamOfCRUDOperation <ObjectMappingForTest> > processingDeleteObjectCacheDecorator = new DeleteCacheCRUDBLLDecorator <ObjectMappingForTest>(processingDeleteObjectTestClass, cacheTestClass);

            var resultSave = processingObjectCacheDecorator.Execute(new AddParamOfCRUDOperation <ObjectMappingForTest>()
            {
                Item = new ObjectMappingForTest()
                {
                    IntValue = 2222, IntValue2 = 3333
                }
            }).Result;


            ObjectMappingForTest resultFromCache = cacheTestClass.GetByIdAsync(2).Result;
            ObjectMappingForTest resultFromDB    = fetchDomainDataTestClass.GetByIdAsync(2).Result;

            //ASSERT
            Assert.IsNotNull(resultFromCache);                                //В кеше есть данные

            Assert.AreEqual(resultFromDB.IntValue, resultFromCache.IntValue); //Проверка, что данные добавленные одинаковые
            Assert.AreEqual(resultFromDB.IntValue2, resultFromCache.IntValue2);
            Assert.AreEqual(3333, resultFromDB.IntValue2);



            //ACT - Удаляем данные
            resultSave = processingDeleteObjectCacheDecorator.Execute(new DeleteParamOfCRUDOperation <ObjectMappingForTest>()
            {
                Item = new ObjectMappingForTest()
                {
                    Id = 2
                }
            }).Result;
            resultFromCache = cacheTestClass.GetByIdAsync(3).Result;
            var exArgumentException = Assert.ThrowsExceptionAsync <ArgumentException>(() => fetchDomainDataTestClass.GetByIdAsync(3));

            //ASSERT
            Assert.IsNull(resultFromCache);//В кеше есть данные
        }
Exemplo n.º 5
0
        protected override RequestIdentity SetIdentity(HttpRequestMessage request)
        {
            var identity = (ClaimsIdentity)Thread.CurrentPrincipal.Identity;
            var claims   = identity.Claims.ToList();

            var porMinuto = string.IsNullOrEmpty(claims.FirstOrDefault(c => c.Type == "porMinuto")?.Value) ? 3 : Convert.ToInt64(claims.FirstOrDefault(c => c.Type == "porMinuto")?.Value);
            var porHora   = string.IsNullOrEmpty(claims.FirstOrDefault(c => c.Type == "porHora")?.Value) ? 60 : Convert.ToInt64(claims.FirstOrDefault(c => c.Type == "porHora")?.Value);

            base.Policy = new ThrottlePolicy(null, porMinuto, porHora)
            {
                IpThrottling = true,
                //scope to clients
                ClientThrottling = true,

                EndpointThrottling = true
            };
            Repository = new MemoryCacheRepository();


            return(base.SetIdentity(request));
        }
        public void CheckWorkWithCacheTest()
        {
            //ARRANGE
            RepositoryAddItem <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> > repositoryAddItem = new RepositoryAddItem <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(_uow, context);

            MemoryCacheRepository <ObjectMappingForTest> cacheTestClass = new MemoryCacheRepository <ObjectMappingForTest>();
            HandlerCRUD <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> > processingObjectTestCalss = new HandlerCRUD <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> >(repositoryAddItem);
            FetchDomainData <ObjectMappingForTest> fetchDomainDataTestClass = new FetchDomainData <ObjectMappingForTest>(_uow);


            //ACT
            CacheCRUDBLLDecorator <ObjectMappingForTest, AddParamOfCRUDOperation <ObjectMappingForTest> > processingObjectCacheDecorator = new AddCacheCRUDBLLDecorator <ObjectMappingForTest>(processingObjectTestCalss, cacheTestClass);
            ObjectMappingForTest resultFromCache = cacheTestClass.GetByIdAsync(1).Result;
            ObjectMappingForTest resultFromDB    = fetchDomainDataTestClass.GetByIdAsync(1).Result;


            //ASSERT
            Assert.IsNull(resultFromCache); //В "БД" есть запись, но в кеше нет ее;

            Assert.IsNotNull(resultFromDB); //В "БД" есть запись
        }
Exemplo n.º 7
0
        protected override void SetupThrottling(Owin.IAppBuilder app)
        {
            MemoryCacheRepository cache = new MemoryCacheRepository();

            cache.Clear();
            app.Use(typeof(CustomThrottlingMiddleware), new ThrottlePolicy(perHour: 600)
            {
                IpThrottling     = false,
                ClientThrottling = true,
                ClientRules      = new Dictionary <string, RateLimits>
                {
                    { CustomThrottlingMiddleware.IS_AUTHENTICATE, new RateLimits {
                          PerHour = 4000
                      } }
                },
                EndpointThrottling = true,
                EndpointRules      = new Dictionary <string, RateLimits>()
                {
                    { "api/ip", new RateLimits {
                          PerMinute = 2
                      } }
                }
            }, new PolicyMemoryCacheRepository(), cache, new ThrottlingLogger());
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     _configuration = MockRepository.GenerateMock <IAntiCsrfConfiguration>();
     _configuration.Stub(arg => arg.MemoryCacheName).Return("cache");
     _repository = new MemoryCacheRepository(_configuration);
 }