Example #1
0
        public void TruncateTimeFrame()
        {
            var expected = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 0, 0, DateTimeKind.Utc));

            Assert.AreEqual(expected, ImpressionsHelper.TruncateTimeFrame(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 53, 12, DateTimeKind.Utc))));
            Assert.AreEqual(expected, ImpressionsHelper.TruncateTimeFrame(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 00, 00, DateTimeKind.Utc))));
            Assert.AreEqual(expected, ImpressionsHelper.TruncateTimeFrame(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 53, 00, DateTimeKind.Utc))));
            Assert.AreEqual(expected, ImpressionsHelper.TruncateTimeFrame(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 00, 12, DateTimeKind.Utc))));

            expected = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 00, 00, 00, DateTimeKind.Utc));
            Assert.AreEqual(expected, ImpressionsHelper.TruncateTimeFrame(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 00, 00, 00, DateTimeKind.Utc))));
        }
Example #2
0
        public void Start_ShouldSendImpressionsCount()
        {
            // Arrange.
            var impressionsCounter = new ImpressionsCounter();

            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 15, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 50, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature2", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 50, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature3", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 50, 11, DateTimeKind.Utc)));

            var impressionsCountSender = new ImpressionsCountSender(_apiClient.Object, impressionsCounter, 1);

            // Act.
            impressionsCountSender.Start();

            // Assert.
            Thread.Sleep(1500);
            _apiClient.Verify(mock => mock.SendBulkImpressionsCount(It.IsAny <ConcurrentDictionary <KeyCache, int> >()), Times.Once);
        }
        public void CorrectFormatSendCounts()
        {
            // Arrange.
            var time9am  = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 00, 00, DateTimeKind.Utc));
            var time10am = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 00, 00, DateTimeKind.Utc));

            var impressions = new ConcurrentDictionary <KeyCache, int>();

            impressions.TryAdd(new KeyCache("featur1", time9am), 2);

            var treatmentSdkApiClient = new TreatmentSdkApiClient(new HTTPHeader(), "http://www.fake-test-split.com", 5, 5);

            // Act.
            var result = treatmentSdkApiClient.ConvertToJson(impressions);

            // Assert.
            var expected = $"{{\"pf\":[{{\"f\":\"featur1\",\"m\":{time9am},\"rc\":2}}]}}";

            Assert.AreEqual(expected, result);
        }
        public void IncBasicUsage()
        {
            // Arrange.
            var impressionsCounter = new ImpressionsCounter();

            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 15, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 20, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 50, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature2", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 50, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature2", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 55, 11, DateTimeKind.Utc)));
            impressionsCounter.Inc("feature1", SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 50, 11, DateTimeKind.Utc)));

            // Act.
            var result = impressionsCounter.PopAll();

            // Assert.
            Assert.AreEqual(3, result.FirstOrDefault(x => x.Key.SplitName.Equals("feature1") && x.Key.TimeFrame.Equals(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 0, 0, DateTimeKind.Utc)))).Value);
            Assert.AreEqual(2, result.FirstOrDefault(x => x.Key.SplitName.Equals("feature2") && x.Key.TimeFrame.Equals(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 0, 0, DateTimeKind.Utc)))).Value);
            Assert.AreEqual(1, result.FirstOrDefault(x => x.Key.SplitName.Equals("feature1") && x.Key.TimeFrame.Equals(SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 0, 0, DateTimeKind.Utc)))).Value);
        }
Example #5
0
        public void CorrectFormatSendCounts()
        {
            // Arrange.
            var time9am  = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 09, 00, 00, DateTimeKind.Utc));
            var time10am = SplitsHelper.MakeTimestamp(new DateTime(2020, 09, 02, 10, 00, 00, DateTimeKind.Utc));

            var impressions = new ConcurrentDictionary <KeyCache, int>();

            impressions.TryAdd(new KeyCache("featur1", time9am), 2);

            var telemetryStorage        = new InMemoryTelemetryStorage();
            var impressionsSdkApiClient = new ImpressionsSdkApiClient(string.Empty, new Dictionary <string, string>(), "http://www.fake-test-split.com", 5, 5, telemetryStorage, _wrapperAdapter, 5);

            // Act.
            var result = impressionsSdkApiClient.ConvertToJson(impressions);

            // Assert.
            var expected = $"{{\"pf\":[{{\"f\":\"featur1\",\"m\":{time9am},\"rc\":2}}]}}";

            Assert.AreEqual(expected, result);
        }