public void DateTimeIsNotOverridenIfAlreadySupplied()
        {
            var provider = Substitute.For <IPropertiesProvider>();
            var options  = Substitute.For <IMixpanelOptions>();

            options.Enabled.Returns(true);

            var eventTracker = Substitute.For <IEventTracker>();
            var timeProvider = Substitute.For <ITimeProvider>();

            timeProvider.UtcTime.Returns(DateTime.UtcNow);

            var service = new MixpanelService(options, provider, timeProvider, eventTracker);

            service.SendEvent("testEvent", new Dictionary <string, object> {
                { EventProperties.DateTime, new DateTime(2010, 12, 31, 13, 59, 30, DateTimeKind.Utc) }
            });

            eventTracker.Received().Track(
                Arg.Is("testEvent"),
                Arg.Is <IDictionary <string, object> >(
                    p => p.ContainsKey(EventProperties.DateTime) &&
                    DateTime.Equals((DateTime)p[EventProperties.DateTime], new DateTime(2010, 12, 31, 13, 59, 30, DateTimeKind.Utc))
                    ));
        }
        public void TrackEventSendsEventPropertyToTracker()
        {
            MixpanelOptions options = new MixpanelOptions
            {
                Enabled = true
            };

            var tracker = Substitute.For <IEventTracker>();

            MixpanelService service = new MixpanelService(options, new NullPropertiesProvider(), null, tracker);

            service.SendEvent("eventName", "property", 123);

            tracker.Received().Track("eventName", Arg.Is <IDictionary <string, object> >(p => p.ContainsKey("property") && (int)p["property"] == 123));
        }
        public void DateTimeIsAddedByDefault()
        {
            var provider = Substitute.For <IPropertiesProvider>();
            var options  = Substitute.For <IMixpanelOptions>();

            options.Enabled.Returns(true);

            var eventTracker = Substitute.For <IEventTracker>();
            var timeProvider = Substitute.For <ITimeProvider>();

            timeProvider.UtcTime.Returns(new DateTime(2010, 12, 31, 13, 59, 30, DateTimeKind.Utc));

            var service = new MixpanelService(options, provider, timeProvider, eventTracker);

            service.SendEvent("testEvent");

            eventTracker.Received().Track(
                Arg.Is("testEvent"),
                Arg.Is <IDictionary <string, object> >(
                    p => p.ContainsKey(EventProperties.DateTime) && string.Equals((string)p[EventProperties.DateTime], "2010-12-31T13:59:30")
                    ));
        }
        public void UserAgentIsAddedByDefault()
        {
            var provider = Substitute.For <IPropertiesProvider>();
            var options  = Substitute.For <IMixpanelOptions>();

            options.Enabled.Returns(true);

            var userAgent = "testAgent";

            options.UserAgent.Returns(userAgent);
            var eventTracker = Substitute.For <IEventTracker>();
            var service      = new MixpanelService(options, provider, new Clock(), eventTracker);

            service.SendEvent("testEvent");

            eventTracker.Received().Track(
                Arg.Is("testEvent"),
                Arg.Is <IDictionary <string, object> >(
                    p => p.ContainsKey(EventProperties.UserAgent) &&
                    string.Equals((string)p[EventProperties.UserAgent], userAgent)
                    ));
        }