public async Task can_use_select_transformations_to_single_field_in_batch() { var batch1 = theSession.CreateBatchQuery(); var toList = batch1.Query <User>().OrderBy(x => x.FirstName).Select(x => x.FirstName).ToList(); var first = batch1.Query <User>().OrderBy(x => x.FirstName).Select(x => x.FirstName).First(); var firstOrDefault = batch1.Query <User>() .OrderBy(x => x.FirstName) .Where(x => x.FirstName == "nobody") .Select(x => x.FirstName) .FirstOrDefault(); var single = batch1.Query <User>().Where(x => x.FirstName == "Tamba").Select(x => x.FirstName).Single(); var singleOrDefault = batch1.Query <User>().Where(x => x.FirstName == "nobody").Select(x => x.FirstName).SingleOrDefault(); await batch1.Execute(); (await toList).ShouldHaveTheSameElementsAs("Derrick", "Dontari", "Eric", "Justin", "Sean", "Tamba"); (await first).ShouldBe("Derrick"); SpecificationExtensions.ShouldBeNull((await firstOrDefault)); (await single).ShouldBe("Tamba"); SpecificationExtensions.ShouldBeNull((await singleOrDefault)); }
public void include_with_any_containment_where_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Tags = new [] { "DIY" }, Title = "Garage Door is busted" }; theSession.Store <object>(user, issue); theSession.SaveChanges(); using (var query = theStore.QuerySession()) { User included = null; var issue2 = query .Query <Issue>() .Include <User>(x => x.AssigneeId, x => included = x) .Single(x => x.Tags.Any <string>(t => t == "DIY")); SpecificationExtensions.ShouldNotBeNull(included); included.Id.ShouldBe(user.Id); SpecificationExtensions.ShouldNotBeNull(issue2); } }
public void simple_include_for_a_single_document() { var user = new User(); var issue = new Issue { AssigneeId = user.Id, Title = "Garage Door is busted" }; theSession.Store <object>(user, issue); theSession.SaveChanges(); using (var query = theStore.QuerySession()) { User included = null; var issue2 = query .Query <Issue>() .Include <User>(x => x.AssigneeId, x => included = x) .Single(x => x.Title == issue.Title); SpecificationExtensions.ShouldNotBeNull(included); included.Id.ShouldBe(user.Id); SpecificationExtensions.ShouldNotBeNull(issue2); } }
public async Task default_id_event_should_not_create_new_document() { StoreOptions(_ => { _.AutoCreateSchemaObjects = AutoCreate.All; _.Events.TenancyStyle = Marten.Storage.TenancyStyle.Conjoined; _.Events.ProjectView <PersistedView, Guid>() .ProjectEvent <QuestStarted>(e => { return(Guid.Empty); }, (view, @event) => view.Events.Add(@event)); }); theSession.Events.StartStream <QuestParty>(streamId, started); theSession.SaveChanges(); var document = await theSession.LoadAsync <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(document); var documentCount = await theSession.Query <PersistedView>().CountAsync(); documentCount.ShouldBe(0); }
public async void using_collection_of_ids_async() { StoreOptions(_ => { _.AutoCreateSchemaObjects = AutoCreate.All; _.Events.InlineProjections.AggregateStreamsWith <QuestParty>(); _.Events.ProjectView <QuestView, Guid>() .ProjectEventAsync <QuestStarted>((view, @event) => { view.Name = @event.Name; return(Task.CompletedTask); }) .ProjectEventAsync <MonsterQuestsAdded>(e => e.QuestIds, (view, @event) => { view.Name = view.Name.Insert(0, $"{@event.Name}: "); return(Task.CompletedTask); }) .DeleteEvent <MonsterQuestsRemoved>(e => e.QuestIds); }); theSession.Events.StartStream <QuestParty>(streamId, started); theSession.Events.StartStream <QuestParty>(streamId2, started2); await theSession.SaveChangesAsync(); theSession.Events.StartStream <Monster>(monsterQuestsAdded); await theSession.SaveChangesAsync(); var document = theSession.Load <QuestView>(streamId); SpecificationExtensions.ShouldStartWith(document.Name, monsterQuestsAdded.Name); var document2 = theSession.Load <QuestView>(streamId2); SpecificationExtensions.ShouldStartWith(document2.Name, monsterQuestsAdded.Name); theSession.Events.StartStream <Monster>(monsterQuestsRemoved); await theSession.SaveChangesAsync(); var nullDocument = theSession.Load <QuestView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument); var nullDocument2 = theSession.Load <QuestView>(streamId2); SpecificationExtensions.ShouldBeNull(nullDocument2); }
public void query_two_fields_by_one_named_parameter() { using (var session = theStore.OpenSession()) { session.Store(new User { FirstName = "Jeremy", LastName = "Miller" }); session.Store(new User { FirstName = "Lindsey", LastName = "Miller" }); session.Store(new User { FirstName = "Max", LastName = "Miller" }); session.Store(new User { FirstName = "Frank", LastName = "Zombo" }); session.SaveChanges(); var user = session.Query <User>("where data ->> 'FirstName' = :Name or data ->> 'LastName' = :Name", new { Name = "Jeremy" }) .Single(); SpecificationExtensions.ShouldNotBeNull(user); } }
public async Task fetch_in_batch_query() { var streamId = theSession.Events .StartStream <QuestParty>(started, joined, slayed1, slayed2, joined2).Id; await theSession.SaveChangesAsync(); var events = await theSession.Events.FetchStreamAsync(streamId); var batch = theSession.CreateBatchQuery(); var slayed1_2 = batch.Events.Load(events[2].Id); var slayed2_2 = batch.Events.Load(events[3].Id); var missing = batch.Events.Load(Guid.NewGuid()); await batch.Execute(); (await slayed1_2).ShouldBeOfType <Event <MonsterSlayed> >() .Data.Name.ShouldBe("Troll"); (await slayed2_2).ShouldBeOfType <Event <MonsterSlayed> >() .Data.Name.ShouldBe("Dragon"); SpecificationExtensions.ShouldBeNull((await missing)); }
public void open_persisted_stream_in_new_store_with_same_settings(DocumentTracking sessionType, TenancyStyle tenancyStyle, string[] tenants) { var store = InitStore(tenancyStyle); var questId = Guid.NewGuid(); When.CalledForEach(tenants, (tenantId, index) => { using (var session = store.OpenSession(tenantId, sessionType)) { //Note "Id = questId" @see live_aggregate_equals_inlined_aggregate... var started = new QuestStarted { Id = questId, Name = "Destroy the One Ring" }; var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream <Quest>(questId, started, joined1); session.SaveChanges(); } // events-aggregate-on-the-fly - works with same store using (var session = store.OpenSession(tenantId, sessionType)) { // questId is the id of the stream var party = session.Events.AggregateStream <QuestParty>(questId); party.Id.ShouldBe(questId); party.ShouldNotBeNull(); var party_at_version_3 = session.Events .AggregateStream <QuestParty>(questId, 3); party_at_version_3.ShouldNotBeNull(); var party_yesterday = session.Events .AggregateStream <QuestParty>(questId, timestamp: DateTime.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } using (var session = store.OpenSession(tenantId, sessionType)) { var party = session.Load <QuestParty>(questId); party.Id.ShouldBe(questId); } var newStore = InitStore(tenancyStyle, false); //Inline is working using (var session = store.OpenSession(tenantId, sessionType)) { var party = session.Load <QuestParty>(questId); SpecificationExtensions.ShouldNotBeNull(party); } //GetAll using (var session = store.OpenSession(tenantId, sessionType)) { var parties = session.Events.QueryRawEventDataOnly <QuestParty>().ToArray(); foreach (var party in parties) { SpecificationExtensions.ShouldNotBeNull(party); } } //This AggregateStream fail with NPE using (var session = newStore.OpenSession(tenantId, sessionType)) { // questId is the id of the stream var party = session.Events.AggregateStream <QuestParty>(questId);//Here we get NPE party.Id.ShouldBe(questId); var party_at_version_3 = session.Events .AggregateStream <QuestParty>(questId, 3); party_at_version_3.Id.ShouldBe(questId); var party_yesterday = session.Events .AggregateStream <QuestParty>(questId, timestamp: DateTime.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } }).ShouldThrowIf( (tenancyStyle == TenancyStyle.Single && tenants.Length > 1) || (tenancyStyle == TenancyStyle.Conjoined && tenants.SequenceEqual(SameTenants)) ); }
public void can_derive_steps_for_apply_methods() { SpecificationExtensions.ShouldNotBeNull(theAggregator.AggregatorFor <MembersJoined>()); SpecificationExtensions.ShouldNotBeNull(theAggregator.AggregatorFor <MembersDeparted>()); SpecificationExtensions.ShouldNotBeNull(theAggregator.AggregatorFor <QuestStarted>()); }
public void it_finds_the_primary_key() { SpecificationExtensions.ShouldNotBeNull(theDerivedTable.PrimaryKey); theDerivedTable.PrimaryKey.Name.ShouldBe("id"); }
public void can_recognize_when_the_existing_table_does_not_exist() { tableExists().ShouldBeFalse(); SpecificationExtensions.ShouldBeNull(theTable.FetchExisting(_conn)); }
public void null_when_it_does_not_have_it() { var tracker = new VersionTracker(); SpecificationExtensions.ShouldBeNull(tracker.Version <User>(Guid.NewGuid())); }
public void can_get_the_Enum_GetName_method() { SpecificationExtensions.ShouldNotBeNull(typeof(Enum).GetMethod(nameof(Enum.GetName), BindingFlags.Static | BindingFlags.Public)); }
public void total_miss_returns_null() { var shop = new CoffeeShop(); SpecificationExtensions.ShouldBeNull(theStore.Tenancy.Default.MetadataFor(shop)); }
public void can_access_the_source_code_for_a_document_type() { SpecificationExtensions.ShouldNotBeNull(theSourceCode); }
public void UrlEncode_should_encode_string() { string test = "encode test"; SpecificationExtensions.ShouldEqual(test.UrlEncoded(), "encode%20test"); }
public async Task include_within_batch_query() { var user1 = new User(); var user2 = new User(); var issue1 = new Issue { AssigneeId = user1.Id, Title = "Garage Door is busted #1" }; var issue2 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted #2" }; var issue3 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted #3" }; theSession.Store(user1, user2); theSession.Store(issue1, issue2, issue3); theSession.SaveChanges(); using (var query = theStore.QuerySession()) { User included = null; var list = new List <User>(); var dict = new Dictionary <Guid, User>(); // SAMPLE: batch_include var batch = query.CreateBatchQuery(); var found = batch.Query <Issue>() .Include <User>(x => x.AssigneeId, x => included = x) .Where(x => x.Title == issue1.Title) .Single(); // ENDSAMPLE var toList = batch.Query <Issue>() .Include <User>(x => x.AssigneeId, list).ToList(); var toDict = batch.Query <Issue>() .Include(x => x.AssigneeId, dict).ToList(); await batch.Execute().ConfigureAwait(false); (await found).Id.ShouldBe(issue1.Id); SpecificationExtensions.ShouldNotBeNull(included); included.Id.ShouldBe(user1.Id); (await toList).Count.ShouldBe(3); list.Count.ShouldBe(2); // Only 2 users (await toDict).Count.ShouldBe(3); dict.Count.ShouldBe(2); dict.ContainsKey(user1.Id).ShouldBeTrue(); dict.ContainsKey(user2.Id).ShouldBeTrue(); } }
public void from_configuration(TenancyStyle tenancyStyle) { StoreOptions(_ => { _.AutoCreateSchemaObjects = AutoCreate.All; _.Events.TenancyStyle = tenancyStyle; _.Events.InlineProjections.AggregateStreamsWith <QuestParty>(); _.Events.ProjectView <PersistedView, Guid>() .ProjectEventAsync <QuestStarted>((view, @event) => { view.Events.Add(@event); return(Task.CompletedTask); }) .ProjectEventAsync <MembersJoined>(e => e.QuestId, (view, @event) => { view.Events.Add(@event); return(Task.CompletedTask); }) .ProjectEventAsync <MonsterSlayed>(e => e.QuestId, (view, @event) => { view.Events.Add(@event); return(Task.CompletedTask); }) .DeleteEvent <QuestEnded>() .DeleteEvent <MembersDeparted>(e => e.QuestId) .DeleteEvent <MonsterDestroyed>((session, e) => session.Load <QuestParty>(e.QuestId).Id); }); theSession.Events.StartStream <QuestParty>(streamId, started, joined); theSession.SaveChanges(); theSession.Events.StartStream <Monster>(slayed1, slayed2); theSession.SaveChanges(); theSession.Events.Append(streamId, joined2); theSession.SaveChanges(); var document = theSession.Load <PersistedView>(streamId); document.Events.Count.ShouldBe(5); document.Events.ShouldHaveTheSameElementsAs(started, joined, slayed1, slayed2, joined2); theSession.Events.Append(streamId, ended); theSession.SaveChanges(); var nullDocument = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument); // Add document back to so we can delete it by selector theSession.Events.Append(streamId, started); theSession.SaveChanges(); var document2 = theSession.Load <PersistedView>(streamId); document2.Events.Count.ShouldBe(1); theSession.Events.Append(streamId, departed); theSession.SaveChanges(); var nullDocument2 = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument2); // Add document back to so we can delete it by other selector type theSession.Events.Append(streamId, started); theSession.SaveChanges(); var document3 = theSession.Load <PersistedView>(streamId); document3.Events.Count.ShouldBe(1); theSession.Events.Append(streamId, destroyed); theSession.SaveChanges(); var nullDocument3 = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument3); }
public void open_persisted_stream_in_new_store_with_same_settings() { var store = InitStore("event_store"); var questId = "Sixth"; using (var session = store.OpenSession()) { //Note "Id = questId" @see live_aggregate_equals_inlined_aggregate... var started = new QuestStarted { Name = "Destroy the One Ring" }; var joined1 = new MembersJoined(1, "Hobbiton", "Frodo", "Merry"); session.Events.StartStream <Quest>(questId, started, joined1); session.SaveChanges(); } // events-aggregate-on-the-fly - works with same store using (var session = store.OpenSession()) { // questId is the id of the stream var party = session.Events.AggregateStream <QuestPartyWithStringIdentifier>(questId); party.ShouldNotBeNull(); var party_at_version_3 = session.Events .AggregateStream <QuestPartyWithStringIdentifier>(questId, 3); party_at_version_3.ShouldNotBeNull(); var party_yesterday = session.Events .AggregateStream <QuestPartyWithStringIdentifier>(questId, timestamp: DateTime.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } using (var session = store.OpenSession()) { var party = session.Load <QuestPartyWithStringIdentifier>(questId); SpecificationExtensions.ShouldNotBeNull(party); } var newStore = InitStore("event_store", false); //Inline is working using (var session = store.OpenSession()) { var party = session.Load <QuestPartyWithStringIdentifier>(questId); party.ShouldNotBeNull(); } //GetAll using (var session = store.OpenSession()) { var parties = session.Events.QueryRawEventDataOnly <QuestPartyWithStringIdentifier>().ToArray(); foreach (var party in parties) { party.ShouldNotBeNull(); } } //This AggregateStream fail with NPE using (var session = newStore.OpenSession()) { // questId is the id of the stream var party = session.Events.AggregateStream <QuestPartyWithStringIdentifier>(questId);//Here we get NPE party.ShouldNotBeNull(); var party_at_version_3 = session.Events .AggregateStream <QuestPartyWithStringIdentifier>(questId, 3); party_at_version_3.ShouldNotBeNull(); var party_yesterday = session.Events .AggregateStream <QuestPartyWithStringIdentifier>(questId, timestamp: DateTime.UtcNow.AddDays(-1)); party_yesterday.ShouldBeNull(); } }
public void has_the_bus() { SpecificationExtensions.ShouldNotBeNull(theRuntime.Get <IServiceBus>()); }
public void role_is_null_by_default() { SpecificationExtensions.ShouldBeNull(new DdlRules().Role); }
public void the_title_of_the_screen_is_in_the_tab_header() { SpecificationExtensions.As <StackPanel>(tab.Header).Children[0].ShouldBeOfType <Label>().Content.ShouldEqual(screen.Title); }
public void no_version_member_by_default() { SpecificationExtensions.ShouldBeNull(DocumentMapping.For <User>().VersionMember); }
public void the_view_is_added_to_the_content_panel_of_the_tab_item() { SpecificationExtensions.As <DockPanel>(tab.Content).Children[0].ShouldBeTheSameAs(screen.View); }
public void duplicate_property_no_target() { SpecificationExtensions.ShouldContain(Assert.Throws <ArgumentException>(() => _expression.Duplicate(x => x.String)) .Message, "At least one destination must be given"); }
public void detect_changes_with_no_document() { var entity = new TrackedEntity(Guid.NewGuid(), new TestsSerializer(), typeof(Target), null, null); SpecificationExtensions.ShouldBeNull(entity.DetectChange()); }
public void from_configuration() { StoreOptions(_ => { _.AutoCreateSchemaObjects = AutoCreate.All; _.Events.TenancyStyle = Marten.Storage.TenancyStyle.Conjoined; _.Events.InlineProjections.AggregateStreamsWith <QuestParty>(); _.Events.ProjectView <PersistedView, Guid>() .ProjectEvent <ProjectionEvent <QuestStarted> >((view, @event) => { view.Events.Add(@event.Data); view.StreamIdsForEvents.Add(@event.StreamId); }) .ProjectEvent <MembersJoined>(e => e.QuestId, (view, @event) => view.Events.Add(@event)) .ProjectEvent <ProjectionEvent <MonsterSlayed> >(e => e.Data.QuestId, (view, @event) => { view.Events.Add(@event.Data); view.StreamIdsForEvents.Add(@event.StreamId); }) .DeleteEvent <QuestEnded>() .DeleteEvent <MembersDeparted>(e => e.QuestId) .DeleteEvent <MonsterDestroyed>((session, e) => session.Load <QuestParty>(e.QuestId).Id); }); theSession.Events.StartStream <QuestParty>(streamId, started, joined); theSession.SaveChanges(); theSession.Events.StartStream <Monster>(slayed1, slayed2); theSession.SaveChanges(); theSession.Events.Append(streamId, joined2); theSession.SaveChanges(); var document = theSession.Load <PersistedView>(streamId); document.Events.Count.ShouldBe(5); document.Events.ShouldHaveTheSameElementsAs(started, joined, slayed1, slayed2, joined2); theSession.Events.Append(streamId, ended); theSession.SaveChanges(); var nullDocument = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument); // Add document back to so we can delete it by selector theSession.Events.Append(streamId, started); theSession.SaveChanges(); var document2 = theSession.Load <PersistedView>(streamId); document2.Events.Count.ShouldBe(1); theSession.Events.Append(streamId, departed); theSession.SaveChanges(); var nullDocument2 = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument2); // Add document back to so we can delete it by other selector type theSession.Events.Append(streamId, started); theSession.SaveChanges(); var document3 = theSession.Load <PersistedView>(streamId); document3.Events.Count.ShouldBe(1); theSession.Events.Append(streamId, destroyed); theSession.SaveChanges(); var nullDocument3 = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument3); // Add document back to see if we can project stream ids from event handlers (Applies to other IEvent properties) theSession.Events.Append(streamId, started, joined); var monsterId = Guid.NewGuid(); theSession.Events.StartStream(monsterId, slayed1); theSession.SaveChanges(); var document4 = theSession.Load <PersistedView>(streamId); document4.StreamIdsForEvents.Count.ShouldBe(2); // Ids of the two streams document4.StreamIdsForEvents.Contains(streamId).ShouldBeTrue(); document4.StreamIdsForEvents.Contains(monsterId).ShouldBeTrue(); theSession.Events.Append(streamId, ended); theSession.SaveChanges(); var nullDocument4 = theSession.Load <PersistedView>(streamId); SpecificationExtensions.ShouldBeNull(nullDocument4); }
public void running_synchronously() { var logger = new RecordingSessionLogger(); Guid streamId = Guid.NewGuid(); using (var session = theStore.OpenSession()) { session.Logger = logger; var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } }; var departed = new MembersDeparted { Members = new[] { "Thom" } }; session.Events.StartStream <Quest>(streamId, joined, departed); session.SaveChanges(); var events = logger.LastCommit.GetEvents().ToArray(); events.Select(x => x.Version) .ShouldHaveTheSameElementsAs(1, 2); events.Each(x => SpecificationExtensions.ShouldBeGreaterThan(x.Sequence, 0L)); events.Select(x => x.Sequence).Distinct().Count().ShouldBe(2); } using (var session = theStore.OpenSession()) { session.Logger = logger; var joined2 = new MembersJoined { Members = new[] { "Egwene" } }; var departed2 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(streamId, joined2, departed2); session.SaveChanges(); logger.LastCommit.GetEvents().Select(x => x.Version) .ShouldHaveTheSameElementsAs(3, 4); } using (var session = theStore.OpenSession()) { session.Logger = logger; var joined3 = new MembersJoined { Members = new[] { "Egwene" } }; var departed3 = new MembersDeparted { Members = new[] { "Perrin" } }; session.Events.Append(streamId, joined3, departed3); session.SaveChanges(); logger.LastCommit.GetEvents().Select(x => x.Version) .ShouldHaveTheSameElementsAs(5, 6); } }
public void cancel_should_be_enabled() { SpecificationExtensions.As <IListener <TestRunEvent> >(ClassUnderTest).Handle(new TestRunEvent(theTest, TestState.Executing)); ClassUnderTest.CancelCommand.CanExecute(null).ShouldBeTrue(); }
public void is_selected_negative() { SpecificationExtensions.As <CheckBox>(selector.Children[0]).IsChecked = false; selector.IsSelected().ShouldBeFalse(); }