public void delete_all_deletes_all_entities_on_provided_scheduler() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); repository .When(x => x.Get(42)) .Return(new TestEntity()); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut .DeleteAll() .Subscribe(); repository .Verify(x => x.DeleteAll()) .WasNotCalled(); scheduler.AdvanceMinimal(); repository .Verify(x => x.DeleteAll()) .WasCalledExactlyOnce(); }
public void future_items_ticks_any_items_removed_after_the_subscription() { var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); repository .When(x => x.GetAll()) .Return(ImmutableList <TestEntity> .Empty); repository .When(x => x.Get(42)) .Return(new TestEntity { Id = 42 }); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(ImmediateScheduler.Instance) .WithRepository(repository) .Build(); var futureItems = new List <ItemChange <TestEntity> >(); sut .FutureItems .Subscribe(futureItems.Add); Assert.Empty(futureItems); sut .Delete(42) .Subscribe(); Assert.Single(futureItems); Assert.Equal(ItemChangeType.Remove, futureItems[0].Type); }
public void items_retrieves_entities_on_provided_scheduler() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); repository .When(x => x.GetAll()) .Return(ImmutableList <TestEntity> .Empty); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut .Items .Subscribe(); repository .Verify(x => x.GetAll()) .WasNotCalled(); scheduler.AdvanceMinimal(); repository .Verify(x => x.GetAll()) .WasCalledExactlyOnce(); }
public void delete_all_does_nothing_without_a_subscription() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut.DeleteAll(); scheduler.AdvanceMinimal(); repository .Verify(x => x.DeleteAll()) .WasNotCalled(); }
public void save_all_does_nothing_without_a_subscription() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut.SaveAll(new[] { new TestEntity() }); scheduler.AdvanceMinimal(); repository .Verify(x => x.SaveAll(It.IsAny <IEnumerable <TestEntity> >())) .WasNotCalled(); }
public void save_all_saves_entities_on_provided_scheduler() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut .SaveAll(new[] { new TestEntity() }) .Subscribe(); repository .Verify(x => x.SaveAll(It.IsAny <IEnumerable <TestEntity> >())) .WasNotCalled(); scheduler.AdvanceMinimal(); repository .Verify(x => x.SaveAll(It.IsAny <IEnumerable <TestEntity> >())) .WasCalledExactlyOnce(); }
public void get_all_retrieves_entity_on_provided_scheduler() { var scheduler = new TestScheduler(); var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose); var sut = new AsyncRepositoryBuilder() .WithDataStoreScheduler(scheduler) .WithRepository(repository) .Build(); sut .GetAll() .Subscribe(); repository .Verify(x => x.GetAll()) .WasNotCalled(); scheduler.AdvanceMinimal(); repository .Verify(x => x.GetAll()) .WasCalledExactlyOnce(); }