private IEventCentricTestSpecificationBuilder Scenario7(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2,
                                                                WkbGeometry geometry3,
                                                                WkbGeometry geometry4)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(4087928),
                crabHouseNumberId,
                geometry3,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("2"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2015, 7, 30, 10, 57, 33, 920, TimeSpan.Zero))),
                new CrabOperator("13040:7405:DAERO"),
                CrabModification.Delete,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario6(fixture, crabHouseNumberId, geometry1, geometry2, geometry3, geometry4))
                   .When(command)
                   .Then(addressId,
                         new AddressWasPositioned(addressId, new AddressGeometry(GeometryMethod.DerivedFromObject, GeometrySpecification.BuildingUnit, GeometryHelpers.CreateEwkbFrom(geometry4))),
                         command.ToLegacyEvent()));
        }
        private IEventCentricTestSpecificationBuilder Scenario1(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var addressWasRegistered = new AddressWasRegistered(
                addressId,
                fixture.Create <StreetNameId>(),
                fixture.Create <HouseNumber>());

            ((ISetProvenance)addressWasRegistered).SetProvenance(fixture.Create <Provenance>());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(1),
                crabHouseNumberId,
                geometry,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("10"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2011, 4, 29, 14, 50, 10, 483, TimeSpan.Zero))),
                new CrabOperator("VLM\\thijsge"),
                CrabModification.Insert,
                Enum.Parse <CrabOrganisation>("5"));

            return(new Scenario()
                   .Given(addressId, addressWasRegistered)
                   .When(command)
                   .Then(addressId,
                         new AddressWasPositioned(addressId, new AddressGeometry(GeometryMethod.DerivedFromObject, GeometrySpecification.BuildingUnit, GeometryHelpers.CreateEwkbFrom(geometry))),
                         command.ToLegacyEvent()));
        }
        private IEventCentricTestSpecificationBuilder Scenario5(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2,
                                                                WkbGeometry geometry3)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(4087928),
                crabHouseNumberId,
                geometry3,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("2"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2014, 3, 19, 16, 56, 36, 90, TimeSpan.Zero))),
                new CrabOperator("VLM\\CRABSSISservice"),
                CrabModification.Correction,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario4(fixture, crabHouseNumberId, geometry1, geometry2, geometry3))
                   .When(command)
                   .Then(addressId,
                         command.ToLegacyEvent()));
        }
        private IEventCentricTestSpecificationBuilder Scenario6(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2,
                                                                WkbGeometry geometry3,
                                                                WkbGeometry geometry4)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(5790888),
                crabHouseNumberId,
                geometry4,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("10"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2015, 7, 30, 10, 57, 33, 273, TimeSpan.Zero))),
                new CrabOperator("13040:7405:DAERO"),
                CrabModification.Insert,
                Enum.Parse <CrabOrganisation>("5"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario5(fixture, crabHouseNumberId, geometry1, geometry2, geometry3))
                   .When(command)
                   .Then(addressId,
                         command.ToLegacyEvent()));
        }
        private IEventCentricTestSpecificationBuilder Scenario2(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(1),
                crabHouseNumberId,
                geometry,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("10"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2014, 2, 2, 20, 43, 51, 373, TimeSpan.Zero))),
                new CrabOperator("VLM\\CRABSSISservice"),
                CrabModification.Delete,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario1(fixture, crabHouseNumberId, geometry))
                   .When(command)
                   .Then(addressId,
                         new AddressPositionWasRemoved(addressId),
                         command.ToLegacyEvent()));
        }
        private IEventCentricTestSpecificationBuilder Scenario3(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(4087928),
                crabHouseNumberId,
                geometry2,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("2"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2014, 2, 2, 22, 21, 24, 997, TimeSpan.Zero))),
                new CrabOperator("VLM\\CRABSSISservice"),
                CrabModification.Insert,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario2(fixture, crabHouseNumberId, geometry1))
                   .When(command)
                   .Then(addressId,
                         new AddressWasPositioned(addressId, new AddressGeometry(GeometryMethod.AppointedByAdministrator, GeometrySpecification.Parcel, GeometryHelpers.CreateEwkbFrom(geometry2))),
                         command.ToLegacyEvent()));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Attempts to generate a <see cref="Instant"/> by deserializing to a <see cref="DateTimeOffset"/> first.
        /// </summary>
        /// <param name="text">The JSON to deserialize.</param>
        /// <returns>The deserialized <see cref="Instant"/></returns>
        /// <exception cref="SerializationException">Failed to deserialize to a <see cref="Instant"/></exception>
        public static Instant ToInstant(string text)
        {
            var dateTimeOffset = DeserializeStruct <DateTimeOffset>(text);
            var instant        = Instant.FromDateTimeOffset(dateTimeOffset);

            return(instant);
        }
Ejemplo n.º 8
0
        public void NextSecondInstant()
        {
            Instant        i = Instant.FromDateTimeOffset(new DateTimeOffset(2011, 1, 1, 0, 0, 0, TimeSpan.Zero));
            OneOffSchedule oneOffSchedule = new OneOffSchedule(i);

            Assert.AreEqual(i, oneOffSchedule.Next(i - TimeHelpers.OneSecond));
        }
Ejemplo n.º 9
0
        private IEventCentricTestSpecificationBuilder ExtraScenarioAddressGetRetired(Fixture fixture,
                                                                                     CrabHouseNumberId crabHouseNumberId,
                                                                                     WkbGeometry geometry1,
                                                                                     WkbGeometry geometry2,
                                                                                     WkbGeometry geometry3)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberFromCrab(
                crabHouseNumberId,
                _streetNameId,
                _houseNumber,
                fixture.Create <GrbNotation>(),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), LocalDateTime.FromDateTime(new DateTime(2014, 10, 3))),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2014, 10, 17, 20, 26, 30, 480, TimeSpan.Zero))),
                new CrabOperator("13029:kenisils"),
                CrabModification.Historize,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario10(fixture, crabHouseNumberId, geometry1, geometry2, geometry3))
                   .When(command)
                   .Then(addressId,
                         new AddressWasRetired(addressId),
                         new AddressPositionWasCorrected(addressId, new AddressGeometry(GeometryMethod.AppointedByAdministrator, GeometrySpecification.Parcel, GeometryHelpers.CreateEwkbFrom(geometry2))),
                         command.ToLegacyEvent()));
        }
Ejemplo n.º 10
0
 static bool EndpointInaccessible(Alias?alias)
 {
     return(alias?.Expiration != null &&
            Instant.FromDateTimeOffset(DateTimeOffset.Now) >= alias.Expiration ||
            alias?.MaxHits != null &&
            alias.Hits >= alias.MaxHits);
 }
Ejemplo n.º 11
0
        private IEventCentricTestSpecificationBuilder Scenario10(Fixture fixture,
                                                                 CrabHouseNumberId crabHouseNumberId,
                                                                 WkbGeometry geometry1,
                                                                 WkbGeometry geometry2,
                                                                 WkbGeometry geometry3)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(3408534),
                crabHouseNumberId,
                geometry2,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("2"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), LocalDateTime.FromDateTime(new DateTime(2014, 10, 3))),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2014, 10, 17, 20, 26, 30, 480, TimeSpan.Zero))),
                new CrabOperator("13029:kenisils"),
                CrabModification.Correction,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario9(fixture, crabHouseNumberId, geometry1, geometry2, geometry3))
                   .When(command)
                   .Then(addressId,
                         command.ToLegacyEvent()));
        }
Ejemplo n.º 12
0
        private IEventCentricTestSpecificationBuilder Scenario8(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2,
                                                                WkbGeometry geometry3)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(3516111),
                crabHouseNumberId,
                geometry3,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("13"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), LocalDateTime.FromDateTime(new DateTime(2014, 12, 31))),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2013, 6, 4, 13, 1, 9, 137, TimeSpan.Zero))),
                new CrabOperator("13029:kenisils"),
                CrabModification.Historize,
                Enum.Parse <CrabOrganisation>("1"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario7(fixture, crabHouseNumberId, geometry1, geometry2, geometry3))
                   .When(command)
                   .Then(addressId,
                         new AddressPositionWasRemoved(addressId),
                         command.ToLegacyEvent()));
        }
Ejemplo n.º 13
0
        private IEventCentricTestSpecificationBuilder Scenario8(Fixture fixture,
                                                                CrabHouseNumberId crabHouseNumberId,
                                                                WkbGeometry geometry1,
                                                                WkbGeometry geometry2,
                                                                WkbGeometry geometry3,
                                                                WkbGeometry geometry4,
                                                                WkbGeometry geometry5)
        {
            var addressId = new AddressId(crabHouseNumberId.CreateDeterministicId());

            var command = new ImportHouseNumberPositionFromCrab(
                new CrabAddressPositionId(5790888),
                crabHouseNumberId,
                geometry5,
                new CrabAddressNature("2"),
                Enum.Parse <CrabAddressPositionOrigin>("10"),
                new CrabLifetime(LocalDateTime.FromDateTime(new DateTime(1830, 1, 1)), null),
                new CrabTimestamp(Instant.FromDateTimeOffset(new DateTimeOffset(2016, 2, 1, 10, 24, 37, 907, TimeSpan.Zero))),
                new CrabOperator("VLM\\daemsgl"),
                CrabModification.Correction,
                Enum.Parse <CrabOrganisation>("5"));

            return(new AutoFixtureScenario(fixture)
                   .Given(Scenario7(fixture, crabHouseNumberId, geometry1, geometry2, geometry3, geometry4))
                   .When(command)
                   .Then(addressId,
                         new AddressPositionWasCorrected(addressId, new AddressGeometry(GeometryMethod.DerivedFromObject, GeometrySpecification.BuildingUnit, GeometryHelpers.CreateEwkbFrom(geometry5))),
                         command.ToLegacyEvent()));
        }
        public void Should_Work_With_Owner_Document()
        {
            AutoFake.Provide <IServiceCollection>(new ServiceCollection());
            var servicesBuilder = AutoFake.Resolve <ServicesBuilder>();

            servicesBuilder.Services.AddTransient <MartenRegistry, MyMartenRegistry>();
            servicesBuilder.Services.AddSingleton <ILoggerFactory>(LoggerFactory);
            servicesBuilder.Services.AddSingleton <IClock>(
                new FakeClock(Instant.FromDateTimeOffset(DateTimeOffset.Now),
                              Duration.FromSeconds(1))
                );
            var martenBuilder = servicesBuilder.WithMarten();

            servicesBuilder.Services.AddScoped <IMartenContext>(_ => new MartenContext()
            {
                User = new MartenUser <string>(() => Guid.NewGuid().ToString())
            });

            martenBuilder.UseDirtyTrackedSession();

            var serviceProvider = servicesBuilder.Build();
            var options         = serviceProvider.GetRequiredService <IOptions <StoreOptions> >().Value;

            options.Connection(() => new NpgsqlConnection(_fixture.ConnectionString.ToString()));

            using (var scope = serviceProvider.CreateScope())
            {
                using (var session = scope.ServiceProvider.GetService <ISecureQuerySession>())
                {
                    var c = session.Query <HaveOwner>()
                            .ToCommand();
                    c.CommandText.Should().Be("select d.data, d.id, d.mt_version from public.mt_doc_securityqueryprovidertests_haveowner as d where d.data -> 'owner' ->> 'id' LIKE :arg0");
                }
            }
        }
Ejemplo n.º 15
0
            public static Generator <IEnumerable <object> > StreetName(Guid streetNameId, string nameDutch = null)
            {
                var provenance = new Provenance(
                    Instant.FromDateTimeOffset(DateTimeOffset.Now),
                    (Application)Produce.Integer(1, 5).Generate(new Random()),
                    new Reason(Produce.AlphaNumericString(5, 15).Generate(new Random())),
                    new Operator(Produce.AlphaNumericString(5, 15).Generate(new Random())),
                    (Modification)Produce.Integer(1, 3).Generate(new Random()),
                    (Organisation)Produce.Integer(1, 10).Generate(new Random()));

                return(new Generator <IEnumerable <object> >(r =>
                {
                    var events = new List <IGenerator <object> >
                    {
                        StreetNameWasRegistered
                        .Select(e =>
                                e.WithId(streetNameId)
                                .WithProvenance(provenance))
                    };

                    if (nameDutch != null)
                    {
                        events.Add(StreetNameNameWasNamed
                                   .Select(e => e.WithId(streetNameId)
                                           .WithName(nameDutch)
                                           .WithLanguage(StreetNameRegistry.Language.Dutch)
                                           .WithProvenance(provenance)));
                    }

                    return events.Select(e => e.Generate(r));
                }));
            }
Ejemplo n.º 16
0
        public void OptimizedCanvas_Renders_Like_Canvas()
        {
            var canvas = new Canvas(100, 100, "");

            canvas.Add(new RectangleShape(0, 0, 20, 20, "white"));
            canvas.Add(new CircleShape(10, 10, 10, "red"));

            canvas.Add(new RectangleShape(80, 80, 20, 20, "white"));
            canvas.Add(new CircleShape(90, 90, 10, "brown"));

            canvas.Layers.Add(new SecondsLayer()
            {
                Offset = new Vertex(50, 50)
            });
            canvas.Add(new RectangleShape(-1, -30, 2, 32, "blue"));
            canvas.Layers.Add(new Layer());

            canvas.Add(new RectangleShape(0, 80, 20, 20, "white"));
            canvas.Add(new CircleShape(10, 90, 10, "green"));

            canvas.Add(new RectangleShape(80, 0, 20, 20, "white"));
            canvas.Add(new CircleShape(90, 10, 10, "purple"));

            var clockCanvas     = new ClockCanvas(new TestTimer(Instant.FromDateTimeOffset(DateTime.Today.AddHours(3).AddMinutes(30).AddSeconds(45))), canvas);
            var optimizedCanvas = clockCanvas.OptimizeFor(1);

            clockCanvas.Update();
            optimizedCanvas.Update();
            var bmp = optimizedCanvas.Render();

            AssertBitmapsAreEqual(clockCanvas.Render(), bmp);
        }
Ejemplo n.º 17
0
        public override object Visit(ConvertNode nodeIn)
        {
            if (nodeIn.TypeReference.Definition == BooleanType)
            {
                return(bool.Parse(Visit(nodeIn.Source).ToString()));
            }

            if (nodeIn.TypeReference.Definition == GuidType)
            {
                return(Guid.Parse(Visit(nodeIn.Source).ToString()));
            }

            if (nodeIn.TypeReference.Definition == DateTimeType)
            {
                var value = Visit(nodeIn.Source);

                if (value is DateTimeOffset dateTimeOffset)
                {
                    return(Instant.FromDateTimeOffset(dateTimeOffset));
                }

                return(InstantPattern.General.Parse(Visit(nodeIn.Source).ToString()).Value);
            }

            return(base.Visit(nodeIn));
        }
Ejemplo n.º 18
0
        public void MustCallDelegatesOnBuild()
        {
            var configurationDelegate          = A.Fake <MartenConfigurationDelegate>();
            var componentConfigurationDelegate = A.Fake <MartenComponentConfigurationDelegate>();

            AutoFake.Provide <IServiceCollection>(new ServiceCollection());
            var servicesBuilder = AutoFake.Resolve <ServicesBuilder>();

            servicesBuilder.Services.AddTransient <MartenRegistry, MyMartenRegistry>();
            servicesBuilder.Services.AddSingleton <ILoggerFactory>(LoggerFactory);
            servicesBuilder.Services.AddSingleton <IClock>(
                new FakeClock(Instant.FromDateTimeOffset(DateTimeOffset.Now),
                              Duration.FromSeconds(1))
                );
            var martenBuilder = servicesBuilder
                                .WithMarten()
                                .AddStartupFilter()
                                .Configure(configurationDelegate)
                                .Configure(componentConfigurationDelegate);

            martenBuilder.UseDirtyTrackedSession();

            var serviceProvider = servicesBuilder.Build();
            var options         = serviceProvider.GetRequiredService <IOptions <StoreOptions> >().Value;

            A.CallTo(() => configurationDelegate(options))
            .MustHaveHappened(Repeated.Exactly.Once)
            .Then(A.CallTo(() => componentConfigurationDelegate(A <IServiceProvider> ._, options))
                  .MustHaveHappened(Repeated.Exactly.Once));
        }
Ejemplo n.º 19
0
        private static Instant ParseInstant(object value)
        {
            if (value is DateTimeOffset dateTimeOffset)
            {
                return(Instant.FromDateTimeOffset(dateTimeOffset.Add(dateTimeOffset.Offset)));
            }

            if (value is DateTime dateTime)
            {
                return(Instant.FromDateTimeUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc)));
            }

            if (value is Date date)
            {
                return(Instant.FromUtc(date.Year, date.Month, date.Day, 0, 0));
            }

            var parseResult = InstantPattern.General.Parse(value.ToString());

            if (!parseResult.Success)
            {
                throw new ODataException("Datetime is not in a valid format. Use ISO 8601");
            }

            return(parseResult.Value);
        }
        private static Instant DeserializeInstant(string text)
        {
            switch (text.ToLowerInvariant())
            {
            case "mininstant":
                return(Instant.MinValue);

            case "maxinstant":
                return(Instant.MaxValue);

            default:
                if (text.LastOrDefault() == ']')
                {
                    var timeCodeIndex = text.IndexOf('[');

                    if (timeCodeIndex >= 0)
                    {
                        text = text.Substring(0, timeCodeIndex);
                    }
                }

                var dateTimeOffset = ParseDateTimeOffset(text);
                return(Instant.FromDateTimeOffset(dateTimeOffset));
            }
        }
Ejemplo n.º 21
0
        private Interval GetTimeRange()
        {
            if (Context.Command == CommandType.DeleteAllPoints)
            {
                // Apply a 1-day margin, to workaround the AQ-23146 OverflowException crash
                return(new Interval(
                           Instant.FromDateTimeOffset(DateTimeOffset.MinValue).Plus(Duration.FromStandardDays(1)),
                           Instant.FromDateTimeOffset(DateTimeOffset.MaxValue).Minus(Duration.FromStandardDays(1))));
            }

            if (Context.TimeRange.HasValue)
            {
                return(Context.TimeRange.Value);
            }

            if (!Points.Any())
            {
                throw new ExpectedException($"Can't infer a time-range from an empty points list. Please set the /{nameof(Context.TimeRange)} option explicitly.");
            }

            return(new Interval(
                       // ReSharper disable once PossibleInvalidOperationException
                       Points.First().Time.Value,
                       // ReSharper disable once PossibleInvalidOperationException
                       Points.Last().Time.Value.PlusTicks(1)));
        }
Ejemplo n.º 22
0
        public override object Visit(ConvertNode nodeIn)
        {
            var booleanType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Boolean);

            if (nodeIn.TypeReference.Definition == booleanType)
            {
                return(bool.Parse(Visit(nodeIn.Source).ToString()));
            }

            var dateTimeType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.DateTimeOffset);

            if (nodeIn.TypeReference.Definition == dateTimeType)
            {
                var value = Visit(nodeIn.Source);

                if (value is DateTimeOffset dateTimeOffset)
                {
                    return(Instant.FromDateTimeOffset(dateTimeOffset));
                }

                return(InstantPattern.General.Parse(Visit(nodeIn.Source).ToString()).Value);
            }

            return(base.Visit(nodeIn));
        }
Ejemplo n.º 23
0
        public void FromDateTimeOffset()
        {
            DateTimeOffset dateTimeOffset = new DateTimeOffset(2011, 08, 18, 20, 53, 0, TimeSpan.FromHours(5));
            Instant        expected       = Instant.FromUtc(2011, 08, 18, 15, 53);

            Assert.AreEqual(expected, Instant.FromDateTimeOffset(dateTimeOffset));
        }
 public void ToInstant_ValidText_Deserialize()
 {
     DeserializeAssert(
         ServiceStackFallbackDeserializers.ToInstant,
         "2014-2-21 19:02:13Z",
         Instant.FromDateTimeOffset(new DateTimeOffset(2014, 2, 21, 19, 2, 13, TimeSpan.Zero)));
 }
Ejemplo n.º 25
0
        private List <ReflectedTimeSeriesPoint> LoadPointsFromNg(IAquariusClient client)
        {
            var timeSeriesInfo = client.GetTimeSeriesInfo(Context.SourceTimeSeries.Identifier);

            var points = client.Publish.Get(new TimeAlignedDataServiceRequest
            {
                TimeSeriesUniqueIds = new List <Guid> {
                    timeSeriesInfo.UniqueId
                },
                QueryFrom = Context.SourceQueryFrom?.ToDateTimeOffset(),
                QueryTo   = Context.SourceQueryTo?.ToDateTimeOffset()
            })
                         .Points
                         .Select(p => new ReflectedTimeSeriesPoint
            {
                Time       = Instant.FromDateTimeOffset(p.Timestamp),
                Value      = p.NumericValue1,
                GradeCode  = p.GradeCode1.HasValue ? (int)p.GradeCode1 : (int?)null,
                Qualifiers = QualifiersParser.Parse(p.Qualifiers1)
            })
                         .ToList();

            Log.Info($"Loaded {points.Count} points from {timeSeriesInfo.Identifier}");

            return(points);
        }
Ejemplo n.º 26
0
        public void TestGetPrayerTimesForToday()
        {
            var imsakExpected    = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 5, 45, 0, TimeSpan.FromHours(8.0)));
            var fajrExpected     = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 5, 55, 0, TimeSpan.FromHours(8.0)));
            var sunriseExpected  = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 7, 13, 0, TimeSpan.FromHours(8.0)));
            var dhuhaExpected    = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 7, 38, 0, TimeSpan.FromHours(8.0)));
            var dhuhrExpected    = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 13, 18, 0, TimeSpan.FromHours(8.0)));
            var asrExpected      = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 16, 29, 0, TimeSpan.FromHours(8.0)));
            var sunsetExpected   = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 19, 22, 0, TimeSpan.FromHours(8.0)));
            var maghribExpected  = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 19, 23, 0, TimeSpan.FromHours(8.0)));
            var ishaExpected     = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 20, 32, 0, TimeSpan.FromHours(8.0)));
            var midnightExpected = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 13, 1, 17, 0, TimeSpan.FromHours(8.0)));

            var prayers = Prayers.Today(_settings, _coordinate, TimeZone, _mockClock);

            AssertEqualInstant(imsakExpected, prayers.Imsak);
            AssertEqualInstant(fajrExpected, prayers.Fajr);
            AssertEqualInstant(sunriseExpected, prayers.Sunrise);
            AssertEqualInstant(dhuhaExpected, prayers.Dhuha);
            AssertEqualInstant(dhuhrExpected, prayers.Dhuhr);
            AssertEqualInstant(asrExpected, prayers.Asr);
            AssertEqualInstant(sunsetExpected, prayers.Sunset);
            AssertEqualInstant(maghribExpected, prayers.Maghrib);
            AssertEqualInstant(ishaExpected, prayers.Isha);
            AssertEqualInstant(midnightExpected, prayers.Midnight);
        }
 private static TimeSeriesNote ConvertNgNote(PublishNote note)
 {
     return(new TimeSeriesNote
     {
         TimeRange = new Interval(Instant.FromDateTimeOffset(note.StartTime), Instant.FromDateTimeOffset(note.EndTime)),
         NoteText = note.NoteText
     });
 }
Ejemplo n.º 28
0
        public void CreateDigimon()
        {
            var instant = Instant.FromDateTimeOffset(new DateTimeOffset(2020, 3, 24, 11, 45, 0, TimeSpan.Zero));
            var digimon = Digimon.Create("Bakugon", 25, instant);

            digimon.Niveau.Should().Be(25);
            digimon.Nom.Should().Be("Bakugon");
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeData{TKey}"/> class.
 /// </summary>
 /// <param name="by">The by.</param>
 /// <param name="at">At.</param>
 public ChangeData(TKey by, DateTimeOffset?at)
 {
     By = by;
     if (at.HasValue)
     {
         At = Instant.FromDateTimeOffset(at.Value);
     }
 }
Ejemplo n.º 30
0
        public void TestGetAfterLaterPrayerTime()
        {
            var expected = Instant.FromDateTimeOffset(new DateTimeOffset(2018, 4, 12, 19, 23, 0, TimeSpan.FromHours(8.0)));
            var prayer   = Prayer.AfterLater(_settings, _coordinate, TimeZone, _mockClock);

            AssertEqualInstant(expected, prayer.Time);
            Assert.Equal(PrayerType.Maghrib, prayer.Type);
        }