public TelemetryServiceFacts()
        {
            _telemetryClient   = new Mock <ITelemetryClient>();
            _configurationMock = new Mock <IOptionsSnapshot <MonitorConfiguration> >();
            _configuration     = new MonitorConfiguration
            {
                Subscription = _subscription,
            };

            _telemetryClient
            .Setup(x => x.TrackMetric(It.IsAny <string>(), It.IsAny <double>(), It.IsAny <IDictionary <string, string> >()))
            .Callback <string, double, IDictionary <string, string> >((_, __, p) => _properties = p);
            _configurationMock
            .Setup(x => x.Value)
            .Returns(() => _configuration);

            _target = new TelemetryService(
                _telemetryClient.Object,
                _configurationMock.Object);
        }
Пример #2
0
        public SearchInstanceRebooterFacts(ITestOutputHelper output)
        {
            _output                    = output;
            _feedClient                = new Mock <IFeedClient>();
            _searchServiceClient       = new Mock <ISearchServiceClient>();
            _azureManagementAPIWrapper = new Mock <IAzureManagementAPIWrapper>();
            _telemetryService          = new Mock <ITelemetryService>();
            _configurationMock         = new Mock <IOptionsSnapshot <MonitorConfiguration> >();
            _configuration             = new MonitorConfiguration
            {
                ProcessLifetime             = TimeSpan.Zero,
                SleepDuration               = TimeSpan.Zero,
                HealthyThresholdInSeconds   = 60,
                UnhealthyThresholdInSeconds = 120,
                Role               = _role,
                Subscription       = _subscription,
                RoleInstanceFormat = "RoleInstance_{0}",
                RegionInformations = new List <RegionInformation>
                {
                    new RegionInformation
                    {
                        Region        = _region,
                        ResourceGroup = _resourceGroup,
                        ServiceName   = _serviceName,
                    },
                },
            };
            _logger = new LoggerFactory()
                      .AddXunit(_output)
                      .CreateLogger <SearchInstanceRebooter>();

            _token     = CancellationToken.None;
            _instances = new List <Instance>
            {
                new Instance(
                    _slot,
                    0,
                    "http://localhost:801/search/diag",
                    "http://localhost:801/query",
                    _region),
                new Instance(
                    _slot,
                    1,
                    "http://localhost:802/search/diag",
                    "http://localhost:802/query",
                    _region),
                new Instance(
                    _slot,
                    2,
                    "http://localhost:803/search/diag",
                    "http://localhost:803/query",
                    _region),
            };
            _feedTimestamp = new DateTimeOffset(2018, 1, 1, 8, 0, 0, TimeSpan.Zero);

            _configurationMock
            .Setup(x => x.Value)
            .Returns(() => _configuration);
            _searchServiceClient
            .Setup(x => x.GetSearchEndpointsAsync(It.IsAny <RegionInformation>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _instances);
            _feedClient
            .Setup(x => x.GetLatestFeedTimeStampAsync())
            .ReturnsAsync(() => _feedTimestamp);

            _target = new SearchInstanceRebooter(
                _feedClient.Object,
                _searchServiceClient.Object,
                _azureManagementAPIWrapper.Object,
                _telemetryService.Object,
                _configurationMock.Object,
                _logger);
        }