Exemple #1
0
    public void TransformDateInJsPatch()
    {
        using var store = GetDocumentStore();
        var @do    = new DateOnly(2022, 2, 21);
        var to     = new TimeOnly(21, 11, 00);
        var entity = new DateAndTimeOnly()
        {
            DateOnly = @do, TimeOnly = to
        };
        {
            using var session = store.OpenSession();
            session.Store(entity);
            session.SaveChanges();
        }
        var operation = store.Operations.Send(new PatchByQueryOperation(@"
declare function modifyDateInJs(date, days) {
  var result = new Date(date);
  result.setDate(result.getDate() + days);
  return result.toISOString().substring(0,10);
}

from DateAndTimeOnlies update { this.DateOnly = modifyDateInJs(this.DateOnly, 1); }"));

        operation.WaitForCompletion(TimeSpan.FromSeconds(5));
        {
            using var session = store.OpenSession();
            WaitForUserToContinueTheTest(store);
            var result = session.Query <DateAndTimeOnly>().Single();
            Assert.Equal(@do.AddDays(1), result.DateOnly);
        }
    }
Exemple #2
0
    public void PatchDateOnlyAndTimeOnly()
    {
        using var store = GetDocumentStore();
        var    @do = new DateOnly(2022, 2, 21);
        var    to  = new TimeOnly(21, 11, 00);
        string id;
        var    entity = new DateAndTimeOnly()
        {
            DateOnly = @do,
            TimeOnly = to
        };
        {
            using var session = store.OpenSession();
            session.Store(entity);
            session.SaveChanges();
            id = session.Advanced.GetDocumentId(entity);
        }

        {
            using var session = store.OpenSession();
            session.Advanced.Patch <DateAndTimeOnly, DateOnly>(id, x => x.DateOnly, @do.AddDays(1));
            session.SaveChanges();
        }

        {
            using var session = store.OpenSession();
            var single = session.Query <DateAndTimeOnly>().Single();
            Assert.Equal(@do.AddDays(1), single.DateOnly);
        }

        {
            using var session = store.OpenSession();
            session.Advanced.Patch <DateAndTimeOnly, TimeOnly>(id, x => x.TimeOnly, to.AddHours(1));
            session.SaveChanges();
        }

        {
            using var session = store.OpenSession();
            var single = session.Query <DateAndTimeOnly>().Single();
            Assert.Equal(to.AddHours(1), single.TimeOnly);
        }
    }