コード例 #1
0
        public async Task <IEnumerable <TEntity> > Query(IQueryCollection query)
        {
            if (!RepositoryUtils.isQueryValid <TEntity>(query))
            {
                throw new Utils.NotValidQueryException("not a valid query");
            }
            var builder = Builders <TEntity> .Filter;
            FilterDefinition <TEntity> filter = Builders <TEntity> .Filter.Empty;
            int count = 0;

            foreach (var item in query)
            {
                if (count == 0)
                {
                    filter = builder.Eq(item.Key, item.Value);
                }
                else
                {
                    filter = filter & builder.Eq(item.Key, item.Value);
                }
                count++;
            }
            var ent = await _dbCollection.FindAsync(filter).Result.ToListAsync();

            return(ent);
        }
コード例 #2
0
 public Customer?CreateCustomer(Customer customer)
 {
     customer.CustomerId   = RepositoryUtils.GetPrimaryKey();
     customer.RewardPoints = 500;
     customer.Status       = MemberStatus.Bronze;
     return(_dataStore.TryAdd(customer.CustomerId, customer) ? customer : null);
 }
コード例 #3
0
        public async Task should_not_return_null_when_service_has_no_active_endpoints()
        {
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Name      = "lorem",
                Endpoints = new[]
                {
                    new Mongo.Infrastructure.Entities.ServiceEndpoint()
                    {
                        Id      = Guid.NewGuid(),
                        Active  = false,
                        Address = "localhost"
                    }
                }
            };
            var mockRepo = RepositoryUtils.MockRepository(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var query = new FindService(service.Id);

            var sut    = new FindServiceHandler(mockDbContext.Object);
            var result = await sut.Handle(query);

            result.Should().NotBeNull();
            result.Name.ShouldBeEquivalentTo(service.Name);
            result.Endpoints.Should().NotBeNullOrEmpty();
        }
コード例 #4
0
ファイル: ContextExtensions.cs プロジェクト: paweld139/PDCore
 public static void SetLogging(this DbContext dbContext, bool input, ILogger logger, bool isLoggingEnabled)
 {
     RepositoryUtils.SetLogging(input, logger, isLoggingEnabled,
                                () => dbContext.Database.Log = logger.Info,
                                () => dbContext.Database.Log = null
                                );
 }
コード例 #5
0
        public async Task should_succeed_when_endpoint_not_found()
        {
            var endpoint = new Mongo.Infrastructure.Entities.ServiceEndpoint()
            {
                Id       = Guid.NewGuid(),
                Address  = "ipsum",
                Protocol = "dolor",
                Active   = false
            };

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = false,
                Name      = "lorem",
                Endpoints = new[] { endpoint }
            };
            var mockRepo = RepositoryUtils.MockRepository(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var sut    = new AddEndpointValidator(mockDbContext.Object);
            var result = await sut.ValidateAsync(new AddEndpoint(service.Id, Guid.NewGuid(), endpoint.Protocol, Guid.NewGuid().ToString()));

            result.Success.Should().BeTrue();
        }
コード例 #6
0
        public async Task should_fail_when_endpoint_already_exists_by_address_and_protocol()
        {
            var endpoint = new Mongo.Infrastructure.Entities.ServiceEndpoint()
            {
                Id       = Guid.NewGuid(),
                Address  = "ipsum",
                Protocol = "dolor",
                Active   = false
            };
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = false,
                Name      = "lorem",
                Endpoints = new[] { endpoint }
            };
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var sut    = new AddEndpointValidator(mockDbContext.Object);
            var result = await sut.ValidateAsync(new AddEndpoint(service.Id, Guid.NewGuid(), endpoint.Protocol, endpoint.Address));

            result.Success.Should().BeFalse();
            result.Errors.Any(e => e.Context == "endpoint" && e.Message.Contains(endpoint.Address)).Should().BeTrue();
        }
コード例 #7
0
        public async Task should_update_service_when_found_with_no_endpoints()
        {
            var command = new AddEndpoint(Guid.NewGuid(), Guid.NewGuid(), "ipsum", "dolor");

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = command.ServiceId,
                Name      = "lorem",
                Active    = false,
                Endpoints = null
            };

            var mockRepo = RepositoryUtils.MockRepository(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var validator = new NullValidator <AddEndpoint>();

            var sut = new AddEndpointHandler(mockDbContext.Object, validator);
            await sut.Handle(command);

            mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(),
                                                  It.Is <Mongo.Infrastructure.Entities.Service>(r =>
                                                                                                r.Id == command.ServiceId &&
                                                                                                r.Active == false &&
                                                                                                null != r.Endpoints && 1 == r.Endpoints.Count() &&
                                                                                                r.Endpoints.Any(es => es.Active == false &&
                                                                                                                es.Id == command.EndpointId &&
                                                                                                                es.Address == command.Address &&
                                                                                                                es.Protocol == command.Protocol))
                                                  ), Times.Once());
        }
コード例 #8
0
 public void SetLogging(bool input, ILogger logger)
 {
     RepositoryUtils.SetLogging(input, logger, IsLoggingEnabled,
                                () => Logger = logger,
                                () => Logger = null
                                );
 }
コード例 #9
0
        public async Task should_delete_service_when_input_valid()
        {
            var startTicks = DateTime.UtcNow.Ticks;

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = true,
                Name      = "lorem",
                Endpoints = Enumerable.Empty <Mongo.Infrastructure.Entities.ServiceEndpoint>()
            };
            var mockServicesRepo = RepositoryUtils.MockRepository(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockServicesRepo.Object);

            var validator = new NullValidator <DeleteService>();

            var sut = new DeleteServiceHandler(mockDbContext.Object, validator);

            await sut.Handle(new DeleteService(service.Id));

            mockServicesRepo.Verify(m => m.DeleteOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >()), Times.Once());
        }
コード例 #10
0
        public async Task should_emit_ServiceRefreshed_event_even_with_no_endpoints()
        {
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = true,
                Name      = "lorem",
                Endpoints = new Mongo.Infrastructure.Entities.ServiceEndpoint[] { }
            };

            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var mockMediator = new Mock <IMediator>();

            var mockPinger = new Mock <IPinger>();

            var validator = new NullValidator <RefreshServiceStatus>();

            var command = new RefreshServiceStatus(service.Id, 10);
            var sut     = new RefreshServiceStatusHandler(mockDbContext.Object, mockPinger.Object, mockMediator.Object, validator);
            await sut.Handle(command);

            mockMediator.Verify(m => m.Publish(It.Is <Core.Events.ServiceRefreshed>(e => e.ServiceId == service.Id),
                                               It.IsAny <System.Threading.CancellationToken>()),
                                Times.Once);
        }
コード例 #11
0
        public async Task should_deactivate_service_when_no_endpoints_available()
        {
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = true,
                Name      = "lorem",
                Endpoints = Enumerable.Empty <Mongo.Infrastructure.Entities.ServiceEndpoint>()
            };
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var mockPinger   = new Mock <IPinger>();
            var mockMediator = new Mock <IMediator>();
            var validator    = new NullValidator <RefreshServiceStatus>();

            var sut = new RefreshServiceStatusHandler(mockDbContext.Object, mockPinger.Object, mockMediator.Object, validator);
            await sut.Handle(new RefreshServiceStatus(service.Id, 10));

            mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(),
                                                  It.Is <Mongo.Infrastructure.Entities.Service>(r => r.Active == false)),
                            Times.Once());
        }
コード例 #12
0
        private void prepareDependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AssetsTestModule(_configBuilder));
            container = builder.Build();

            AssetRepository           = RepositoryUtils.ResolveGenericRepository <AssetEntity, IAsset>(container);
            AssetExtendedInfosManager = RepositoryUtils.ResolveGenericRepository <AssetExtendedInfosEntity, IAssetExtendedInfo>(container);
            AssetCategoryManager      = RepositoryUtils.ResolveGenericRepository <AssetCategoryEntity, IAssetCategory>(container);
            AssetAttributesManager    = container.Resolve <IDictionaryRepository <IAssetAttributes> >() as AssetAttributesRepository;
            AssetGroupsManager        = RepositoryUtils.ResolveGenericRepository <AssetGroupEntity, IAssetGroup>(container);

            AssetAttributesRepository = container.Resolve <IDictionaryRepository <IAssetAttributes> >() as AssetAttributesRepository;
            AssetGroupsRepository     = RepositoryUtils.ResolveGenericRepository <AssetGroupEntity, IAssetGroup>(container);

            AssetPairManager       = RepositoryUtils.ResolveGenericRepository <AssetPairEntity, IAssetPair>(container);
            AssetSettingsManager   = RepositoryUtils.ResolveGenericRepository <AssetSettingsEntity, IAssetSettings>(container);
            AssetIssuersManager    = RepositoryUtils.ResolveGenericRepository <AssetIssuersEntity, IAssetIssuers>(container);
            MarginAssetPairManager = RepositoryUtils.ResolveGenericRepository <MarginAssetPairsEntity, IMarginAssetPairs>(container);
            MarginAssetManager     = RepositoryUtils.ResolveGenericRepository <MarginAssetEntity, IMarginAsset>(container);
            MarginIssuerManager    = RepositoryUtils.ResolveGenericRepository <MarginIssuerEntity, IMarginIssuer>(container);

            WatchListRepository = container.Resolve <IDictionaryRepository <IWatchList> >() as WatchListRepository;
        }
コード例 #13
0
        public virtual async Task <bool> UpdateAsync <T>(T dataInfo) where T : Entity
        {
            if (dataInfo == null || dataInfo.Id <= 0)
            {
                return(false);
            }

            if (!Utilities.IsGuid(dataInfo.Guid))
            {
                dataInfo.Guid = Utilities.GetGuid();
            }
            dataInfo.LastModifiedDate = DateTime.Now;

            var query = Q.Where(nameof(Entity.Id), dataInfo.Id);

            foreach (var tableColumn in TableColumns)
            {
                if (Utilities.EqualsIgnoreCase(tableColumn.AttributeName, nameof(Entity.Id)))
                {
                    continue;
                }

                var value = ValueUtils.GetSqlValue(dataInfo, tableColumn);

                query.Set(tableColumn.AttributeName, value);
            }

            return(await RepositoryUtils.UpdateAllAsync(Database, TableName, Redis, query) > 0);
        }
コード例 #14
0
        public async Task should_create_trace_data_when_input_valid()
        {
            var startTicks = DateTime.UtcNow.Ticks;

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = true,
                Name      = "lorem",
                Endpoints = Enumerable.Empty <Mongo.Infrastructure.Entities.ServiceEndpoint>()
            };
            var mockServicesRepo = RepositoryUtils.MockRepository(service);

            var mockEventsRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.TraceEvent>();

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockServicesRepo.Object);
            mockDbContext.Setup(db => db.TraceEvents).Returns(mockEventsRepo.Object);

            var @event = new ServiceRefreshed(service.Id);
            var sut    = new ServiceRefreshedHandler(mockDbContext.Object);
            await sut.Handle(@event);

            mockEventsRepo.Verify(m => m.InsertOneAsync(It.Is <Mongo.Infrastructure.Entities.TraceEvent>(
                                                            te => te.Id != Guid.Empty &&
                                                            te.CreationDate >= startTicks &&
                                                            te.Name == Core.TraceEventNames.ServiceRefreshed &&
                                                            te.CustomData == service
                                                            )
                                                        ), Times.Once);
        }
コード例 #15
0
        public virtual bool Update <T>(T dataInfo) where T : Entity
        {
            if (dataInfo == null || dataInfo.Id <= 0)
            {
                return(false);
            }

            if (!Utilities.IsGuid(dataInfo.Guid))
            {
                dataInfo.Guid = Utilities.GetGuid();
            }
            dataInfo.LastModifiedDate = DateTime.Now;

            var query = Q.Where(nameof(Entity.Id), dataInfo.Id);

            foreach (var tableColumn in TableColumns)
            {
                if (Utilities.EqualsIgnoreCase(tableColumn.AttributeName, nameof(Entity.Id)))
                {
                    continue;
                }

                var value = tableColumn.IsExtend
                    ? Utilities.JsonSerialize(dataInfo.ToDictionary(dataInfo.GetColumnNames()))
                    : dataInfo.Get(tableColumn.AttributeName);

                query.Set(tableColumn.AttributeName, value);
            }

            return(RepositoryUtils.UpdateAll(DatabaseType, ConnectionString, TableName, query) > 0);
        }
コード例 #16
0
        private void PrepareDependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AlgoStoreTestModule(_configBuilder));
            _container = builder.Build();


            var builderDB = new ContainerBuilder();

            builderDB.RegisterModule(new AlgoStoreTestModule(_configBuilderDB));
            _containerDB = builderDB.Build();

            this.MetaDataRepository                  = RepositoryUtils.ResolveGenericRepository <MetaDataEntity, IMetaData>(this._containerDB);
            this.RuntimeDataRepository               = RepositoryUtils.ResolveGenericRepository <RuntimeDataEntity, IStatistics>(this._containerDB);
            this.ClientInstanceRepository            = RepositoryUtils.ResolveGenericRepository <ClientInstanceEntity, IClientInstance>(this._containerDB);
            this.AlgoRatingsRepository               = RepositoryUtils.ResolveGenericRepository <AlgoRatingsTableEntity, IAlgoRatingsTable>(this._containerDB);
            this.AlgoApiLogRepository                = RepositoryUtils.ResolveGenericRepository <AlgoStoreApiLogEntity, IAlgoStoreApiLog>(this._containerDB);
            this.CSharpAlgoTemplateLogRepository     = RepositoryUtils.ResolveGenericRepository <CSharpAlgoTemplateLogEntity, ICSharpAlgoTemplateLog>(this._containerDB);
            this.CSharpAlgoTemplateUserLogRepository = RepositoryUtils.ResolveGenericRepository <CSharpAlgoTemplateUserLogEntity, ICSharpAlgoTemplateUserLog>(this._containerDB);
            this.PublicAlgosRepository               = RepositoryUtils.ResolveGenericRepository <PublicsAlgosTableEntity, IPublicAlgosTable>(this._containerDB);
            this.StatisticsRepository                = RepositoryUtils.ResolveGenericRepository <StatisticsEntity, IStatisticss>(this._containerDB);
            this.BlobRepository = new AlgoBlobRepository(_configBuilderDB.Config["TableStorageConnectionString"], timespan);
            this.AlgoInstanceStaticsticsRepository = RepositoryUtils.ResolveGenericRepository <AlgoInstanceStatisticsEntity, IAlgoInstanceStatistics>(this._containerDB);
        }
コード例 #17
0
        public void TestTableName()
        {
            AModel model     = new AModel();
            string tableName = RepositoryUtils <AModel> .GetTableNameFromModel(model);

            Assert.IsTrue(!string.IsNullOrEmpty(tableName), "Error the tableName is null");
            Assert.IsTrue(tableName?.Equals("model_exemple"), $"Expected value => model_exemple and received => {tableName}");
        }
コード例 #18
0
        public async Task <bool> RemoveSmackUser(string id)
        {
            var objectId = RepositoryUtils.GetObjectId(id);

            var actionResult = await _smackUserContext.SmackUsers.DeleteOneAsync(Builders <SmackUser> .Filter.Eq("Id", objectId));

            return(actionResult.IsAcknowledged && actionResult.DeletedCount > 0);
        }
コード例 #19
0
        public async Task should_activate_service_when_at_least_one_endpoint_responds_to_ping()
        {
            var endpoint1 = new Mongo.Infrastructure.Entities.ServiceEndpoint()
            {
                Address  = "localhost1",
                Protocol = "dolor",
                Active   = true
            };
            var endpoint2 = new Mongo.Infrastructure.Entities.ServiceEndpoint()
            {
                Address  = "localhost2",
                Protocol = "dolor",
                Active   = true
            };

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = false,
                Name      = "lorem",
                Endpoints = new[] {
                    endpoint1, endpoint2
                }
            };
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var mockPinger = new Mock <IPinger>();

            mockPinger.Setup(p => p.PingAsync(It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync((string Address, int timeout) =>
            {
                return(new PingResult((Address == endpoint2.Address), 0));
            });

            var mockMediator = new Mock <IMediator>();

            var validator = new NullValidator <RefreshServiceStatus>();

            var command = new RefreshServiceStatus(service.Id, 10);
            var sut     = new RefreshServiceStatusHandler(mockDbContext.Object, mockPinger.Object, mockMediator.Object, validator);
            await sut.Handle(command);

            foreach (var endpoint in service.Endpoints)
            {
                mockPinger.Verify(m => m.PingAsync(endpoint.Address, command.Timeout), Times.Once());
            }

            mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(),
                                                  It.Is <Mongo.Infrastructure.Entities.Service>(r => r.Active == true && 1 == r.Endpoints.Count(es => es.Active && es.Address == endpoint2.Address))),
                            Times.Once());
        }
コード例 #20
0
        private void PrepareDependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new BlueApiTestModule(_appSettings));
            _container = builder.Build();

            PledgeRepository       = RepositoryUtils.ResolveGenericRepository <PledgeEntity, IPledgeEntity>(this._container);
            PersonalDataRepository = RepositoryUtils.ResolveGenericRepository <PersonalDataEntity, IPersonalData>(this._container);
            ReferralLinkRepository = RepositoryUtils.ResolveGenericRepository <ReferralLinkEntity, IReferralLink>(this._container);
        }
コード例 #21
0
        public virtual T Get <T>(Query query = null)
        {
            var value = RepositoryUtils.GetValue <T>(DatabaseType, ConnectionString, TableName, query);

            if (typeof(T).IsAssignableFrom(typeof(Entity)))
            {
                RepositoryUtils.SyncAndCheckGuid(DatabaseType, ConnectionString, TableName, value as Entity);
            }

            return(value);
        }
コード例 #22
0
        public virtual async Task <T> GetAsync <T>(Query query = null)
        {
            var value = await RepositoryUtils.GetValueAsync <T>(Database, TableName, Redis, query);

            if (typeof(T).IsAssignableFrom(typeof(Entity)))
            {
                await RepositoryUtils.SyncAndCheckGuidAsync(Database, TableName, Redis, value as Entity);
            }

            return(value);
        }
コード例 #23
0
        public async Task InsertAsync(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"INSERT INTO {tableName}";
            await db.QueryAsync <T>(sql, model);
        }
コード例 #24
0
        public async Task DeleteAsync(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"DELETE FROM {tableName} WHERE id = {model.ID}";
            await db.QueryAsync <T>(sql, model);
        }
        private void PrepareDependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AlgoStoreTestModule(_configBuilder));
            _container = builder.Build();

            this.MetaDataRepository       = RepositoryUtils.ResolveGenericRepository <MetaDataEntity, IMetaData>(this._container);
            this.RuntimeDataRepository    = RepositoryUtils.ResolveGenericRepository <RuntimeDataEntity, IRuntimeData>(this._container);
            this.ClientInstanceRepository = RepositoryUtils.ResolveGenericRepository <ClientInstanceEntity, IClientInstance>(this._container);
            this.BlobRepository           = new AlgoBlobRepository(_configBuilder.Config["MainConnectionString"], timespan);
        }
コード例 #26
0
        public static void Init()
        {
            /*registrazioni */
            var container = Container.GetInstance();

            container.Register <AuthenticationService>(Lifestyle.Singleton);
            container.Register <UserService>(Lifestyle.Singleton);
            container.Register <MapService>(Lifestyle.Singleton);
            container.Register <PositionService>(Lifestyle.Singleton);
            container.Register <RoomService>(Lifestyle.Singleton);
            RepositoryUtils.Init();
        }
コード例 #27
0
        public async Task should_not_create_service_health_data_when_found()
        {
            var now   = DateTime.UtcNow;
            var start = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, DateTimeKind.Utc);

            var service = new Heimdall.Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = true,
                Name      = "lorem",
                Endpoints = Enumerable.Empty <Heimdall.Mongo.Infrastructure.Entities.ServiceEndpoint>()
            };
            var mockRepo = RepositoryUtils.MockRepository(service);

            var mockEventsRepo = RepositoryUtils.MockRepository <Heimdall.Mongo.Infrastructure.Entities.TraceEvent>();

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);
            mockDbContext.Setup(db => db.TraceEvents).Returns(mockEventsRepo.Object);

            var serviceHealth = new Infrastructure.Entities.ServiceHealth()
            {
                ServiceId       = service.Id,
                TimestampMinute = start.Ticks
            };
            var mockServicesHealthRepo = RepositoryUtils.MockRepository <Infrastructure.Entities.ServiceHealth>();

            mockServicesHealthRepo.Setup(r => r.FindOneAndUpdateAsync(It.IsAny <Expression <Func <Infrastructure.Entities.ServiceHealth, bool> > >(),
                                                                      It.IsAny <MongoDB.Driver.UpdateDefinition <Infrastructure.Entities.ServiceHealth> >()))
            .ReturnsAsync((Expression <Func <Infrastructure.Entities.ServiceHealth, bool> > filter, MongoDB.Driver.UpdateDefinition <Infrastructure.Entities.ServiceHealth> update) =>
            {
                return(serviceHealth);
            });

            var mockAnalyticsDb = new Mock <IAnalyticsDbContext>();

            mockAnalyticsDb.Setup(db => db.ServicesHealth).Returns(mockServicesHealthRepo.Object);

            var @event = new ServiceRefreshed(service.Id);
            var sut    = new ServiceRefreshedHandler(mockDbContext.Object, mockAnalyticsDb.Object);
            await sut.Handle(@event);

            mockServicesHealthRepo.Verify(m => m.InsertOneAsync(It.Is <Infrastructure.Entities.ServiceHealth>(
                                                                    sh => null != sh &&
                                                                    sh.ServiceId == service.Id &&
                                                                    sh.TimestampMinute >= start.Ticks &&
                                                                    null != sh.Details &&
                                                                    sh.Details.Count() == 1
                                                                    )
                                                                ), Times.Never);
        }
コード例 #28
0
        private void prepareDependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new MatchingEngineTestModule(_configBuilder));
            this.container = builder.Build();

            this.AccountRepository      = RepositoryUtils.ResolveGenericRepository <AccountEntity, IAccount>(this.container);
            this.CashSwapRepository     = RepositoryUtils.ResolveGenericRepository <CashSwapEntity, ICashSwap>(this.container);
            this.AssetPairsRepository   = RepositoryUtils.ResolveGenericRepository <AssetPairEntity, IAssetPair>(this.container);
            this.MarketOrdersRepository = RepositoryUtils.ResolveGenericRepository <MarketOrderEntity, IMarketOrderEntity>(this.container);
            this.LimitOrdersRepository  = RepositoryUtils.ResolveGenericRepository <LimitOrderEntity, ILimitOrderEntity>(this.container);
        }
コード例 #29
0
        public void Delete(T model)
        {
            if (!CanExecute)
            {
                return;
            }

            string tableName = RepositoryUtils <T> .GetTableNameFromModel(model);

            string sql = $"DELETE FROM {tableName} WHERE id = {model.ID}";

            db.Query <T>(sql, model);
        }
コード例 #30
0
        public async Task should_succeed_when_service_not_found()
        {
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>();

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var sut    = new CreateServiceValidator(mockDbContext.Object);
            var result = await sut.ValidateAsync(new CreateService(System.Guid.NewGuid(), "lorem"));

            result.Success.Should().BeTrue();
        }
コード例 #31
0
        private void CheckItemCommentForRequiredValues(ItemCommentEntity ic, RepositoryUtils.RepositoryAction action)
        {
            List<string> missingFields = new List<string>();

            //if (String.IsNullOrWhiteSpace(p.userName)) missingFields.Add("User Name");
            //if (String.IsNullOrWhiteSpace(p.emailAddress)) missingFields.Add("Email Address");
            //if (String.IsNullOrWhiteSpace(p.firstName)) missingFields.Add("First Name");
            //if (String.IsNullOrWhiteSpace(p.lastName)) missingFields.Add("Last Name");
            //if (String.IsNullOrWhiteSpace(p.passwordHash)) missingFields.Add("Password");

            if (missingFields.Count > 0)
            {
                throw new Exception(String.Format("Cannot {0} Person: Missing Fields {1}", action.ToString(), String.Join(", ", missingFields.ToArray())));
            }
        }